From 80b6ce7d7fb24eb9969c5393c4c7263cf7dec734 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 23 Jan 2026 17:30:08 +0100 Subject: [PATCH 1/2] tornado: pass request attributes at span creation To ease sampling. --- .../opentelemetry/instrumentation/tornado/__init__.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py index 58fc470cb5..190ee02cc8 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py @@ -754,22 +754,21 @@ def _get_full_handler_name(handler): def _start_span(tracer, handler, sem_conv_opt_in_mode) -> _TraceContext: + attributes = _get_attributes_from_request( + handler.request, sem_conv_opt_in_mode + ) span, token = _start_internal_or_server_span( tracer=tracer, span_name=_get_default_span_name(handler.request), start_time=time_ns(), context_carrier=handler.request.headers, context_getter=textmap.default_getter, + attributes=attributes, ) if span.is_recording(): - attributes = _get_attributes_from_request( - handler.request, sem_conv_opt_in_mode - ) - for key, value in attributes.items(): - span.set_attribute(key, value) span.set_attribute("tornado.handler", _get_full_handler_name(handler)) - if span.is_recording() and span.kind == trace.SpanKind.SERVER: + if span.kind == trace.SpanKind.SERVER: custom_attributes = _collect_custom_request_headers_attributes( handler.request.headers ) From 39699eb874abd7a1c625dfabb184ea1d3c615aec Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 23 Jan 2026 17:32:31 +0100 Subject: [PATCH 2/2] Add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f26a21d56..ea9fbe9e25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#4108](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4108)) - `opentelemetry-instrumentation-tornado`: Implement new semantic convention opt-in migration ([#3993](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3993)) +- `opentelemetry-instrumentation-tornado`: pass request attributes at span creation + ([#4140](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4140)) - `opentelemetry-instrumentation-pyramid` Implement new semantic convention opt-in migration ([#3982](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3982))