diff --git a/engine/engine/wsgi.py b/engine/engine/wsgi.py index c95992be..1642bd9d 100644 --- a/engine/engine/wsgi.py +++ b/engine/engine/wsgi.py @@ -40,3 +40,22 @@ if settings.OTEL_TRACING_ENABLED and settings.OTEL_EXPORTER_OTLP_ENDPOINT: except ModuleNotFoundError: # Only works under uwsgi web server environment pass + +if settings.PYROSCOPE_PROFILER_ENABLED: + try: + import pyroscope + from uwsgidecorators import postfork + + @postfork + def init_pyroscope(): + pyroscope.configure( + application_name=settings.PYROSCOPE_APPLICATION_NAME, + server_address=settings.PYROSCOPE_SERVER_ADDRESS, + auth_token=settings.PYROSCOPE_AUTH_TOKEN, + detect_subprocesses=True, + tags={"celery_worker": settings.PYROSCOPE_CELERY_WORKER_QUEUE}, + ) + + except ModuleNotFoundError: + # Only works under uwsgi web server environment + pass diff --git a/engine/settings/base.py b/engine/settings/base.py index c647fb51..97a8fee0 100644 --- a/engine/settings/base.py +++ b/engine/settings/base.py @@ -678,15 +678,7 @@ MIGRATION_LINTER_OPTIONS = {"exclude_apps": ["social_django", "silk", "fcm_djang MIGRATION_LINTER_OVERRIDE_MAKEMIGRATIONS = True PYROSCOPE_PROFILER_ENABLED = getenv_boolean("PYROSCOPE_PROFILER_ENABLED", default=False) -if PYROSCOPE_PROFILER_ENABLED: - import pyroscope - - pyroscope.configure( - application_name=os.getenv("PYROSCOPE_APPLICATION_NAME", "oncall"), - server_address=os.getenv("PYROSCOPE_SERVER_ADDRESS", "http://pyroscope:4040"), - auth_token=os.getenv("PYROSCOPE_AUTH_TOKEN", ""), - detect_subprocesses=True, - tags={ - "celery_worker": os.getenv("CELERY_WORKER_QUEUE", None), - }, - ) +PYROSCOPE_APPLICATION_NAME = os.getenv("PYROSCOPE_APPLICATION_NAME", "oncall") +PYROSCOPE_SERVER_ADDRESS = os.getenv("PYROSCOPE_SERVER_ADDRESS", "http://pyroscope:4040") +PYROSCOPE_AUTH_TOKEN = os.getenv("PYROSCOPE_AUTH_TOKEN", "") +PYROSCOPE_CELERY_WORKER_QUEUE = os.getenv("CELERY_WORKER_QUEUE", None)