StoicBuilder

HandbookXII the SpeculaDistributed tracing

XIIthe Specula, Watch production

Distributed tracing

1 min readUpdated 28 November

In plain words

Distributed tracing gives each request an ID that travels with it between services and records every step as a timed span, so you can see where a slow request spent its time.

Where you see it

Checkout on Harbor takes four seconds. In Grafana Tempo or Jaeger, the trace for one slow request draws a waterfall: the API takes 40 ms, billing waits 3.6 seconds on the tax provider, and the database takes 30 ms. The longest bar is your answer.

services/billing/checkout.tsserver
import { trace } from "@opentelemetry/api";const tracer = trace.getTracer("billing"); const quote = await tracer.startActiveSpan("tax.quote", async (span) => { span.setAttribute("plan", plan); try { return await taxClient.quote(order); } finally { span.end(); }});
Automatic instrumentation covers HTTP and database calls. Add your own spans around the steps you care about.

What goes wrong

  1. Dropping the context between services

    If one hop doesn't forward the traceparent header, the trace splits in two and the slow part seems to come from nowhere. Use OpenTelemetry's instrumentation for your HTTP client so the context travels with each call.

  2. Sampling away the interesting requests

    Keeping 1 percent of traces at random means you rarely keep the slow or failing ones. Tail-based sampling in the OpenTelemetry Collector decides after a trace finishes, so it can keep every error and every slow request.

  3. Losing the trail across a queue

    A job picked up by a worker starts a fresh trace unless the producer puts the trace context into the message. Pass it along, so the worker's spans link back to the request that queued them.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Set up OpenTelemetry in each service with automatic instrumentation for HTTP, the database and the queue, exporting to our collector. Make sure the traceparent header and queue messages carry the context, and add the trace ID to every log line so I can jump from a log line to its trace.

Quick check

Sign in to earn +10 XP for it

A trace for a slow Harbor checkout shows the API span at 4.1 seconds, with a 3.8-second stretch where no child span appears. What's the most likely explanation?

Got a prompt that touches distributed tracing?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.