Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ endif::[]
===== Bug fixes

* Fix url argument fetching in aiohttp_client instrumentation {pull}1890[#1890]
* Fix a bug in the AWS Lambda instrumentation when `event["headers"] is None` {pull}1907[#1907]



Expand Down
4 changes: 2 additions & 2 deletions elasticapm/contrib/serverless/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __enter__(self):
# service like Step Functions, and is unlikely to be standardized
# in any way. We just have to rely on our defaults in this case.
self.event = {}
trace_parent = TraceParent.from_headers(self.event.get("headers", {}))
trace_parent = TraceParent.from_headers(self.event.get("headers") or {})

global COLD_START
cold_start = COLD_START
Expand Down Expand Up @@ -525,7 +525,7 @@ def get_url_dict(event: dict) -> dict:
"""
Reconstruct URL from API Gateway
"""
headers = event.get("headers", {})
headers = event.get("headers") or {}
protocol = headers.get("X-Forwarded-Proto", headers.get("x-forwarded-proto", "https"))
host = headers.get("Host", headers.get("host", ""))
stage = nested_key(event, "requestContext", "stage") or ""
Expand Down
15 changes: 15 additions & 0 deletions tests/contrib/serverless/aws_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,18 @@ def test_func(event, context):
assert b"metadata" in request.data
assert b"transaction" in request.data
sending_elasticapm_client.close()


def test_with_headers_as_none(event_api2, context, elasticapm_client):
os.environ["AWS_LAMBDA_FUNCTION_NAME"] = "test_func"

@capture_serverless
def test_func(event, context):
with capture_span("test_span"):
time.sleep(0.01)
return {"statusCode": 200, "headers": {"foo": "bar"}}

event_api2["headers"] = None

test_func(event_api2, context)
assert len(elasticapm_client.events[constants.TRANSACTION]) == 1