bugfix: AWS Lambda event source key incorrect for SNS in instrumenta… (#2612)

This commit is contained in:
Fools
2024-06-20 18:50:31 +01:00
committed by GitHub
parent 41ca9027a8
commit a61739c9c2
3 changed files with 39 additions and 3 deletions

View File

@ -349,12 +349,43 @@ class TestAwsLambdaInstrumentor(TestBase):
mock_execute_lambda({"Records": [{"eventSource": "aws:sqs"}]})
mock_execute_lambda({"Records": [{"eventSource": "aws:s3"}]})
mock_execute_lambda({"Records": [{"eventSource": "aws:sns"}]})
mock_execute_lambda({"Records": [{"EventSource": "aws:sns"}]})
mock_execute_lambda({"Records": [{"eventSource": "aws:dynamodb"}]})
spans = self.memory_exporter.get_finished_spans()
assert spans
assert len(spans) == 4
for span in spans:
assert span.kind == SpanKind.CONSUMER
test_env_patch.stop()
def test_lambda_handles_invalid_event_source(self):
test_env_patch = mock.patch.dict(
"os.environ",
{
**os.environ,
# NOT Active Tracing
_X_AMZN_TRACE_ID: MOCK_XRAY_TRACE_CONTEXT_NOT_SAMPLED,
# NOT using the X-Ray Propagator
OTEL_PROPAGATORS: "tracecontext",
},
)
test_env_patch.start()
AwsLambdaInstrumentor().instrument()
mock_execute_lambda({"Records": [{"eventSource": "invalid_source"}]})
spans = self.memory_exporter.get_finished_spans()
assert spans
assert len(spans) == 1
assert (
spans[0].kind == SpanKind.SERVER
) # Default to SERVER for unknown sources
test_env_patch.stop()