Skip to content

Commit fedf944

Browse files
authored
Fixes issue with headers not being a dict in AWS lambda instr (#1055)
1 parent b6964cc commit fedf944

File tree

2 files changed

+12
-3
lines changed
  • instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda

2 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.11.1-0.30b1...HEAD)
99

10+
### Fixed
11+
- `opentelemetry-instrumentation-aws-lambda` Fixed an issue - in some rare cases (API GW proxy integration test)
12+
headers are set to None, breaking context propagators.
13+
([#1055](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1055))
1014

1115
## [1.11.1-0.30b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.1-0.30b1) - 2022-04-21
1216

1317
### Added
1418
- `opentelemetry-instrumentation-starlette` Capture custom request/response headers in span attributes
1519
([#1046])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1046)
1620

21+
### Fixed
1722
- Prune autoinstrumentation sitecustomize module directory from PYTHONPATH immediately
1823
([#1066](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1066))
1924

@@ -23,13 +28,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2328
- `opentelemetry-instrumentation-pyramid` Fixed which package is the correct caller in _traced_init.
2429
([#830](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/830))
2530
- `opentelemetry-instrumentation-tornado` Fix Tornado errors mapping to 500
26-
([#1048])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1048)
31+
([#1048](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1048))
2732
- `opentelemetry-instrumentation-urllib` make span attributes available to sampler
2833
([1014](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1014))
2934
- `opentelemetry-instrumentation-flask` Fix non-recording span bug
30-
([#999])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/999)
35+
([#999](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/999))
3136
- `opentelemetry-instrumentation-tornado` Fix non-recording span bug
32-
([#999])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/999)
37+
([#999](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/999))
3338

3439
### Added
3540

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def _default_event_context_extractor(lambda_event: Any) -> Context:
108108
Assumes the Lambda Event is a map with the headers under the 'headers' key.
109109
This is the mapping to use when the Lambda is invoked by an API Gateway
110110
REST API where API Gateway is acting as a pure proxy for the request.
111+
Protects headers from being something other than dictionary, as this
112+
is what downstream propagators expect.
111113
112114
See more:
113115
https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
@@ -118,12 +120,14 @@ def _default_event_context_extractor(lambda_event: Any) -> Context:
118120
Returns:
119121
A Context with configuration found in the event.
120122
"""
123+
headers = None
121124
try:
122125
headers = lambda_event["headers"]
123126
except (TypeError, KeyError):
124127
logger.debug(
125128
"Extracting context from Lambda Event failed: either enable X-Ray active tracing or configure API Gateway to trigger this Lambda function as a pure proxy. Otherwise, generated spans will have an invalid (empty) parent context."
126129
)
130+
if not isinstance(headers, dict):
127131
headers = {}
128132
return get_global_textmap().extract(headers)
129133

0 commit comments

Comments
 (0)