How do I label Docker container logs so an AI SRE can narrow 5xx errors on an API to one service?
Tares lets you label Docker container logs by declaring a service label on the docker_logs source and marking it primary: true. The log lines then share a key with that service’s metrics and alerts. A read on that service returns the 5xx rate, the error log lines and the fired alerts together on one timeline, so an AI SRE looks at one service instead of every container.
How it works
The docker_logs connector tails a running container’s logs, one event per line. It needs access to the Docker daemon, so run taresd on the host, or mount the Docker socket and include the Docker CLI in the image.
A label gives each event a key. You declare it under labels with a name and primary: true. In the docker_logs example the value comes from a constant, const: api-server. Every line the source tails carries service set to api-server.
The correlation comes from using the same label name on every source for that service:
- Your metrics source reads
servicefrom the metric labels. In the Prometheus connector that is a label withfield: metric.service. - Your alerts source carries the same
servicekey. - Your Docker logs source sets
serviceto a constant that matches.
Tares merges everything that carries service into one timeline per service, with metrics, logs and alerts on one clock. A read for api-server returns the 5xx rate, the error lines from the API container and any alert such as HighErrorRate. Nothing from other services mixes in. The AI SRE guide builds this whole setup end to end.
If you need a per-line value, the label_pattern option takes a regex with named groups and turns each line into per-line label context.
Set it up
-
Install Tares and start it:
tares up -
Find the container name with
docker ps. If the container runs under Compose without a fixedcontainer_name, use the service name and also setcompose_fileto an absolute path, or a path relative to where the daemon runs, so the tail follows restarts. -
Add the source under Sources → Add source → docker_logs, or ask a connected agent to find your containers and ingest the api-server’s logs. Declare the label with a constant and mark it primary:
- name: logs connector: docker_logs poll: 5s config: container: tares-demo-api-server # the container name (docker ps) labels: - { name: service, const: api-server, primary: true }You can also send the same object with
POST /api/sources. -
Give your metrics and alerts sources the same
servicelabel, so all three share one key. For metrics, readservicefrom the metric labels. The log constant must equal the value those sources produce, hereapi-server. -
Verify. Open the source in the console and check that Recent events shows lines on the next poll. If nothing arrives, check that
taresdcan rundocker logson that container. Then open Explore, pickapi-server, and confirm that logs, metrics and alerts appear together. -
Connect your agent. Start the MCP endpoint in a second shell:
tares mcpThen ask: what happened to api-server in the last 15 minutes? The agent reads the correlated timeline for that one service.
To cut noise before it is stored, set match to keep only lines that match a regex, or drop to skip lines that match one. Both are optional, and the default keeps all lines.
What you get
- Every log line from the API container is tagged with the service it belongs to.
- One read for
api-serverreturns its 5xx rate, its error lines and its alerts on one clock, so the agent ties a spike to specific log evidence. - Triggers keyed by
servicewake an agent with the same correlated timeline. The agent’s finding is written back onto that service’s timeline, so the next investigation starts from it. - Other services’ logs stay out of the read, because they carry a different
servicevalue. - You can check the result yourself in Explore before any agent uses it.
When something else fits
- If your logs already flow through an OpenTelemetry pipeline, the OTLP connector covers logs per service, and you label it with the
resourceAttributes.service.namepath. - If your containers run on hosts where
taresdcannot reach the Docker daemon, use another source for those logs. See the Docker logs connector for the access it needs.
Related
- Build an AI SRE
- How do I label Docker container logs so an AI SRE can narrow a stopped cron job to one service?
- How do I label OpenTelemetry log records so an AI SRE can narrow error spikes to one service?
- How do I label OpenTelemetry log records so an AI SRE can narrow high latency to one service?
Still stuck? Get help