Skip to content

Commit 3e9adfd

Browse files
mariojonkealrexocelotl
authored
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 <[email protected]> Co-authored-by: Diego Hurtado <[email protected]>
1 parent 97e9f2f commit 3e9adfd

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Changed
1111
- `opentelemetry-instrumentation-botocore` Unpatch botocore Endpoint.prepare_request on uninstrument
1212
([#664](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/664))
13+
- `opentelemetry-instrumentation-botocore` Fix span injection for lambda invoke
14+
([#663](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/663))
1315

1416
## [1.5.0-0.24b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.5.0-0.24b0) - 2021-08-26
1517

@@ -24,8 +26,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2426

2527
- `opentelemetry-instrumentation-fastapi` Allow instrumentation of newer FastAPI versions.
2628
([#602](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/602))
27-
28-
### Changed
2929
- Enable explicit `excluded_urls` argument in `opentelemetry-instrumentation-flask`
3030
([#604](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/604))
3131

instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/__init__.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ def _patched_api_call(self, original_func, instance, args, kwargs):
150150
error = None
151151
result = None
152152

153-
# inject trace context into payload headers for lambda Invoke
154-
if BotocoreInstrumentor._is_lambda_invoke(
155-
service_name, operation_name, api_params
156-
):
157-
BotocoreInstrumentor._patch_lambda_invoke(api_params)
158-
159153
with self._tracer.start_as_current_span(
160154
"{}".format(service_name), kind=SpanKind.CLIENT,
161155
) as span:
156+
# inject trace context into payload headers for lambda Invoke
157+
if BotocoreInstrumentor._is_lambda_invoke(
158+
service_name, operation_name, api_params
159+
):
160+
BotocoreInstrumentor._patch_lambda_invoke(api_params)
161+
162162
if span.is_recording():
163163
span.set_attribute("aws.operation", operation_name)
164164
span.set_attribute("aws.region", instance.meta.region_name)

instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,13 @@ def test_lambda_invoke_propagation(self):
435435

436436
self.assertIn(MockTextMapPropagator.TRACE_ID_KEY, headers)
437437
self.assertEqual(
438-
"0", headers[MockTextMapPropagator.TRACE_ID_KEY],
438+
str(spans[2].get_span_context().trace_id),
439+
headers[MockTextMapPropagator.TRACE_ID_KEY],
439440
)
440441
self.assertIn(MockTextMapPropagator.SPAN_ID_KEY, headers)
441442
self.assertEqual(
442-
"0", headers[MockTextMapPropagator.SPAN_ID_KEY],
443+
str(spans[2].get_span_context().span_id),
444+
headers[MockTextMapPropagator.SPAN_ID_KEY],
443445
)
444446
finally:
445447
set_global_textmap(previous_propagator)

0 commit comments

Comments
 (0)