Distributed Tracing
When one checkout hop crosses gateway → Orders → inventory → pricing, logs alone cannot show where time went.
Introduction
When one checkout hop crosses gateway → Orders → inventory → pricing, logs alone cannot show where time went. Distributed tracing stitches spans with a shared trace id so you see the critical path.
Spring Boot 3 uses Micrometer Tracing with bridges such as OpenTelemetry (micrometer-tracing-bridge-otel) and OTLP export to Tempo, Jaeger, or a vendor backend. Sampling controls cost in production.
Propagate context over HTTP and messaging. Put trace ids in MDC so logs deep-link to traces — completing the observability story started in monitoring.
This lesson makes TechLearningPRO Orders debuggable as a distributed system.
Purpose of this lesson
Enable Micrometer Tracing + OpenTelemetry for Orders and propagate trace context across service calls.
Understanding the topic
Trace = tree of spans across process boundaries.
- Trace id: identifies the whole request journey.
- Span: one unit of work (HTTP server, client, DB).
- Propagation: W3C Trace Context headers on outbound calls.
- Micrometer Tracing: Boot 3 facade over OTel/Brave bridges.
- Sampling: 1.0 in lab; lower in prod to control volume.
Step-by-step explanation
- Add
micrometer-tracing-bridge-oteland an OTLP exporter dependency. - Configure sampling and OTLP endpoint toward Tempo/Jaeger.
- Call inventory from Orders with instrumented WebClient/RestClient.
- Confirm one trace shows gateway → Orders → inventory spans; log lines share the trace id.
Informative example
Boot 3 Micrometer Tracing with OTLP.
// Dependencies (Maven excerpt)// micrometer-tracing-bridge-otel// opentelemetry-exporter-otlp# application.ymlmanagement:tracing:sampling:probability: 1.0 # use ~0.05–0.1 in productionotlp:tracing:endpoint: http://tempo:4318/v1/traceslogging:pattern:level: "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]"# Outbound calls must use instrumented clients so headers propagatebean WebClient.Builder → WebClient.create() // prefer builder from Boot
Real-world use
TechLearningPRO's p99 checkout spike looked like 'Orders is slow'. A single trace showed 80% of time in inventory DNS timeouts after a bad kube service rename. Without tracing, teams blamed Postgres for half a day. With tracing, DNS was fixed in twenty minutes.
Security implications
Traces can leak sensitive data.
- Do not put tokens, passwords, or card data in span attributes.
- Restrict who can query the tracing backend.
- Keep exporter endpoints on private networks.
Best practices
- Always correlate logs via MDC trace ids.
- Trace the gateway and each Boot service with the same propagator standard.
- Alert from metrics; use traces to explain the alert.
Common mistakes
- Sampling 100% in huge prod clusters without a budget — bill shock.
- Manual HTTP clients that drop propagation headers.
- High-cardinality span attributes (raw PII or unbounded ids) leaking into backends.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionWhat question does tracing answer?+
Answer
2IntermediateQuestionWhat does Boot 3 use for tracing?+
Answer
3IntermediateQuestionWhy is sampling important?+
Answer
Hands-on exercise
Lab. Enable OTel bridge on Orders and a fake inventory service. Generate one checkout and open the trace in Jaeger/Tempo. Break propagation deliberately (raw JDK HttpClient) and observe a broken trace — then restore the instrumented client.
Summary
Distributed tracing completes Orders observability across microservices. With limits, metrics, tests, and resilience in place, you can operate a Boot 3 estate with eyes open.