From 0f11f8ede77010c9031de8961b2316f0ab5039cb Mon Sep 17 00:00:00 2001 From: Sai Chander Date: Wed, 11 Sep 2024 07:56:21 +0530 Subject: [PATCH] Django instrument middleware location is configurable via django settings --- .../src/opentelemetry/instrumentation/django/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py index d37c45993c..0af25ef3bf 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py @@ -388,10 +388,11 @@ def _instrument(self, **kwargs): is_sql_commentor_enabled = kwargs.pop("is_sql_commentor_enabled", None) + opentelemetry_middleware_index = getattr(settings, 'OTEL_MIDDLEWARE_INDEX', 0) if is_sql_commentor_enabled: - settings_middleware.insert(0, self._sql_commenter_middleware) + settings_middleware.insert(opentelemetry_middleware_index, self._sql_commenter_middleware) - settings_middleware.insert(0, self._opentelemetry_middleware) + settings_middleware.insert(opentelemetry_middleware_index, self._opentelemetry_middleware) setattr(settings, _middleware_setting, settings_middleware)