Skip to content

Commit ff3a2fb

Browse files
Request Flask attributes passed to Sampler
1 parent 890e5dd commit ff3a2fb

File tree

1 file changed

+10
-9
lines changed
  • instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,27 +364,28 @@ def _before_request():
364364
flask_request_environ = flask.request.environ
365365
span_name = get_default_span_name()
366366

367+
attributes = otel_wsgi.collect_request_attributes(
368+
flask_request_environ
369+
)
370+
if flask.request.url_rule:
371+
# For 404 that result from no route found, etc, we
372+
# don't have a url_rule.
373+
attributes[
374+
SpanAttributes.HTTP_ROUTE
375+
] = flask.request.url_rule.rule
367376
span, token = _start_internal_or_server_span(
368377
tracer=tracer,
369378
span_name=span_name,
370379
start_time=flask_request_environ.get(_ENVIRON_STARTTIME_KEY),
371380
context_carrier=flask_request_environ,
372381
context_getter=otel_wsgi.wsgi_getter,
382+
attributes=attributes,
373383
)
374384

375385
if request_hook:
376386
request_hook(span, flask_request_environ)
377387

378388
if span.is_recording():
379-
attributes = otel_wsgi.collect_request_attributes(
380-
flask_request_environ
381-
)
382-
if flask.request.url_rule:
383-
# For 404 that result from no route found, etc, we
384-
# don't have a url_rule.
385-
attributes[
386-
SpanAttributes.HTTP_ROUTE
387-
] = flask.request.url_rule.rule
388389
for key, value in attributes.items():
389390
span.set_attribute(key, value)
390391
if span.is_recording() and span.kind == trace.SpanKind.SERVER:

0 commit comments

Comments
 (0)