Kest

Search

Search the documentation

Observability

Distributed tracing

Follow one request across many services.

When one user action touches several services (the website calls orders, which calls payments and inventory), a log line in each service does not tell you which belong together. Distributed tracing gives the whole action one trace id and passes it from service to service, so you can see the complete path and where the time went.

Loading diagram…

The id travels in an HTTP header, traceparent, defined by the W3C Trace Context standard (so a Kest service can join a trace started by a Java, Node or Go service, and the other way round).

Turn it on in each service

Kest.run<AppModule> { import(OpenTelemetryModule.forRoot { serviceName = "orders"; otlpEndpoint = "http://tempo:4317" }) }
app.http(adapter) { useTracing(tracing) }                                           // a server span per request, continues the caller's trace
HttpClientModule.register { interceptor(TracingClientInterceptor(tracing)) }        // client spans + the header on outgoing calls

The first line gives each service its own name in the trace viewer; the middleware reads traceparent on the way in; the client interceptor writes it on the way out. A request without the header starts a new trace.

Reading a trace

In Grafana, Jaeger or any viewer a trace is a waterfall: each bar is a span, nested under its parent, its length is its duration. Look for the longest bar with no children (that is where time is spent), for red spans (errors), and for gaps (time spent waiting in a queue or on the network between services).

What is and is not propagated

BoundaryPropagated?
HTTP in (server span)yes
HTTP out with the traced clientyes
Queue jobs, message brokers, WebSockets, scheduled jobsnot yet: a job starts a new trace. Pass the trace id in the message yourself (tracing.currentTraceId()) and log it, to link them by hand

Sampling

Tracing every request is expensive at scale. sampleRatio = 0.1 keeps 10% of new traces. The decision is made at the first service and passed along, so a trace is kept complete or dropped completely. To always keep errors you need tail sampling, which is done in an OpenTelemetry Collector, not in the application.

Troubleshooting

  • Two services, two separate traces: the caller did not use the traced client (no traceparent sent), or a proxy removed the header.
  • No traces at all: check otlpEndpoint (gRPC port 4317, not 4318), and that the application flushed (spans are exported in batches every few seconds).

Read more