@@ -38,13 +38,15 @@ import {
3838 TraceFlags ,
3939 TracerProvider ,
4040 ROOT_CONTEXT ,
41+ Attributes ,
4142} from '@opentelemetry/api' ;
4243import {
4344 AWSXRAY_TRACE_ID_HEADER ,
4445 AWSXRayPropagator ,
4546} from '@opentelemetry/propagator-aws-xray' ;
4647import {
4748 SEMATTRS_FAAS_EXECUTION ,
49+ SEMATTRS_HTTP_URL ,
4850 SEMRESATTRS_CLOUD_ACCOUNT_ID ,
4951 SEMRESATTRS_FAAS_ID ,
5052} from '@opentelemetry/semantic-conventions' ;
@@ -203,6 +205,7 @@ export class AwsLambdaInstrumentation extends InstrumentationBase<AwsLambdaInstr
203205 AwsLambdaInstrumentation . _extractAccountId (
204206 context . invokedFunctionArn
205207 ) ,
208+ ...AwsLambdaInstrumentation . _extractOtherEventFields ( event ) ,
206209 } ,
207210 } ,
208211 parent
@@ -385,6 +388,41 @@ export class AwsLambdaInstrumentation extends InstrumentationBase<AwsLambdaInstr
385388 return propagation . extract ( otelContext . active ( ) , httpHeaders , headerGetter ) ;
386389 }
387390
391+ private static _extractOtherEventFields ( event : any ) : Attributes {
392+ const answer : Attributes = { } ;
393+ const fullUrl = this . _extractFullUrl ( event ) ;
394+ if ( fullUrl ) {
395+ answer [ SEMATTRS_HTTP_URL ] = fullUrl ;
396+ }
397+ return answer ;
398+ }
399+
400+ private static _extractFullUrl ( event : any ) : string | undefined {
401+ // API gateway encodes a lot of url information in various places to recompute this
402+ if ( ! event . headers || ! event . path ) {
403+ return undefined ;
404+ }
405+ let answer = '' ;
406+ if ( event . headers [ 'x-forwarded-proto' ] ) {
407+ answer += event . headers [ 'x-forwarded-proto' ] + '://' ;
408+ }
409+ if ( event . headers [ 'host' ] ) {
410+ answer += event . headers [ 'host' ] ;
411+ }
412+ answer += event . path ;
413+ if ( event . queryStringParameters ) {
414+ let first = true ;
415+ for ( const key in event . queryStringParameters ) {
416+ answer += first ? '?' : '&' ;
417+ answer += encodeURIComponent ( key ) ;
418+ answer += '=' ;
419+ answer += encodeURIComponent ( event . queryStringParameters [ key ] ) ;
420+ first = false ;
421+ }
422+ }
423+ return answer . length === 0 ? undefined : answer ;
424+ }
425+
388426 private static _determineParent (
389427 event : any ,
390428 context : Context ,
0 commit comments