Skip to content

int check for middleware position and updated changelog #1

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

Open
wants to merge 1 commit into
base: fix-1781-alt
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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)
([#2834]https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2834)

### Added
- `opentelemetry-instrumentation-kafka-python` Add instrumentation to `consume` method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,23 @@ def _instrument(self, **kwargs):
is_sql_commentor_enabled = kwargs.pop("is_sql_commentor_enabled", None)

otel_position = environ.get("OTEL_PYTHON_DJANGO_MIDDLEWARE_POSITION")
middleware_position = int(otel_position) if otel_position is not None else kwargs.pop("middleware_position", 0)
try:
middleware_position = int(otel_position)
except (ValueError, TypeError):
_logger.debug(
"The middleware_position you provided (%s) is not an integer. Defaulting to 0.",
otel_position,
)
middleware_position = kwargs.pop("middleware_position", 0)

if len(settings_middleware) < middleware_position:
_logger.debug(
"The middleware_position you provided (%d) is greater than the current number of middlewares (%d). \
Since the number of middlewares is less than the total number of middlewares, the Otel middleware will be appended at the end of the middleware chain.",
"The middleware_position you provided (%s) is greater than the number of middlewares (%s). Defaulting "
"the middleware_position to 0.",
middleware_position,
len(settings_middleware),
)
middleware_position = len(settings_middleware)
middleware_position = 0
if is_sql_commentor_enabled:
settings_middleware.insert(
middleware_position, self._sql_commenter_middleware
Expand Down