RousselTMLEARNING

Proxy & networking

Traefik: distributed tracing with OpenTelemetry

Enable Traefik v3 tracing with OpenTelemetry (OTLP), propagate the W3C context to applications, sample, and analyze Traefik's spans in Jaeger or Grafana Tempo.

1. Why trace the proxy #

The first link of the request.

Principle #

Traefik sees every request first. By creating the root span and passing the traceparent header (W3C Trace Context), it makes it possible to follow a request from the entry point to the database and to distinguish time spent in the proxy from time spent in the applications.

Traefik and distributed tracing
Applications must also be instrumented and read the context they receive.

2. Configuration (Traefik v3) #

Native OpenTelemetry.

Static configuration #

tracing:
  serviceName: traefik
  sampleRate: 0.2                 # 20 % des requêtes
  addInternals: false             # ne pas tracer le tableau de bord ni /ping
  otlp:
    grpc:
      endpoint: otel-collector:4317
      insecure: true
Change in v3: Traefik v3 no longer exports directly to Jaeger, Zipkin or Datadog: it emits OTLP, and the OpenTelemetry Collector routes to the backend of your choice.

Checking #

curl -s -H 'traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01' https://app.exemple.fr/ -o /dev/null
# puis rechercher la trace 4bf92f3577b34da6a3ce929d0e0e4736 dans Jaeger ou Tempo

3. Reading and using traces #

What Traefik spans show.

Analysis #

  • The Traefik span contains the router, the service, the status and the backend address.
  • A large gap between the duration of the Traefik span and that of the application span reveals waiting on the proxy or network side (connections, TLS, queue).
  • The TraceId also appears in access logs: you can go from the log to the trace.
Good practice: Head-sample in Traefik at a reasonable rate and keep 100% of errors with the Collector's tail sampling.

Related articles

Traefik: securing and transforming requests with middlewares (BasicAuth, ForwardAuth…)

Traefik middlewares modify requests and responses between the router and the service: BasicAuth and ForwardAu…

Traefik: providers (Docker, Kubernetes, Nomad, Consul, files, key-value stores)

Providers feed Traefik's dynamic configuration: service discovery for Docker, Swarm, Kubernetes, Nomad and Co…

Traefik as an Ingress Controller for Kubernetes (Helm, IngressRoute, Gateway API)

Install Traefik in Kubernetes with Helm and publish applications with Ingress, the IngressRoute and Middlewar…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!