diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c18e2ca43..15c62f7077 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - `opentelemetry-instrumentation-botocore` Unpatch botocore Endpoint.prepare_request on uninstrument ([#664](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/664)) +- `opentelemetry-instrumentation-botocore` Fix span injection for lambda invoke + ([#663](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/663)) ## [1.5.0-0.24b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.5.0-0.24b0) - 2021-08-26 @@ -24,8 +26,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-fastapi` Allow instrumentation of newer FastAPI versions. ([#602](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/602)) - -### Changed - Enable explicit `excluded_urls` argument in `opentelemetry-instrumentation-flask` ([#604](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/604)) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py index 634ba8b577..3212866b2e 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py @@ -150,15 +150,15 @@ def _patched_api_call(self, original_func, instance, args, kwargs): error = None result = None - # inject trace context into payload headers for lambda Invoke - if BotocoreInstrumentor._is_lambda_invoke( - service_name, operation_name, api_params - ): - BotocoreInstrumentor._patch_lambda_invoke(api_params) - with self._tracer.start_as_current_span( "{}".format(service_name), kind=SpanKind.CLIENT, ) as span: + # inject trace context into payload headers for lambda Invoke + if BotocoreInstrumentor._is_lambda_invoke( + service_name, operation_name, api_params + ): + BotocoreInstrumentor._patch_lambda_invoke(api_params) + if span.is_recording(): span.set_attribute("aws.operation", operation_name) span.set_attribute("aws.region", instance.meta.region_name) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py index 96ecac2b00..3c6a50251f 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py @@ -435,11 +435,13 @@ def test_lambda_invoke_propagation(self): self.assertIn(MockTextMapPropagator.TRACE_ID_KEY, headers) self.assertEqual( - "0", headers[MockTextMapPropagator.TRACE_ID_KEY], + str(spans[2].get_span_context().trace_id), + headers[MockTextMapPropagator.TRACE_ID_KEY], ) self.assertIn(MockTextMapPropagator.SPAN_ID_KEY, headers) self.assertEqual( - "0", headers[MockTextMapPropagator.SPAN_ID_KEY], + str(spans[2].get_span_context().span_id), + headers[MockTextMapPropagator.SPAN_ID_KEY], ) finally: set_global_textmap(previous_propagator)