Skip to content

Commit

Permalink
Prevent AttributeError from being raised when lambda event is a list …
Browse files Browse the repository at this point in the history
…rather than a dict
  • Loading branch information
e-pavlica committed Mar 30, 2023
1 parent e4d8f10 commit 642a653
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
# 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/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")

if lambda_event.get("version") == "2.0":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@ def test_api_gateway_http_api_proxy_event_sets_attributes(self):
},
)

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):
AwsLambdaInstrumentor().instrument()

Expand Down

0 comments on commit 642a653

Please sign in to comment.