Skip to content

Commit 5539d1f

Browse files
authored
adding additional event sources (#926)
1 parent 7a0caed commit 5539d1f

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919

2020
### Added
2121

22+
- `opentelemetry-instrumentation-aws-lambda` `SpanKind.SERVER` by default, add more cases for `SpanKind.CONSUMER` services. ([#926](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/926))
2223
- `opentelemetry-instrumentation-sqlalchemy` added experimental sql commenter capability
2324
([#924](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/924))
2425
- `opentelemetry-instrumentation-dbapi` add experimental sql commenter capability

instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,19 @@ def _instrumented_lambda_handler_call(
187187
lambda_event, event_context_extractor
188188
)
189189

190-
# See more:
191-
# https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
190+
span_kind = None
192191
try:
193-
if lambda_event["Records"][0]["eventSource"] == "aws:sqs":
192+
if lambda_event["Records"][0]["eventSource"] in set(
193+
["aws:sqs", "aws:s3", "aws:sns", "aws:dynamodb"]
194+
):
195+
# See more:
196+
# https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
197+
# https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html
198+
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/notification-content-structure.html
199+
# https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html
194200
span_kind = SpanKind.CONSUMER
201+
else:
202+
span_kind = SpanKind.SERVER
195203
except (IndexError, KeyError, TypeError):
196204
span_kind = SpanKind.SERVER
197205

instrumentation/opentelemetry-instrumentation-aws-lambda/tests/test_aws_lambda_instrumentation_manual.py

+26
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,29 @@ def test_lambda_no_error_with_invalid_flush_timeout(self):
274274
self.assertEqual(len(spans), 1)
275275

276276
test_env_patch.stop()
277+
278+
def test_lambda_handles_multiple_consumers(self):
279+
test_env_patch = mock.patch.dict(
280+
"os.environ",
281+
{
282+
**os.environ,
283+
# NOT Active Tracing
284+
_X_AMZN_TRACE_ID: MOCK_XRAY_TRACE_CONTEXT_NOT_SAMPLED,
285+
# NOT using the X-Ray Propagator
286+
OTEL_PROPAGATORS: "tracecontext",
287+
},
288+
)
289+
test_env_patch.start()
290+
291+
AwsLambdaInstrumentor().instrument()
292+
293+
mock_execute_lambda({"Records": [{"eventSource": "aws:sqs"}]})
294+
mock_execute_lambda({"Records": [{"eventSource": "aws:s3"}]})
295+
mock_execute_lambda({"Records": [{"eventSource": "aws:sns"}]})
296+
mock_execute_lambda({"Records": [{"eventSource": "aws:dynamodb"}]})
297+
298+
spans = self.memory_exporter.get_finished_spans()
299+
300+
assert spans
301+
302+
test_env_patch.stop()

0 commit comments

Comments
 (0)