Skip to content

Commit a7a4f71

Browse files
authored
Prevent AttributeError from being raised when lambda event is a list (#1738)
1 parent e4d42e6 commit a7a4f71

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Make Django request span attributes available for `start_span`.
1717
([#1730](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1730))
1818

19+
### Fixed
20+
21+
- Fix `AttributeError` when AWS Lambda handler receives a list event
22+
([#1738](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1738))
23+
1924

2025
## Version 1.17.0/0.38b0 (2023-03-22)
2126

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
342342
# If the request came from an API Gateway, extract http attributes from the event
343343
# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/instrumentation/aws-lambda.md#api-gateway
344344
# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-server-semantic-conventions
345-
if lambda_event and lambda_event.get("requestContext"):
345+
if isinstance(lambda_event, dict) and lambda_event.get(
346+
"requestContext"
347+
):
346348
span.set_attribute(SpanAttributes.FAAS_TRIGGER, "http")
347349

348350
if lambda_event.get("version") == "2.0":

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

+9
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,15 @@ def test_api_gateway_http_api_proxy_event_sets_attributes(self):
399399
},
400400
)
401401

402+
def test_lambda_handles_list_event(self):
403+
AwsLambdaInstrumentor().instrument()
404+
405+
mock_execute_lambda([{"message": "test"}])
406+
407+
spans = self.memory_exporter.get_finished_spans()
408+
409+
assert spans
410+
402411
def test_uninstrument(self):
403412
AwsLambdaInstrumentor().instrument()
404413

0 commit comments

Comments
 (0)