Skip to content

Commit f82f6a2

Browse files
Fix FlaskInstrumentor http.server.duration exemplars
1 parent ea25349 commit f82f6a2

File tree

1 file changed

+14
-3
lines changed
  • instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask

1 file changed

+14
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,20 @@ def _start_response(status, response_headers, *args, **kwargs):
408408
# http.target to be included in old semantic conventions
409409
duration_attrs_old[HTTP_TARGET] = str(request_route)
410410

411-
duration_histogram_old.record(
412-
max(round(duration_s * 1000), 0), duration_attrs_old
413-
)
411+
# Get the span from wrapped_app_environ and re-create context manually
412+
# to pass to histogram for exemplars generation
413+
span = wrapped_app_environ.get(_ENVIRON_SPAN_KEY)
414+
if span:
415+
exemplar_context = context.set_value(_SPAN_KEY, span)
416+
duration_histogram_old.record(
417+
max(round(duration_s * 1000), 0),
418+
duration_attrs_old,
419+
context=exemplar_context,
420+
)
421+
else:
422+
duration_histogram_old.record(
423+
max(round(duration_s * 1000), 0), duration_attrs_old
424+
)
414425
if duration_histogram_new:
415426
duration_attrs_new = otel_wsgi._parse_duration_attrs(
416427
attributes, _StabilityMode.HTTP

0 commit comments

Comments
 (0)