mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-29 13:12:39 +08:00
Prevent AttributeError from being raised when lambda event is a list (#1738)
This commit is contained in:
@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Make Django request span attributes available for `start_span`.
|
- Make Django request span attributes available for `start_span`.
|
||||||
([#1730](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1730))
|
([#1730](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1730))
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix `AttributeError` when AWS Lambda handler receives a list event
|
||||||
|
([#1738](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1738))
|
||||||
|
|
||||||
|
|
||||||
## Version 1.17.0/0.38b0 (2023-03-22)
|
## Version 1.17.0/0.38b0 (2023-03-22)
|
||||||
|
|
||||||
|
@ -342,7 +342,9 @@ def _instrument(
|
|||||||
# If the request came from an API Gateway, extract http attributes from the event
|
# If the request came from an API Gateway, extract http attributes from the event
|
||||||
# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/instrumentation/aws-lambda.md#api-gateway
|
# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/instrumentation/aws-lambda.md#api-gateway
|
||||||
# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-server-semantic-conventions
|
# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-server-semantic-conventions
|
||||||
if lambda_event and lambda_event.get("requestContext"):
|
if isinstance(lambda_event, dict) and lambda_event.get(
|
||||||
|
"requestContext"
|
||||||
|
):
|
||||||
span.set_attribute(SpanAttributes.FAAS_TRIGGER, "http")
|
span.set_attribute(SpanAttributes.FAAS_TRIGGER, "http")
|
||||||
|
|
||||||
if lambda_event.get("version") == "2.0":
|
if lambda_event.get("version") == "2.0":
|
||||||
|
@ -399,6 +399,15 @@ class TestAwsLambdaInstrumentor(TestBase):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_lambda_handles_list_event(self):
|
||||||
|
AwsLambdaInstrumentor().instrument()
|
||||||
|
|
||||||
|
mock_execute_lambda([{"message": "test"}])
|
||||||
|
|
||||||
|
spans = self.memory_exporter.get_finished_spans()
|
||||||
|
|
||||||
|
assert spans
|
||||||
|
|
||||||
def test_uninstrument(self):
|
def test_uninstrument(self):
|
||||||
AwsLambdaInstrumentor().instrument()
|
AwsLambdaInstrumentor().instrument()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user