This guide explains how to send OpenTelemetry data from a Django app to Axiom using the Python OpenTelemetry SDK.
requirements.txt
file:
manage.py
to initialize tracingDjangoInstrumentor().instrument()
ensures that all incoming HTTP requests are automatically traced, which helps in monitoring the app’s performance and behavior without manually adding trace points in every view.
exporter.py
for tracer configurationTracerProvider
and configuring the OTLPSpanExporter
, you define how and where the trace data is sent. The BatchSpanProcessor
is used to batch and send trace spans efficiently. The tracer created at the end is used throughout the app to create new spans.
AXIOM_DOMAIN
with api.axiom.co
if your organization uses the US region, and with api.eu.axiom.co
if your organization uses the EU region. For more information, see Regions.Replace API_TOKEN
with the Axiom API token you have generated. For added security, store the API token in an environment variable.Replace DATASET_NAME
with the name of the Axiom dataset where you want to send data.exporter.py
. By wrapping the view logic within tracer.start_as_current_span
, you create spans that capture the execution of these views. This provides detailed insights into the performance of individual request handlers, helping to identify slow operations or errors.
settings.py
for OpenTelemetry instrumentationsettings.py
, add the OpenTelemetry Django instrumentation. This setup automatically creates spans for HTTP requests handled by Django:
urls.py
Updating urls.py
with these entries sets up the URL routing for the Django app. It connects the URL paths to the corresponding view functions. This ensures that when users visit the specified paths, the corresponding views are executed, and their spans are created and sent to Axiom for monitoring.
http://127.0.0.1:8000/rolldice
to interact with your Django app. Each time you load the page, the app displays a message and sends the collected traces to Axiom.
AXIOM_DOMAIN
with api.axiom.co
if your organization uses the US region, and with api.eu.axiom.co
if your organization uses the EU region. For more information, see Regions.Replace API_TOKEN
with the Axiom API token you have generated. For added security, store the API token in an environment variable.Replace DATASET_NAME
with the name of the Axiom dataset where you want to send data.AXIOM_DOMAIN
with api.axiom.co
if your organization uses the US region, and with api.eu.axiom.co
if your organization uses the EU region. For more information, see Regions.Replace API_TOKEN
with the Axiom API token you have generated. For added security, store the API token in an environment variable.Replace DATASET_NAME
with the name of the Axiom dataset where you want to send data.manage.py
to include OpenTelemetry initialization, ensuring that tracing is active before the Django app fully starts.Field Category | Field Name | Description |
---|---|---|
General Trace Information | ||
_rowId | Unique identifier for each row in the trace data. | |
_sysTime | System timestamp when the trace data was recorded. | |
_time | Timestamp when the actual event being traced occurred. | |
trace_id | Unique identifier for the entire trace. | |
span_id | Unique identifier for the span within the trace. | |
parent_span_id | Unique identifier for the parent span within the trace. | |
HTTP Attributes | ||
attributes.http.method | HTTP method used for the request. | |
attributes.http.status_code | HTTP status code returned in response. | |
attributes.http.route | Route accessed during the HTTP request. | |
attributes.http.scheme | Protocol scheme (HTTP/HTTPS). | |
attributes.http.url | Full URL accessed during the HTTP request. | |
User Agent | ||
attributes.http.user_agent | User agent string, providing client software and OS. | |
Custom Attributes | ||
attributes.custom[“http.host”] | Host information where the HTTP request was sent. | |
attributes.custom[“http.server_name”] | Server name for the HTTP request. | |
attributes.custom[“net.peer.ip”] | IP address of the peer in the network interaction. | |
Network Attributes | ||
attributes.net.host.port | Port number on the host receiving the request. | |
Operational Details | ||
duration | Time taken for the operation, typically in microseconds or milliseconds. | |
kind | Type of span (For example, server, internal). | |
name | Name of the span, often a high-level title for the operation. | |
Scope and Instrumentation | ||
scope | Instrumentation scope, (For example., opentelemetry.instrumentation.django.) | |
Service Attributes | ||
service.name | Name of the service generating the trace, typically set as the app or service name. | |
Telemetry SDK Attributes | ||
telemetry.sdk.language | Programming language of the SDK used for telemetry, typically ‘python’ for Django. | |
telemetry.sdk.name | Name of the telemetry SDK, for example., OpenTelemetry. | |
telemetry.sdk.version | Version of the telemetry SDK used in the tracing setup. |
exporter.py
file and other relevant parts of the Django OpenTelemetry setup import the following libraries:
exporter.py
manage.py
views.py
exporter.py
, which is used to create spans for tracing the execution of Django views. By wrapping view logic within tracer.start_as_current_span
, it captures detailed insights into the performance of individual request handlers.