Skip to content

Commit 4e9fa5c

Browse files
committed
pyramid: pass request attributes at span creation
To ease sampling work.
1 parent dcb3316 commit 4e9fa5c

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

  • instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid

instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,29 @@ def _before_traversal(event):
115115
else:
116116
span_name = otel_wsgi.get_default_span_name(request_environ)
117117

118+
attributes = otel_wsgi.collect_request_attributes(
119+
request_environ, _sem_conv_opt_in_mode
120+
)
121+
if request.matched_route:
122+
attributes[HTTP_ROUTE] = request.matched_route.pattern
123+
118124
span, token = _start_internal_or_server_span(
119125
tracer=tracer,
120126
span_name=span_name,
121127
start_time=start_time,
122128
context_carrier=request_environ,
123129
context_getter=otel_wsgi.wsgi_getter,
130+
attributes=attributes,
124131
)
125132

126133
if span.is_recording():
127-
attributes = otel_wsgi.collect_request_attributes(
128-
request_environ, _sem_conv_opt_in_mode
129-
)
130-
if request.matched_route:
131-
attributes[HTTP_ROUTE] = request.matched_route.pattern
134+
attributes = {}
132135
_set_http_url(
133136
attributes,
134137
redact_url(wsgiref_util.request_uri(request_environ)),
135138
_sem_conv_opt_in_mode,
136139
)
137-
for key, value in attributes.items():
138-
span.set_attribute(key, value)
140+
span.set_attributes(attributes)
139141
if span.kind == trace.SpanKind.SERVER:
140142
custom_attributes = (
141143
otel_wsgi.collect_custom_request_headers_attributes(

0 commit comments

Comments
 (0)