Open your gunicorn.config.py file and add the following code. This will initialize the OpenTelemetry SDK and set up the necessary
instrumentation.
Notice the HttpHeaderSampler class. This is a custom, head-based sampler that will only sample spans that are generated
by Checkly by inspecting the trace state. This way you only pay for the egress traffic generated by Checkly and not for
any other traffic.
Note the code in the post_fork function. This will instrument your Django app with OpenTelemetry.
When using uWSGI, you can use the post_fork hook to instrument your Django app with OpenTelemetry.
Note you will need to install the uwsgidecorators package.
And then add the following code to your wsgi.py file.
Toggle on Import Traces and grab your OTel API key in the OTel API keys section of the Traces page in the Checkly app and
take a note of the endpoint for the region you want to use.
Now, export your API key in your shell by setting the OTEL_EXPORTER_OTLP_HEADERS environment variable.
Next, export the endpoint for the region you want to use and give your service a name.
Then, explicitly set the protocol to use for the OTLP exporter.
We are using the standard OpenTelemetry environment variables here to configure the OTLP exporter.
Variable
Description
OTEL_EXPORTER_OTLP_HEADERS
The Authorization HTTP header containing your Checkly OTel API key.
OTEL_EXPORTER_OTLP_ENDPOINT
The Checkly OTel API endpoint for the region you want to use.
OTEL_EXPORTER_OTLP_PROTOCOL
The protocol to use for the OTLP exporter.
OTEL_SERVICE_NAME
The name of your service to identify it among the spans in the web UI.
Finally, start your app using the relevant command:
For Gunicorn, your startup command will look similar to
For uWSGI, your startup command will look similar to
🎉 You are done. Any interactions with your app that are triggered by a Checkly synthetic monitoring check will now generate
traces, which are sent back to Checkly and displayed in the Checkly UI.