From 4e9fa5ce59bc2920223fa5346df09b3e96a9d766 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 23 Jan 2026 17:05:43 +0100 Subject: [PATCH 1/2] pyramid: pass request attributes at span creation To ease sampling work. --- .../instrumentation/pyramid/callbacks.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py index b3c45944b3..68d51bf155 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py @@ -115,27 +115,29 @@ def _before_traversal(event): else: span_name = otel_wsgi.get_default_span_name(request_environ) + attributes = otel_wsgi.collect_request_attributes( + request_environ, _sem_conv_opt_in_mode + ) + if request.matched_route: + attributes[HTTP_ROUTE] = request.matched_route.pattern + span, token = _start_internal_or_server_span( tracer=tracer, span_name=span_name, start_time=start_time, context_carrier=request_environ, context_getter=otel_wsgi.wsgi_getter, + attributes=attributes, ) if span.is_recording(): - attributes = otel_wsgi.collect_request_attributes( - request_environ, _sem_conv_opt_in_mode - ) - if request.matched_route: - attributes[HTTP_ROUTE] = request.matched_route.pattern + attributes = {} _set_http_url( attributes, redact_url(wsgiref_util.request_uri(request_environ)), _sem_conv_opt_in_mode, ) - for key, value in attributes.items(): - span.set_attribute(key, value) + span.set_attributes(attributes) if span.kind == trace.SpanKind.SERVER: custom_attributes = ( otel_wsgi.collect_custom_request_headers_attributes( From 6337461df5950f3ce4ac8575d98be419934fbe95 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 23 Jan 2026 17:09:34 +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..6c702d6cbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3993](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3993)) - `opentelemetry-instrumentation-pyramid` Implement new semantic convention opt-in migration ([#3982](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3982)) +- `opentelemetry-instrumentation-pyramid`: pass request attributes at span creation + ([#4139](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4139)) ### Fixed