diff --git a/apps/api/manage.py b/apps/api/manage.py index a79268b37c..6f69f44252 100644 --- a/apps/api/manage.py +++ b/apps/api/manage.py @@ -8,6 +8,13 @@ import sys if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "plane.settings.production") + + # Bootstrap OpenTelemetry before Django imports so runserver and + # management commands are instrumented too. No-op unless OTEL_ENABLED=1. + from plane.observability.setup import configure_otel + + configure_otel() + try: from django.core.management import execute_from_command_line except ImportError as exc: diff --git a/apps/api/plane/asgi.py b/apps/api/plane/asgi.py index 9d3bd6b07a..e7db9b2d31 100644 --- a/apps/api/plane/asgi.py +++ b/apps/api/plane/asgi.py @@ -4,15 +4,17 @@ import os -from channels.routing import ProtocolTypeRouter -from django.core.asgi import get_asgi_application - -django_asgi_app = get_asgi_application() - - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "plane.settings.production") + +# Bootstrap OpenTelemetry before Django wires up so DjangoInstrumentor can +# patch the ASGI handler. No-op unless OTEL_ENABLED=1. +from plane.observability.setup import configure_otel # noqa: E402 + +configure_otel() + +from channels.routing import ProtocolTypeRouter # noqa: E402 +from django.core.asgi import get_asgi_application # noqa: E402 + # Initialize Django ASGI application early to ensure the AppRegistry # is populated before importing code that may import ORM models. - - application = ProtocolTypeRouter({"http": get_asgi_application()}) diff --git a/apps/api/plane/wsgi.py b/apps/api/plane/wsgi.py index 4c8a791636..1b4faf4873 100644 --- a/apps/api/plane/wsgi.py +++ b/apps/api/plane/wsgi.py @@ -11,8 +11,14 @@ It exposes the WSGI callable as a module-level variable named ``application``. import os -from django.core.wsgi import get_wsgi_application - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "plane.settings.production") +# Bootstrap OpenTelemetry before Django wires up so DjangoInstrumentor can +# patch the WSGI handler. No-op unless OTEL_ENABLED=1. +from plane.observability.setup import configure_otel # noqa: E402 + +configure_otel() + +from django.core.wsgi import get_wsgi_application # noqa: E402 + application = get_wsgi_application()