Prompt
I'm building a troubleshooting workflow and want request-level log search during incidents
Latest observation
A good way to support request-level log search during incidents is to make every request traceable end-to-end and then expose a fast, simple search path for on-call use.
Core idea
Add a correlation ID to every incoming request and propagate it through all services, logs, and traces. During an incident, operators can search logs by that ID to reconstruct exactly what happened for a single request.
What to implement
1. Generate or accept a request ID
- If the client sends one, preserve it.
- Otherwise generate one at the edge (API gateway / ingress / load balancer / first app hop).
- Return it in the response header so users can share it with support.
Example:
X-Request-ID: 7f3c2d1a...
2. Include it in every log line
Make sure structured logs always contain:
request_idtrace_idif you use distributed tracingserviceendpointstatus_codelatency_msuser_idortenant_idif appropriate
Prefer JSON logs over plaintext for fast filtering.
3. Propagate it across services
Pass the ID through:
- HTTP headers
- message queues
- background jobs
- async tasks
If a request spawns downstream work, carry the same correlation ID or a parent/child span relationship.
4. Index logs for fast incident search
Your log backend should support:
- exact-match search on
request_id - time-range narrowing
- filtering by service/environment
- optional wildcard/partial search for prefixes
Common options:
- Elasticsearch / OpenSearch
- Grafana Loki
- Splunk
- Datadog Logs
- Cloud-native logs with query support
5. Build an on-call-friendly workflow
Create a runbook or UI shortcut that lets responders search by:
- request ID
- user ID
- order ID / job ID
- trace ID
- error timestamp + endpoint
A good incident page should show:
- the request timeline
- all logs for that request
- related traces/spans
- recent deploys / config changes
- error counts around the same time
Recommended incident workflow
- User reports an issue or alert fires.
- Support or on-call gets the
request_idor a timestamp + endpoint. - Search logs by
request_id. - Inspect:
- ingress log
- application logs
- downstream service logs
- trace if available
- Identify failing dependency, exception, timeout, or bad input.
- Correlate with deploys/feature flags/config changes.
- Fix and verify by replaying or comparing a successful request.
Best practices
- Use structured logging only.
- Keep IDs stable across retries for the same logical request, if that makes sense.
- Mask sensitive data; never log secrets, tokens, or full PII.
- Sample traces, not correlation IDs — request IDs should be present for all requests.
- Standardize header names across all services.
- Add dashboards and saved searches for common incident patterns.
Example log entry
{
"timestamp": "2026-10-28T12:34:56.789Z",
"level": "error",
"service": "checkout-api",
"request_id": "7f3c2d1a9b8e4c1f",
"trace_id": "3c7a1f...",
"endpoint": "/purchase",
"method": "POST",
"status_code": 500,
"message": "Payment provider timeout",
"latency_ms": 1284
}
Example search
request_id:"7f3c2d1a9b8e4c1f"
If you want, I can also help you design:
- a production-ready logging schema
- a search UI/query workflow
- or a reference implementation for a specific stack like Python, Node.js, Go, or Java.