-
Notifications
You must be signed in to change notification settings - Fork 809
Fix FlaskInstrumentor exemplars generation for http.server.(request.)duration #3912
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 FlaskInstrumentor exemplars generation for http.server.(request.)duration #3912
Conversation
| # Get the span from wrapped_app_environ and re-create context manually | ||
| # to pass to histogram for exemplars generation | ||
| span = wrapped_app_environ.get(_ENVIRON_SPAN_KEY) | ||
| if span: |
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 do you think of doing something like metrics_context = context.set_value(_SPAN_KEY, span) if span else None and reuse the same record call to keep the code more compact?
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.
Yes! Changed in 6e38a77
Description
When exemplars are opted into via metrics SDK, this fixes FlaskInstrumentor generation of exemplars for
http.server.request.durationandhttp.server.duration(new and old semconv respectively) so trace ID and span ID are no longer empty.How? The metrics SDK implementation depends on its received OTel context being valid with a real span context inside it -- see ExemplarBucket.offer. Some metrics like these from FlaskInstrumentor don't have their values known until spans are complete and no longer in the current context, so metrics are recorded after spans ended. We now pass a new OTel context containing the Flask-stashed span.
Fixes #3913
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.