-
Notifications
You must be signed in to change notification settings - Fork 543
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
django: Fix carrier usage on ASGI requests #767
django: Fix carrier usage on ASGI requests #767
Conversation
742101b
to
157c260
Compare
would be nice to add a small test case so we detect breakage with ASGI context extraction. |
Happy to provide a test, but didn't find an easy way to do it, without adding a propagator as dependency, or mocking attach/extract and validating what is received there. If you have a better test scenario in mind, I can definitely implement it and add it to this PR. |
@owais, I was able to add a test by taking advantage of how the default propagator works, so we check the provided |
propagator as test dep sounds fine. I think all instrumentations that propagate context should do this if they don't already. |
For ASGI requests, we must use `request.scope` instead of `request.META`. This is because `ASGIGetter` retrieves the `headers` key from the carrier [0], which is only present in `request.scope`. [0] https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py#L133
14cca2e
to
22c8b1f
Compare
* django: Fix carrier usage on ASGI requests For ASGI requests, we must use `request.scope` instead of `request.META`. This is because `ASGIGetter` retrieves the `headers` key from the carrier [0], which is only present in `request.scope`. [0] https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py#L133 * Add unit tests
* django: Fix carrier usage on ASGI requests For ASGI requests, we must use `request.scope` instead of `request.META`. This is because `ASGIGetter` retrieves the `headers` key from the carrier [0], which is only present in `request.scope`. [0] https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py#L133 * Add unit tests
Description
For ASGI requests, we must use
request.scope
instead ofrequest.META
. This is becauseASGIGetter
retrieves theheaders
key from the carrier [0], which is only present inrequest.scope
.[0] https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py#L133
Type of change
How Has This Been Tested?
aws
propagator and requests including header:X-Amzn-Trace-Id: Root=1-5759e988-bd862e3fe1be46a994272793; Parent=53995c3f42cd8ad8; Sampled=1
Does This PR Require a Core Repo Change?
Checklist: