Opentelemetry with Frappe framework?

Hello everyone, I’m new here. I’m curious if anyone here uses OpenTelemetry with the Frappe framework. Are there any documents demonstrating how to use it with frappe ? Or is it better to use other tools instead of OpenTelemetry for tracing ?

Hello anyone here in this forum ?

Hi @deawkotic:

Be patient, there are hundred of users using the forum daily …
I think that Posthog and Sentry are being used for this now.

Hope this helps.

@avc Thank you very much for the response, but this doesn’t help me much. I want something like this article for tracing my erpnext.

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.

5 Likes

This is great info. Thank you. Quick question. How can I add env variables in Dockerfile? I’d like to separate staging with production so I want it to be dynamic.

I’m trying to use Infisical. I’ve had success setting it up, but not so much when separating environments. I have to rebuild docker image for production.

Thank you in Advance.

You can pass env variables to container when it starts

1 Like

I already do that with some env and for some reason I did not think of this. Thank you!