tracing
Enables integration with OpenTelemetry tracing facilities, using opentelemetry-go
.
When enabled, it will propagate an existing trace context or initialize a new one.
It uses gRPC as an exporter protocol and W3C tracecontext and baggage as propagators.
The trace ID and span ID are added to access logs as the standard traceID
and spanID
fields. Additionally, the {http.vars.trace_id}
and {http.vars.span_id}
placeholders are available; for example, you can use them in a request_header
to pass the IDs to your app.
Syntax
tracing {
[span <span_name>]
}
-
<span_name> is a span name. Please see span naming guidelines.
Placeholders may be used in span names; keep in mind that tracing happens as early as possible, so only request placeholders may be used, and not response placeholders.
Configuration
Environment variables
It can be configured using the environment variables defined by the OpenTelemetry Environment Variable Specification.
For the exporter configuration details, please see spec.
For example:
export OTEL_EXPORTER_OTLP_HEADERS="myAuthHeader=myToken,anotherHeader=value"
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://my-otlp-endpoint:55680
Examples
Here is a Caddyfile example:
example.com {
handle /api* {
tracing {
span api
}
request_header X-Trace-Id {http.vars.trace_id}
reverse_proxy localhost:8081
}
handle {
tracing {
span app
}
reverse_proxy localhost:8080
}
}