botocore: Fix span inject for lambda invoke (#663)

* Botocore: Fix span inject for lambda invoke

* for lambda invoke span injection happend to early which resulted in the botocore
  span being injected instead of the actual botocore span

* changelog

Co-authored-by: alrex <aboten@lightstep.com>
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
This commit is contained in:
Mario Jonke
2021-09-09 16:35:48 +02:00
committed by GitHub
parent 97e9f2f9ef
commit 3e9adfddb0
3 changed files with 12 additions and 10 deletions

View File

@ -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))

View File

@ -150,15 +150,15 @@ class BotocoreInstrumentor(BaseInstrumentor):
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)

View File

@ -435,11 +435,13 @@ class TestBotocoreInstrumentor(TestBase):
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)