Adding tracing to a service takes an afternoon with OpenTelemetry auto-instrumentation. Getting traces that are complete, readable and useful in an incident takes a few deliberate practices across all services.
1. Consistent resource attributes
Every service sets service.name, service.version and deployment.environment.name, using names agreed across teams. Inconsistent names split one service into several in every view. See OpenTelemetry semantic conventions.
2. Propagation everywhere
A trace is only complete if context travels across every hop: HTTP, gRPC, message queues, background jobs and proxies. Standardise on W3C Trace Context, make sure proxies forward the traceparent header, and inject and extract context in message headers for queues. Broken propagation is the most common reason traces stop halfway. See context propagation.
3. Low-cardinality span names
Name spans by what they do, not with IDs: GET /orders/:id, SELECT orders, render invoice. IDs belong in attributes, or nowhere. See what is a span.
4. Attributes that answer questions
Add the attributes you will want to filter by during an incident: customer tier, region, feature flag variant, job type. Avoid unbounded values in fields you aggregate on, and never add secrets or personal data.
span.setAttributes({ 'app.plan': account.plan, 'app.region': region, 'feature.new_checkout': flags.newCheckout });
5. Record errors properly
Set span status to ERROR for failures, record exceptions as events, and do not mark expected outcomes (a 404 for a missing optional resource) as errors, or error rates become meaningless.
6. Instrument what auto-instrumentation misses
Automatic instrumentation covers frameworks and clients. Add manual spans for important business steps (pricing, tax, rendering), for work done in thread pools or async callbacks, and for calls through custom clients.
7. Put trace IDs in logs
Logs with the trace ID connect a request's story with its details, and let tools show logs inside the trace. Most logging libraries can add it automatically. See structured logging best practices and how to add trace IDs to logs.
8. Sample deliberately
Keep 100% while volume allows; then use parent-based head sampling, and consider tail sampling to keep every error and slow trace. Always sample consistently across services so traces are not half kept. See trace sampling.
9. Keep secrets out
Strip authorization headers, tokens, passwords and query-string values, sanitize SQL, and redact centrally in a Collector as a second line of defence.
10. Use traces during incidents
Tracing pays off when on-call engineers use it. Link alerts to the endpoint's slowest and failing traces, teach the team to read waterfalls, and add a trace link to every runbook step that involves "find the slow request".
Worked example
A team's traces always ended at the API gateway: backend services appeared as separate traces. The gateway's custom HTTP client did not propagate context. After instrumenting it, traces showed the full path, and the next latency incident was diagnosed in minutes: a cache service in one zone timing out, visible as long client spans from every caller. Before, three teams had spent an hour each concluding "our service looks fine".
Checklist
- Agreed service names, versions and environments.
- W3C propagation across HTTP, gRPC, queues and proxies.
- Low-cardinality span names; IDs in attributes only.
- Useful attributes for slicing; no secrets.
- Correct error status and exceptions.
- Manual spans for key business steps.
- Trace IDs in logs.
- Consistent sampling.
- Traces linked from alerts and runbooks.
VitalRix APM builds endpoints, a database view and a service map from your traces, and shows logs that carry the trace ID inside each trace. See distributed tracing and microservices monitoring.
Common mistakes
- Tracing only the edge service, so traces show a single long span with no explanation.
- Different sampling decisions per service, leaving half-recorded traces.
- Span per loop iteration, producing thousands of spans for one request.
- Putting request bodies in attributes, which leaks data and costs money.
- Never looking at traces outside incidents: review a few slow traces each week to find problems early.
Why are my traces broken into pieces?
Context is not propagated somewhere: an uninstrumented client, a proxy dropping headers, or a queue without context injection.
How many spans should a trace have?
Enough to explain where time goes: the server span, outgoing calls, database queries and key business steps. Hundreds of tiny spans add cost without insight.
Should I trace every request?
At low to moderate traffic, yes. At high traffic, sample consistently and keep errors and slow traces with tail sampling.
Try VitalRix free
Uptime monitoring, APM, logs, real user monitoring and status pages in one place. No credit card needed.