Prompt
How do I search application logs by request ID across multiple microservices?
Latest observation
Nov 11, 2026
OpenAI APIWeb search: off
To search application logs by request ID across multiple microservices, you generally want a setup where every service logs the same correlation/request ID and your logging platform indexes it as a field.
1) Make sure the request ID is propagated
- Generate a request ID / correlation ID at the edge if one isn’t already present.
- Pass it through all downstream calls via a header, commonly:
X-Request-IDX-Correlation-ID
- Each microservice should:
- read the incoming ID from the request headers,
- include it in all log entries,
- forward it on outgoing HTTP/gRPC/message calls.
2) Log the request ID as a structured field
Prefer structured logs (JSON) instead of plain text. Example:
{
"timestamp": "2026-11-11T12:34:56Z",
"service": "payment-service",
"level": "INFO",
"request_id": "abc123",
"message": "Charge completed"
}
This makes searching much easier and more reliable.
3) Search in your centralized log system
If you use tools like:
Elasticsearch / Kibana
request_id:"abc123"
or
{"query":{"match":{"request_id":"abc123"}}}
Splunk
request_id="abc123"
Grafana Loki
{request_id="abc123"}
Datadog Logs
@request_id:abc123
Google Cloud Logging
jsonPayload.request_id="abc123"
AWS CloudWatch Logs Insights
fields @timestamp, @message
| filter request_id = "abc123"
| sort @timestamp asc
4) Include service name to see the full trace
When searching, filter by request ID and sort by time:
- request ID:
abc123 - service:
auth-service,order-service,payment-service
This lets you reconstruct the request path across services.
5) Best practice: use distributed tracing too
Request IDs are useful, but distributed tracing is even better for multi-service systems.
Use:
- OpenTelemetry
- W3C Trace Context headers (
traceparent,tracestate)
Then logs can include:
trace_idspan_idrequest_id(optional)
This gives you:
- end-to-end request flow,
- latency breakdown per service,
- easier correlation between logs, metrics, and traces.
6) Example workflow
- User makes a request to API Gateway.
- Gateway assigns
X-Request-ID: abc123. - All services log
request_id=abc123. - In Kibana/Splunk/Loki, search for
abc123. - Inspect logs from each microservice to follow the request path.
7) If logs are plain text today
You can still search by request ID if it appears consistently in the message, e.g.:
[request_id=abc123] Payment approved
But structured logs are strongly recommended.
8) Operational tips
- Ensure every service logs the ID in the same field name.
- Add the ID automatically via middleware/interceptors.
- Ensure async jobs/queues also carry the ID if the request spans background processing.
- Avoid regenerating the ID in downstream services.
If you want, I can show:
- how to implement this in a specific stack like Java/Spring, Node.js, Python/FastAPI, or .NET, or
- how to query it in Splunk, Kibana, Loki, Datadog, or CloudWatch.