-
Notifications
You must be signed in to change notification settings - Fork 820
Fix DjangoInstrumentor exemplars generation for http.server.(request.)duration #3945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix DjangoInstrumentor exemplars generation for http.server.(request.)duration #3945
Conversation
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
| self.assertTrue(len(metrics_data.resource_metrics) > 0) | ||
|
|
||
| duration_metric = None | ||
| metric_names = [] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't used! Repurposed for more assertions in 10d7c56
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also do
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep it as the spread-out nested loops for visual spoon feed of metrics structure, if that's ok.
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.
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
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.