Skip to content

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 ​

yaml
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: extract

The 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:

endpointProtocolTransport
collector:4317OTLP/gRPCTLS, or plaintext with insecure: true
collector:4318/v1/tracesOTLP/HTTPTLS, or plaintext with insecure: true
http://collector:4318/v1/tracesOTLP/HTTPPlaintext. The scheme decides and insecure is ignored.
https://collector:4318/v1/tracesOTLP/HTTPTLS. 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:

text
DAG: etl-daily
└── Step: load
    └── DAG: load-warehouse
        ├── Step: copy
        └── Step: analyze

The 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:

yaml
otel:
  enabled: true
  endpoint: otel-collector:4317

steps:
  - id: trigger
    run: |
      curl -fsS -X POST -H "traceparent: $TRACEPARENT" \
        http://report-service:8080/jobs

The 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 TRACEPARENT or TRACESTATE set in the step's own env, or its container's env, wins, and Dagu then sets neither. Set TRACEPARENT to an empty value there to give the process no trace context.
  • A TRACEPARENT from the DAG-level env is 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 ​

FieldDefaultDescription
enabledfalseTurns tracing on for the DAG.
endpointnone, requiredOTLP endpoint. See Endpoints and TLS.
headersnoneHeaders sent with each export, such as Authorization. Values can use ${env.NAME}, which includes secrets.
insecurefalseSend without TLS. Ignored for http:// and https:// URLs.
timeoutexporter defaultExport timeout, such as 30s.
resourceservice.name: daguResource 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.

yaml
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-platform

A DAG can set only some fields. Fields it leaves out come from base.yaml.

Spans and Attributes ​

SpanAttributes
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.

Dagu is open source under the GNU General Public License v3.0.