Prompt
I’m building a production debugging workflow with traces and logs
Latest observation
That’s a great fit for observability-first debugging. A strong production workflow usually makes it easy to go from:
alert → trace/span → logs → root cause → fix verification
Here’s a practical blueprint.
1) Standardize correlation
Make sure every request has shared identifiers across signals:
- trace_id
- span_id
- request_id or correlation_id
- user/session/tenant identifiers where appropriate
In practice
- Propagate trace context via W3C Trace Context (
traceparent,tracestate) - Include
trace_idandspan_idin every structured log line - Attach the same IDs to errors, metrics exemplars, and support tickets
2) Use structured logs, not plain text
Log in JSON or another machine-readable format.
Good log fields
- timestamp
- severity
- service
- environment
- trace_id
- span_id
- request_id
- route/operation
- user_id / tenant_id
- error_type / error_code
- message
- duration_ms
This makes logs joinable with traces and searchable by dimensions.
3) Instrument traces at the right level
Trace the important edges, not everything.
Good spans
- inbound request / RPC
- database calls
- cache calls
- queue publish/consume
- external API calls
- critical business operations
- long-running jobs
Span attributes
Add meaningful attributes like:
http.methodhttp.routedb.systemdb.statementonly if safepeer.serviceretry_countcache.hittenant_id
Avoid high-cardinality or sensitive attributes unless you know the cost and privacy implications.
4) Make logs and traces cross-link
In your observability UI or workflow:
- from a trace, jump to all logs with the same
trace_id - from a log line, jump to the trace that produced it
- from an error span, see surrounding logs and child spans
This is the core productivity boost.
5) Capture errors with enough context
For exceptions and failed operations, log:
- exception type
- stack trace
- operation name
- input shape or IDs
- downstream dependency status
- retry/backoff info
- sampled payload snippets if safe
In traces, mark failed spans clearly and set status/error attributes.
6) Add sampling intelligently
You generally want:
- 100% of errors
- higher sampling for slow requests
- lower baseline sampling for normal traffic
- adaptive sampling during incidents
Useful patterns:
- head-based sampling for cost control
- tail-based sampling for retaining slow/error traces
- “always sample on error” rules
7) Define a debugging runbook
When an incident happens, your workflow should be repeatable:
- Find the error metric spike or alert
- Identify affected service/route/tenant
- Open a representative trace
- Inspect the slow/failing span
- Jump to related logs using
trace_id - Look for dependency failures, retries, or timeouts
- Confirm with dashboards/metrics
- Validate fix with trace and log signals after deployment
8) Guard against common pitfalls
- Logging too much data and increasing cost/noise
- Missing correlation IDs in async/background jobs
- Inconsistent naming across services
- Sensitive data in logs/spans
- High-cardinality labels in metrics
- Sampling away the very traces you need
9) Recommended stack shape
A common production setup:
- OpenTelemetry for instrumentation
- Collector to route/process signals
- Tracing backend: Jaeger, Tempo, Honeycomb, Datadog, New Relic, etc.
- Log backend: Loki, Elasticsearch/OpenSearch, Datadog, Splunk, etc.
- Metrics backend: Prometheus, Mimir, Datadog, etc.
OpenTelemetry is especially useful because it unifies trace/log context propagation.
10) A simple implementation pattern
When handling a request:
- create/continue a trace
- generate or reuse a request ID
- put IDs into logger context
- log key events with structured fields
- propagate context to all downstream calls
- record span errors on failure
Example log
{
"timestamp": "2026-10-28T12:34:56Z",
"level": "error",
"service": "checkout",
"trace_id": "3f2a1c...",
"span_id": "7b9d4e...",
"request_id": "req-123",
"route": "/api/checkout",
"tenant_id": "acme",
"message": "payment authorization failed",
"error_type": "timeout",
"duration_ms": 2480
}
Example trace flow
- HTTP request span
- auth span
- cart lookup span
- payment provider span
- order write span
If payment fails, you can see:
- retry behavior
- latency
- which dependency failed
- matching logs for the exact request
If you want, I can help you design:
- a minimal production architecture for traces/logs,
- an OpenTelemetry implementation plan, or
- a debugging runbook template for your team.