Skip to content

Conversation

@tammy-baylis-swi
Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi commented Nov 14, 2025

Description

When exemplars are opted into via metrics SDK, this fixes DjangoInstrumentor middleware's generation of exemplars for http.server.request.duration and http.server.duration (new and old semconv respectively) so trace ID and span ID are no longer empty. Similar to Flask fix in #3912 -- test dep updates will conflict

Fixes #3951

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Added unit tests
  • Added new Flask docker test
  • Installed changes to instrumented app

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@tammy-baylis-swi tammy-baylis-swi changed the title Fix FlaskInstrumentor exemplars generation for http.server.(request.)duration Fix DjangoInstrumentor exemplars generation for http.server.(request.)duration Nov 14, 2025
@tammy-baylis-swi tammy-baylis-swi marked this pull request as ready for review November 17, 2025 19:41
@tammy-baylis-swi tammy-baylis-swi requested a review from a team as a code owner November 17, 2025 19:41
self.assertTrue(len(metrics_data.resource_metrics) > 0)

duration_metric = None
metric_names = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this variable?

Comment on lines +98 to +111
for resource_metric in metrics_data.resource_metrics:
for scope_metric in resource_metric.scope_metrics:
for metric in scope_metric.metrics:
metric_names.append(metric.name)
if metric.name in [
"http.server.request.duration",
"http.server.duration",
]:
duration_metric = metric
break
if duration_metric:
break
if duration_metric:
break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also do

Suggested change
for resource_metric in metrics_data.resource_metrics:
for scope_metric in resource_metric.scope_metrics:
for metric in scope_metric.metrics:
metric_names.append(metric.name)
if metric.name in [
"http.server.request.duration",
"http.server.duration",
]:
duration_metric = metric
break
if duration_metric:
break
if duration_metric:
break
duration_metric = next((metric for metric in self.get_sorted_metrics() if metric.name in ("http.server.request.duration", "http.server.duration")), None)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DjangoInstrumentor http.server.request.duration exemplars are missing span context

2 participants