mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-23 08:16:14 +00:00
fix otel middleware instrumentation (#13219)
* fix otel instrumentation * fix name conflict
This commit is contained in:
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.ready import isInMainThread, isRunningBackup
|
||||||
from InvenTree.sentry import default_sentry_dsn, init_sentry
|
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.validators import invalid_site_url_hint
|
||||||
from InvenTree.version import checkMinPythonVersion, inventreeCommitHash
|
from InvenTree.version import checkMinPythonVersion, inventreeCommitHash
|
||||||
from users.oauth2_scopes import oauth2_scopes
|
from users.oauth2_scopes import oauth2_scopes
|
||||||
@@ -702,6 +703,7 @@ TRACING_ENABLED = (
|
|||||||
TRACING_DETAILS: Optional[dict] = tracing.configure_tracing(
|
TRACING_DETAILS: Optional[dict] = tracing.configure_tracing(
|
||||||
DB_ENGINE, TRACING_ENABLED, inventree_tags
|
DB_ENGINE, TRACING_ENABLED, inventree_tags
|
||||||
)
|
)
|
||||||
|
MIDDLEWARE = ensure_otel_middleware(MIDDLEWARE)
|
||||||
|
|
||||||
# Cache configuration
|
# Cache configuration
|
||||||
GLOBAL_CACHE_ENABLED = is_global_cache_enabled()
|
GLOBAL_CACHE_ENABLED = is_global_cache_enabled()
|
||||||
|
|||||||
@@ -173,6 +173,14 @@ def setup_tracing(
|
|||||||
TRACE_PID = os.getpid()
|
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
|
def setup_instruments(db_engine: str): # pragma: no cover
|
||||||
"""Run auto-instrumentation for OpenTelemetry tracing."""
|
"""Run auto-instrumentation for OpenTelemetry tracing."""
|
||||||
if not DjangoInstrumentor()._is_instrumented_by_opentelemetry:
|
if not DjangoInstrumentor()._is_instrumented_by_opentelemetry:
|
||||||
|
|||||||
Reference in new issue
Block a user