From fcf7dbb0a9c6e3de801e904226115cd717c8d60c Mon Sep 17 00:00:00 2001 From: Jakub Wach Date: Fri, 15 Apr 2022 15:26:57 +0200 Subject: [PATCH 1/3] Fixes issue with headers not being a dict in AWS lambda instr --- CHANGELOG.md | 9 ++++++--- .../opentelemetry/instrumentation/aws_lambda/__init__.py | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7549c25ef..6eb484d44d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,16 +8,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.10.0-0.29b0...HEAD) ### Fixed +- `opentelemetry-instrumentation-aws-lambda` Fixed an issue - in some rare cases (API GW proxy integration test) + headers are set to None, breaking context propagators. + ([#1055](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1055)) - `opentelemetry-instrumentation-pyramid` Fixed which package is the correct caller in _traced_init. ([#830](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/830)) - `opentelemetry-instrumentation-tornado` Fix Tornado errors mapping to 500 - ([#1048])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1048) + ([#1048](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1048)) - `opentelemetry-instrumentation-urllib` make span attributes available to sampler ([1014](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1014)) - `opentelemetry-instrumentation-flask` Fix non-recording span bug - ([#999])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/999) + ([#999](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/999)) - `opentelemetry-instrumentation-tornado` Fix non-recording span bug - ([#999])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/999) + ([#999](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/999)) ### Added - `opentelemetry-instrumentation-fastapi` Capture custom request/response headers in span attributes diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py b/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py index ad83418fbb..17f8c3252b 100644 --- a/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py @@ -108,6 +108,8 @@ def _default_event_context_extractor(lambda_event: Any) -> Context: Assumes the Lambda Event is a map with the headers under the 'headers' key. This is the mapping to use when the Lambda is invoked by an API Gateway REST API where API Gateway is acting as a pure proxy for the request. + Protects headers from being something other than dictionary, as this + is what downstream propagators See more: 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: Returns: A Context with configuration found in the event. """ + headers = None try: headers = lambda_event["headers"] except (TypeError, KeyError): logger.debug( "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." ) + if not isinstance(headers, dict): headers = {} return get_global_textmap().extract(headers) From 6a0e0c05ab7cd35c196903738dac72ac3d6aca90 Mon Sep 17 00:00:00 2001 From: Jakub Wach Date: Thu, 21 Apr 2022 13:41:29 +0200 Subject: [PATCH 2/3] code review --- CHANGELOG.md | 6 ++++-- .../opentelemetry/instrumentation/aws_lambda/__init__.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e824066bd..12869cf2a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.11.0-0.30b0...HEAD) -## [1.11.0-0.30b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.0-0.30b0) - 2022-04-18 - ### Fixed - `opentelemetry-instrumentation-aws-lambda` Fixed an issue - in some rare cases (API GW proxy integration test) headers are set to None, breaking context propagators. ([#1055](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1055)) + +## [1.11.0-0.30b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.0-0.30b0) - 2022-04-18 + +### Fixed - `opentelemetry-instrumentation-pyramid` Fixed which package is the correct caller in _traced_init. ([#830](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/830)) - `opentelemetry-instrumentation-tornado` Fix Tornado errors mapping to 500 diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py b/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py index 17f8c3252b..d791b2f17c 100644 --- a/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py @@ -109,7 +109,7 @@ def _default_event_context_extractor(lambda_event: Any) -> Context: This is the mapping to use when the Lambda is invoked by an API Gateway REST API where API Gateway is acting as a pure proxy for the request. Protects headers from being something other than dictionary, as this - is what downstream propagators + is what downstream propagators expect. See more: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format From dd11dd1a04a98ca50b63b5591252e04e55659558 Mon Sep 17 00:00:00 2001 From: Jakub Wach Date: Mon, 25 Apr 2022 11:48:10 +0200 Subject: [PATCH 3/3] changelog - after main merge --- CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c864f9447b..051b3d115d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.11.1-0.30b1...HEAD) +### Fixed +- `opentelemetry-instrumentation-aws-lambda` Fixed an issue - in some rare cases (API GW proxy integration test) + headers are set to None, breaking context propagators. + ([#1055](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1055)) ## [1.11.1-0.30b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.1-0.30b1) - 2022-04-21 @@ -15,9 +19,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1046])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1046) ### Fixed -- `opentelemetry-instrumentation-aws-lambda` Fixed an issue - in some rare cases (API GW proxy integration test) - headers are set to None, breaking context propagators. - ([#1055](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1055)) - Prune autoinstrumentation sitecustomize module directory from PYTHONPATH immediately ([#1066](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1066))