OpenTelemetry Tracing
Dagu can export a trace of each DAG run to any OTLP backend, such as Jaeger, Grafana Tempo, Honeycomb, or an OpenTelemetry Collector. Each run becomes one trace with a span for the run and one for each step. Sub-DAG runs, and services that your steps call, join the same trace.
Tracing is set per DAG with the otel field. Put it in base.yaml to trace every DAG.
Enable Tracing
otel:
enabled: true
endpoint: otel-collector:4317 # OTLP over gRPC
resource:
deployment.environment: production
working_dir: . # run the scripts beside this file
steps:
- id: extract
run: ./extract.sh
- id: load
run: ./load.sh
depends: extractThe next run sends a trace with the span DAG: <name> and one Step: <name> span per step. The service name is dagu unless resource sets service.name. The run's log lines carry trace-id and span-id, so you can go from a log to its trace.
To try it on your machine with Jaeger, see Test OpenTelemetry Locally.
Endpoints and TLS
The endpoint decides the protocol:
endpoint | Protocol | Transport |
|---|---|---|
collector:4317 | OTLP/gRPC | TLS, or plaintext with insecure: true |
collector:4318/v1/traces | OTLP/HTTP | TLS, or plaintext with insecure: true |
http://collector:4318/v1/traces | OTLP/HTTP | Plaintext. The scheme decides and insecure is ignored. |
https://collector:4318/v1/traces | OTLP/HTTP | TLS. The scheme decides and insecure is ignored. |
An endpoint is OTLP/HTTP only when it ends with /v1/traces. Any other value is a gRPC host:port.
insecure: true sends spans without TLS. It does not skip certificate checks on a TLS connection.
Sub-DAGs and Services
Sub-DAG Runs
A dag.run step passes the trace to the sub-DAG run, whose DAG: span becomes a child of the calling step's span:
DAG: etl-daily
└── Step: load
└── DAG: load-warehouse
├── Step: copy
└── Step: analyzeThe sub-DAG must enable otel too. Configuring it in base.yaml covers both. The sub-DAG span carries dag.parent_name and dag.parent_run_id.
Step Processes
Each step process receives the W3C trace context of its step span in TRACEPARENT, and in TRACESTATE when the span has a trace state. A program that uses an OpenTelemetry SDK can read them to create child spans, and a script can forward them to the services it calls:
otel:
enabled: true
endpoint: otel-collector:4317
steps:
- id: trigger
run: |
curl -fsS -X POST -H "traceparent: $TRACEPARENT" \
http://report-service:8080/jobsThe service's spans then appear under Step: trigger in the same trace.
- The variables are set only when tracing is on for the DAG. Lifecycle handlers do not receive them.
- A
TRACEPARENTorTRACESTATEset in the step's ownenv, or its container'senv, wins, and Dagu then sets neither. SetTRACEPARENTto an empty value there to give the process no trace context. - A
TRACEPARENTfrom the DAG-levelenvis replaced by the step span's.
Runs Started From Outside
dagu start continues a trace when its own environment has TRACEPARENT, so a CI job or another traced program can make the run part of its trace.
Configuration Reference
| Field | Default | Description |
|---|---|---|
enabled | false | Turns tracing on for the DAG. |
endpoint | none, required | OTLP endpoint. See Endpoints and TLS. |
headers | none | Headers sent with each export, such as Authorization. Values can use ${env.NAME}, which includes secrets. |
insecure | false | Send without TLS. Ignored for http:// and https:// URLs. |
timeout | exporter default | Export timeout, such as 30s. |
resource | service.name: dagu | Resource attributes on every span. |
In resource, ${DAG_NAME} expands to the DAG name and other ${NAME} references read the environment of the Dagu process. ${env.NAME} and ${context.*} references are not expanded there.
otel:
enabled: true
endpoint: https://otlp.example.com/v1/traces
headers:
Authorization: "Bearer ${env.OTEL_TOKEN}"
timeout: 30s
resource:
service.name: "dagu-${DAG_NAME}"
deployment.environment: production
team: data-platformA DAG can set only some fields. Fields it leaves out come from base.yaml.
Spans and Attributes
| Span | Attributes |
|---|---|
DAG: <name> | dag.name, dag.run_id, dag.attempt_id, dag.status; dag.worker_id on a distributed worker; dag.parent_name and dag.parent_run_id for a sub-DAG run |
Step: <name> | step.name, step.status; step.exit_code when it is not 0 |
If the exporter cannot be created, for example because endpoint is empty or its scheme is not http or https, the run logs Failed to initialize OpenTelemetry tracer and continues without tracing.
Related
- Test OpenTelemetry Locally
- Prometheus Metrics
- Runtime Variables:
TRACEPARENTandTRACESTATE

