fix otel middleware instrumentation (#13219)

* fix otel instrumentation

* fix name conflict
This commit is contained in:
Matthias Mair authored and GitHub committed 2026-11-08 07:33:17 +11:00
1 parent da655f2312
commit b4e74791e6
2 files changed
+10

No files matched your search

@@ -34,6 +34,7 @@ from InvenTree.config import (
)
from InvenTree.ready import isInMainThread, isRunningBackup
from InvenTree.sentry import default_sentry_dsn, init_sentry
from InvenTree.tracing import ensure_otel_middleware
from InvenTree.validators import invalid_site_url_hint
from InvenTree.version import checkMinPythonVersion, inventreeCommitHash
from users.oauth2_scopes import oauth2_scopes
@@ -702,6 +703,7 @@ TRACING_ENABLED = (
TRACING_DETAILS: Optional[dict] = tracing.configure_tracing(
DB_ENGINE, TRACING_ENABLED, inventree_tags
)
MIDDLEWARE = ensure_otel_middleware(MIDDLEWARE)
# Cache configuration
GLOBAL_CACHE_ENABLED = is_global_cache_enabled()
@@ -173,6 +173,14 @@ def setup_tracing(
TRACE_PID = os.getpid()
def ensure_otel_middleware(middleware):
"""Ensure the OTELmiddleware is the first entry in MIDDLEWARE."""
if not DjangoInstrumentor().is_instrumented_by_opentelemetry:
return list(middleware)
otel = DjangoInstrumentor._opentelemetry_middleware
return [otel, *(m for m in middleware if m != otel)]
def setup_instruments(db_engine: str): # pragma: no cover
"""Run auto-instrumentation for OpenTelemetry tracing."""
if not DjangoInstrumentor()._is_instrumented_by_opentelemetry: