Django
Send traces to Last9 from a Django app using OpenTelemetry
Introduction
Django is a high-level Python web framework that simplifies the development of secure and maintainable web applications. This comprehensive guide will help you instrument your Django application with OpenTelemetry and smoothly send the traces to a Last9 cluster. You can also check out the example application on GitHub↗.
Pre-requisites
- You have a Django application
- You have signed up for Last9, created a cluster, and obtained the following OTLP credentials from the Integrations page:
endpoint
auth_header
Install OpenTelemetry packages
To install the required packages, run the following command:
pip install python-dotenv opentelemetry-distro opentelemetry-exporter-otlp
After, installing the required packages, run the following command to install the required instrumentation packages:
opentelemetry-bootstrap -a install
To know more about them, you can check: https://opentelemetry.io/docs/languages/python/libraries/
Set the environment variables
Now, that you've installed all the packages. Run the following command to initialize environment variables:
export OTEL_SERVICE_NAME=django-app
export OTEL_EXPORTER_OTLP_ENDPOINT=<ENDPOINT>
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=<BASIC_AUTH_HEADER>"
export OTEL_TRACES_EXPORTER=otlp
export OTEL_METRICS_EXPORTER=otlp
Note: Replace
<BASIC_AUTH_HEADER>
with the URL encoded value of the basic auth header.
Run the application
After setting the environment variables, run the Django application:
opentelemetry-instrument uwsgi --http 8000 --ini uwsgi.ini
Visualize data
After running the Django app, you can visualize the traces in the Last9's APM dashboard: Link
Troubleshooting
Please get in touch with us on Discord or Email if you have any questions.