Back to Pyroscope

Django Example

examples/language-sdk-instrumentation/python/rideshare/django/README.md

2.2.01.2 KB
Original Source

Django Example

This example runs Django with Gunicorn and preloads the application before Gunicorn forks its workers. The Pyroscope Python client starts background threads and must not be initialized in the Gunicorn master process before those forks.

The post_fork hook calls pyroscope.configure() separately in each worker. Don't move that call into Django settings or another application module: Gunicorn imports those modules in the master process when preload_app is enabled. For more information, refer to the Python client documentation.

To run the example run the following commands:

# Pull latest pyroscope and grafana images:
docker pull grafana/pyroscope:latest
docker pull grafana/grafana:latest

# Run the example project:
docker compose up --build

# Reset the database (if needed):
docker compose down

Navigate to Grafana to explore profiles.