Create a custom app, add python libraries setup using opentelemetry-bootstrap -a install (Automatic Instrumentation | OpenTelemetry) to the custom app’s pyproject.toml so they get installed when you install app.
Add app.py with following content at the level of hooks.py of custom app:
from frappe.app import application
from opentelemetry.instrumentation.wsgi import OpenTelemetryMiddleware
application = OpenTelemetryMiddleware(application)
Use following command to start gunicorn instead of regular gunicorn command.
/home/frappe/frappe-bench/env/bin/opentelemetry-instrument \
/home/frappe/frappe-bench/env/bin/gunicorn \
--chdir=/home/frappe/frappe-bench/sites \
--bind=0.0.0.0:8000 \
--threads=4 \
--workers=2 \
--log-level=debug \
--worker-class=gthread \
--worker-tmp-dir=/dev/shm \
--timeout=120 \
--preload \
custom_app.app:application
Note: replace custom_app with your app name.
For python rq and opentelemetry follow OpenTelemetry tracing · Issue #1999 · rq/rq · GitHub
If you can use sentry then just set FRAPPE_SENTRY_DSN, ENABLE_SENTRY_DB_MONITORING, SENTRY_TRACING_SAMPLE_RATE environment variables and start using sentry.