diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts index c6d63ca86a..efc336d0f1 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts @@ -37,8 +37,10 @@ import { TextMapGetter, TracerProvider, ROOT_CONTEXT, + Attributes, } from '@opentelemetry/api'; import { + ATTR_URL_FULL, SEMATTRS_FAAS_EXECUTION, SEMRESATTRS_CLOUD_ACCOUNT_ID, SEMRESATTRS_FAAS_ID, @@ -244,6 +246,7 @@ export class AwsLambdaInstrumentation extends InstrumentationBase { assert.strictEqual(span.parentSpanId, undefined); }); }); + + describe('url parsing', () => { + it('pulls url from api gateway rest events', async () => { + initializeHandler('lambda-test/sync.handler'); + const event = { + path: '/lambda/test/path', + headers: { + Host: 'www.example.com', + 'X-Forwarded-Proto': 'http', + 'X-Forwarded-Port': 1234, + }, + queryStringParameters: { + key: 'value', + key2: 'value2', + }, + }; + + await lambdaRequire('lambda-test/sync').handler(event, ctx, () => {}); + const [span] = memoryExporter.getFinishedSpans(); + assert.ok( + span.attributes[ATTR_URL_FULL] === + 'http://www.example.com:1234/lambda/test/path?key=value&key2=value2' || + span.attributes[ATTR_URL_FULL] === + 'http://www.example.com:1234/lambda/test/path?key2=value2&key=value' + ); + }); + it('pulls url from api gateway http events', async () => { + initializeHandler('lambda-test/sync.handler'); + const event = { + rawPath: '/lambda/test/path', + headers: { + host: 'www.example.com', + 'x-forwarded-proto': 'http', + 'x-forwarded-port': 1234, + }, + queryStringParameters: { + key: 'value', + }, + }; + + await lambdaRequire('lambda-test/sync').handler(event, ctx, () => {}); + const [span] = memoryExporter.getFinishedSpans(); + assert.strictEqual( + span.attributes[ATTR_URL_FULL], + 'http://www.example.com:1234/lambda/test/path?key=value' + ); + }); + }); });