@@ -23,7 +23,7 @@ public static void AddEventTypeAttributes(IAgent agent, ITransaction transaction
23
23
{
24
24
case AwsLambdaEventType . APIGatewayProxyRequest :
25
25
dynamic apiReqEvent = inputObject ; // Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest
26
- SetWebRequestProperties ( agent , transaction , apiReqEvent ) ;
26
+ SetWebRequestProperties ( agent , transaction , apiReqEvent , eventType ) ;
27
27
28
28
if ( apiReqEvent . RequestContext != null )
29
29
{
@@ -34,14 +34,29 @@ public static void AddEventTypeAttributes(IAgent agent, ITransaction transaction
34
34
transaction . AddEventSourceAttribute ( "resourceId" , ( string ) requestContext . ResourceId ) ;
35
35
transaction . AddEventSourceAttribute ( "resourcePath" , ( string ) requestContext . ResourcePath ) ;
36
36
transaction . AddEventSourceAttribute ( "stage" , ( string ) requestContext . Stage ) ;
37
+ }
38
+ break ;
39
+
40
+ case AwsLambdaEventType . APIGatewayHttpApiV2ProxyRequest :
41
+ dynamic apiReqv2Event = inputObject ; // Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest
42
+ SetWebRequestProperties ( agent , transaction , apiReqv2Event , eventType ) ;
37
43
44
+ if ( apiReqv2Event . RequestContext != null )
45
+ {
46
+ dynamic requestContext = apiReqv2Event . RequestContext ;
47
+ // arn is not available
48
+ transaction . AddEventSourceAttribute ( "accountId" , ( string ) requestContext . AccountId ) ;
49
+ transaction . AddEventSourceAttribute ( "apiId" , ( string ) requestContext . ApiId ) ;
50
+ // resourceId is not available for v2
51
+ // resourcePath is not available for v2
52
+ transaction . AddEventSourceAttribute ( "stage" , ( string ) requestContext . Stage ) ;
38
53
}
39
54
break ;
40
55
41
56
case AwsLambdaEventType . ApplicationLoadBalancerRequest :
42
57
dynamic albReqEvent = inputObject ; //Amazon.Lambda.ApplicationLoadBalancerEvents.ApplicationLoadBalancerRequest
43
58
44
- SetWebRequestProperties ( agent , transaction , albReqEvent ) ;
59
+ SetWebRequestProperties ( agent , transaction , albReqEvent , eventType ) ;
45
60
46
61
transaction . AddEventSourceAttribute ( "arn" , ( string ) albReqEvent . RequestContext . Elb . TargetGroupArn ) ;
47
62
break ;
@@ -231,26 +246,30 @@ private static void TryParseSNSDistributedTraceHeaders(dynamic snsEvent, ITransa
231
246
transaction . AcceptDistributedTraceHeaders ( snsHeaders , GetHeaderValue , TransportType . Other ) ;
232
247
}
233
248
234
- private static void SetWebRequestProperties ( IAgent agent , ITransaction transaction , dynamic webReqEvent )
249
+ private static void SetWebRequestProperties ( IAgent agent , ITransaction transaction , dynamic webReqEvent , AwsLambdaEventType eventType )
235
250
{
236
251
//HTTP headers
237
252
IDictionary < string , string > headers = webReqEvent . Headers ;
238
253
Func < IDictionary < string , string > , string , string > headersGetter = ( h , k ) => h [ k ] ;
239
254
240
- IDictionary < string , IList < string > > multiValueHeaders = webReqEvent . MultiValueHeaders ;
241
- Func < IDictionary < string , IList < string > > , string , string > multiValueHeadersGetter = ( h , k ) => string . Join ( "," , h [ k ] ) ;
242
-
243
- if ( multiValueHeaders != null )
255
+ if ( eventType != AwsLambdaEventType . APIGatewayHttpApiV2ProxyRequest ) // v2 doesn't have MultiValueHeaders
244
256
{
245
- transaction . SetRequestHeaders ( multiValueHeaders , agent . Configuration . AllowAllRequestHeaders ? multiValueHeaders . Keys : Statics . DefaultCaptureHeaders , multiValueHeadersGetter ) ;
257
+ IDictionary < string , IList < string > > multiValueHeaders = webReqEvent . MultiValueHeaders ;
258
+ Func < IDictionary < string , IList < string > > , string , string > multiValueHeadersGetter = ( h , k ) => string . Join ( "," , h [ k ] ) ;
246
259
247
- // DT transport comes from the X-Forwarded-Proto header, if present
248
- var forwardedProto = GetMultiHeaderValue ( multiValueHeaders , xForwardedProtoHeader ) . FirstOrDefault ( ) ;
249
- var dtTransport = GetDistributedTransportType ( forwardedProto ) ;
260
+ if ( multiValueHeaders != null )
261
+ {
262
+ transaction . SetRequestHeaders ( multiValueHeaders , agent . Configuration . AllowAllRequestHeaders ? multiValueHeaders . Keys : Statics . DefaultCaptureHeaders , multiValueHeadersGetter ) ;
263
+
264
+ // DT transport comes from the X-Forwarded-Proto header, if present
265
+ var forwardedProto = GetMultiHeaderValue ( multiValueHeaders , xForwardedProtoHeader ) . FirstOrDefault ( ) ;
266
+ var dtTransport = GetDistributedTransportType ( forwardedProto ) ;
250
267
251
- transaction . AcceptDistributedTraceHeaders ( multiValueHeaders , GetMultiHeaderValue , dtTransport ) ;
268
+ transaction . AcceptDistributedTraceHeaders ( multiValueHeaders , GetMultiHeaderValue , dtTransport ) ;
269
+ }
252
270
}
253
- else if ( headers != null )
271
+
272
+ if ( headers != null )
254
273
{
255
274
transaction . SetRequestHeaders ( headers , agent . Configuration . AllowAllRequestHeaders ? webReqEvent . Headers ? . Keys : Statics . DefaultCaptureHeaders , headersGetter ) ;
256
275
@@ -261,8 +280,18 @@ private static void SetWebRequestProperties(IAgent agent, ITransaction transacti
261
280
transaction . AcceptDistributedTraceHeaders ( headers , GetHeaderValue , dtTransport ) ;
262
281
}
263
282
264
- transaction . SetRequestMethod ( webReqEvent . HttpMethod ) ;
265
- transaction . SetUri ( webReqEvent . Path ) ;
283
+ if ( eventType == AwsLambdaEventType . APIGatewayHttpApiV2ProxyRequest ) // v2 buries method and path
284
+ {
285
+ var reqContext = webReqEvent . RequestContext ;
286
+ transaction . SetRequestMethod ( reqContext . Http . Method ) ;
287
+ transaction . SetUri ( reqContext . Http . Path ) ;
288
+ }
289
+ else
290
+ {
291
+ transaction . SetRequestMethod ( webReqEvent . HttpMethod ) ;
292
+ transaction . SetUri ( webReqEvent . Path ) ;
293
+ }
294
+
266
295
transaction . SetRequestParameters ( webReqEvent . QueryStringParameters ) ;
267
296
}
268
297
0 commit comments