Skip to content

Commit ca9e744

Browse files
author
Puneet Singhwaiya
committed
Adding Environment Variable for Auto Instrumentation
1 parent 896f6f5 commit ca9e744

File tree

1 file changed

+5
-3
lines changed
  • instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django

1 file changed

+5
-3
lines changed

instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,13 @@ def _instrument(self, **kwargs):
388388

389389
is_sql_commentor_enabled = kwargs.pop("is_sql_commentor_enabled", None)
390390

391-
middleware_position = kwargs.pop("middleware_position", 0)
391+
otel_position = environ.get("OTEL_PYTHON_DJANGO_MIDDLEWARE_POSITION")
392+
middleware_position = int(otel_position) if otel_position is not None else kwargs.pop("middleware_position", 0)
393+
392394
if len(settings_middleware) < middleware_position:
393395
_logger.debug(
394-
"The middleware_position you provided (%d) is less than the current number of middlewares (%d). \
395-
Since the number of middlewares is less than the total, the Otel middleware will be appended at the end of the middleware chain.",
396+
"The middleware_position you provided (%d) is greater than the current number of middlewares (%d). \
397+
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.",
396398
middleware_position,
397399
len(settings_middleware),
398400
)

0 commit comments

Comments
 (0)