Prompt
How do I set up centralized log management for multiple microservices?
Latest observation
A good centralized log setup for multiple microservices usually has 5 parts:
- Each service writes structured logs
- Logs are collected from all services
- Logs are shipped to a central store
- You can search, filter, and visualize them
- Logs include correlation data so you can trace requests across services
1) Make every service log in a consistent format
Use structured logging, usually JSON, instead of plain text.
Include fields like:
timestamplevelservice_nameenvironmentrequest_id/correlation_idtrace_id/span_idif you use distributed tracingmessageerror_stackuser_idor tenant ID if appropriate
Example JSON log:
{
"timestamp": "2026-10-28T12:00:00Z",
"level": "INFO",
"service": "orders-service",
"environment": "prod",
"request_id": "a1b2c3",
"trace_id": "f9e8d7",
"message": "Order created",
"order_id": "12345"
}
2) Use a log collection agent
Instead of every service sending logs directly to your logging backend, run a collector/agent.
Common options:
- Fluent Bit
- Fluentd
- Filebeat
- Vector
- OpenTelemetry Collector for logs + traces + metrics
Typical flow:
- App logs to stdout or a file
- Agent reads logs from containers/hosts
- Agent enriches and forwards them centrally
3) Choose a central log backend
Popular choices:
- Elasticsearch / OpenSearch + Kibana / OpenSearch Dashboards
- Grafana Loki + Grafana
- Splunk
- Datadog
- Cloud-native:
- AWS: CloudWatch Logs
- GCP: Cloud Logging
- Azure: Azure Monitor / Log Analytics
Common recommendation
- If you want powerful search and analysis: Elasticsearch/OpenSearch
- If you want lower cost and simpler ops: Loki
- If you want managed SaaS: Datadog or Splunk
4) Add correlation across services
For microservices, the key is to trace one request through many services.
Best practice
- Generate a
request_idat the edge (API gateway / ingress) - Pass it via headers to downstream services
- Log it in every service
- If using tracing, also propagate
traceparent/trace_id
This lets you answer:
- “What happened during this user request?”
- “Which service failed?”
- “How long did each step take?”
5) Centralize search and dashboards
Build dashboards and saved searches for:
- Errors by service
- Error rates over time
- Logs by request_id / trace_id
- Top exception types
- Slow requests
- Deployment-related spikes
6) Recommended architecture
A common production setup:
Microservices → stdout/json logs → Fluent Bit / Vector / Filebeat → central backend → dashboard/search
Example:
- Docker/Kubernetes services log to stdout
- Fluent Bit DaemonSet tails container logs
- Fluent Bit sends to:
- Loki, or
- Elasticsearch/OpenSearch, or
- Cloud logging service
7) If you’re using Kubernetes
Kubernetes logging best practice:
- Log to stdout/stderr
- Do not write important logs only inside the container filesystem
- Run a node-level agent or DaemonSet:
- Fluent Bit
- Vector
- Filebeat
Also:
- Tag logs with
namespace,pod,container,node - Add
app,version,env
8) Security and retention
Plan for:
- Access control by team/service
- Encryption in transit and at rest
- Retention policies
- Redaction of secrets/PII
- Audit logs for the logging platform itself
9) Practical implementation steps
- Standardize a logging library across services
- Emit JSON logs to stdout
- Add request/trace ID propagation
- Deploy a log collector
- Send logs to a central platform
- Create dashboards and alerts
- Set retention and redaction rules
10) Good starter stack examples
Option A: Kubernetes + Loki
- App logs to stdout
- Fluent Bit or Promtail ships logs
- Loki stores logs
- Grafana visualizes them
Option B: Kubernetes + OpenSearch
- App logs to stdout
- Fluent Bit ships logs
- OpenSearch stores logs
- Kibana/OpenSearch Dashboards for search
Option C: Managed
- App logs to stdout
- Cloud agent sends to Datadog/Splunk/Cloud Logging
- Use built-in UI and alerting
11) Don’t forget tracing
Logs are best when paired with distributed tracing. Use:
- OpenTelemetry for traces, metrics, and logs correlation
- Propagate
trace_idin logs
That makes debugging much easier than logs alone.
If you want, I can also give you:
- a Kubernetes reference architecture
- a Docker Compose example
- or a step-by-step setup for Loki, OpenSearch, or ELK