Skip to content

Commit 9f0b7b5

Browse files
authored
tornado: pass request attributes at span creation (#4140)
* tornado: pass request attributes at span creation To ease sampling. * Add changelog
1 parent 5babfb2 commit 9f0b7b5

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

  • instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4343
([#4108](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4108))
4444
- `opentelemetry-instrumentation-tornado`: Implement new semantic convention opt-in migration
4545
([#3993](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3993))
46+
- `opentelemetry-instrumentation-tornado`: pass request attributes at span creation
47+
([#4140](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4140))
4648
- `opentelemetry-instrumentation-pyramid` Implement new semantic convention opt-in migration
4749
([#3982](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3982))
4850

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -754,22 +754,21 @@ def _get_full_handler_name(handler):
754754

755755

756756
def _start_span(tracer, handler, sem_conv_opt_in_mode) -> _TraceContext:
757+
attributes = _get_attributes_from_request(
758+
handler.request, sem_conv_opt_in_mode
759+
)
757760
span, token = _start_internal_or_server_span(
758761
tracer=tracer,
759762
span_name=_get_default_span_name(handler.request),
760763
start_time=time_ns(),
761764
context_carrier=handler.request.headers,
762765
context_getter=textmap.default_getter,
766+
attributes=attributes,
763767
)
764768

765769
if span.is_recording():
766-
attributes = _get_attributes_from_request(
767-
handler.request, sem_conv_opt_in_mode
768-
)
769-
for key, value in attributes.items():
770-
span.set_attribute(key, value)
771770
span.set_attribute("tornado.handler", _get_full_handler_name(handler))
772-
if span.is_recording() and span.kind == trace.SpanKind.SERVER:
771+
if span.kind == trace.SpanKind.SERVER:
773772
custom_attributes = _collect_custom_request_headers_attributes(
774773
handler.request.headers
775774
)

0 commit comments

Comments
 (0)