File tree 3 files changed +39
-3
lines changed
instrumentation/opentelemetry-instrumentation-aws-lambda
src/opentelemetry/instrumentation/aws_lambda
3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
## Unreleased
9
9
10
+ - ` opentelemetry-instrumentation-aws-lambda ` Bugfix: AWS Lambda event source key incorrect for SNS in instrumentation library.
11
+ ([ #2612 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2612 ) )
12
+
10
13
### Added
11
14
12
15
- ` opentelemetry-instrumentation-pyramid ` Record exceptions raised when serving a request
Original file line number Diff line number Diff line change @@ -306,9 +306,11 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
306
306
disable_aws_context_propagation ,
307
307
)
308
308
309
- span_kind = None
310
309
try :
311
- if lambda_event ["Records" ][0 ]["eventSource" ] in {
310
+ event_source = lambda_event ["Records" ][0 ].get (
311
+ "eventSource"
312
+ ) or lambda_event ["Records" ][0 ].get ("EventSource" )
313
+ if event_source in {
312
314
"aws:sqs" ,
313
315
"aws:s3" ,
314
316
"aws:sns" ,
Original file line number Diff line number Diff line change @@ -349,12 +349,43 @@ def test_lambda_handles_multiple_consumers(self):
349
349
350
350
mock_execute_lambda ({"Records" : [{"eventSource" : "aws:sqs" }]})
351
351
mock_execute_lambda ({"Records" : [{"eventSource" : "aws:s3" }]})
352
- mock_execute_lambda ({"Records" : [{"eventSource " : "aws:sns" }]})
352
+ mock_execute_lambda ({"Records" : [{"EventSource " : "aws:sns" }]})
353
353
mock_execute_lambda ({"Records" : [{"eventSource" : "aws:dynamodb" }]})
354
354
355
355
spans = self .memory_exporter .get_finished_spans ()
356
356
357
357
assert spans
358
+ assert len (spans ) == 4
359
+
360
+ for span in spans :
361
+ assert span .kind == SpanKind .CONSUMER
362
+
363
+ test_env_patch .stop ()
364
+
365
+ def test_lambda_handles_invalid_event_source (self ):
366
+ test_env_patch = mock .patch .dict (
367
+ "os.environ" ,
368
+ {
369
+ ** os .environ ,
370
+ # NOT Active Tracing
371
+ _X_AMZN_TRACE_ID : MOCK_XRAY_TRACE_CONTEXT_NOT_SAMPLED ,
372
+ # NOT using the X-Ray Propagator
373
+ OTEL_PROPAGATORS : "tracecontext" ,
374
+ },
375
+ )
376
+ test_env_patch .start ()
377
+
378
+ AwsLambdaInstrumentor ().instrument ()
379
+
380
+ mock_execute_lambda ({"Records" : [{"eventSource" : "invalid_source" }]})
381
+
382
+ spans = self .memory_exporter .get_finished_spans ()
383
+
384
+ assert spans
385
+ assert len (spans ) == 1
386
+ assert (
387
+ spans [0 ].kind == SpanKind .SERVER
388
+ ) # Default to SERVER for unknown sources
358
389
359
390
test_env_patch .stop ()
360
391
You can’t perform that action at this time.
0 commit comments