-
Notifications
You must be signed in to change notification settings - Fork 633
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
add middleware_position feature in django #1903
base: main
Are you sure you want to change the base?
Conversation
middleware_position = kwargs.pop("middleware_position", 0) | ||
if len(settings_middleware) < middleware_position: | ||
_logger.debug( | ||
"The middleware_position you provided (%d) is less than the current number of middlewares (%d). \ |
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.
"The middleware_position you provided (%d) is less than the current number of middlewares (%d). \ | |
"The middleware_position you provided (%d) is greater than the current number of middlewares (%d). \ |
if len(settings_middleware) < middleware_position: | ||
_logger.debug( | ||
"The middleware_position you provided (%d) is less than the current number of middlewares (%d). \ | ||
Since the number of middlewares is less than the total, the Otel middleware will be appended at the end of the middleware chain.", |
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 total
here?
...on/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py
Show resolved
Hide resolved
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.
May be a good idea to reconsider implementation
@@ -53,6 +53,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
([#1879](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1879)) | |||
- Add optional distro and configurator selection for auto-instrumentation | |||
([#1823](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1823)) | |||
- Add option to add Opentelemetry middleware at specific position in middleware chain | |||
([#1903]https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1903) |
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.
Please move this to the Unreleased section.
@@ -355,10 +355,23 @@ def _instrument(self, **kwargs): | |||
|
|||
is_sql_commentor_enabled = kwargs.pop("is_sql_commentor_enabled", None) | |||
|
|||
middleware_position = kwargs.pop("middleware_position", 0) |
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.
Can you add an OTEL_PYTHON_DJANGO_MIDDLEWARE_POSITION
env so that auto instrumentation people who use opentelemetry-instrument
can also use this capability?
@TheAnshul756 This PR has enough approvals, seems we only need a few fixes in order to merge it. 👍 |
Description
Feature to add middleware at specific location. Added keyword argument
middleware_position
which one can set to the number of middleware they want to add before otel middleware to start instrumentation.Fixes #1781
Type of change
How Has This Been Tested?
tox -e lint
tox -e test-instrumentation-django1
tox -e test-instrumentation-django2
tox -e test-instrumentation-django3
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.