How do I pair alerts from Prometheus with Grafana Loki logs for an AI SRE?
In Tares, you pair Prometheus alerts with Grafana Loki logs by giving both sources the same service label, so one timeline holds the alert and its logs. Add a prometheus_alerts source and a loki source, and label each by service. A trigger wakes your agent when an alert fires, and the agent reads the alert and the log lines together from one per-service timeline.
How it works
Tares correlates by label. Sources that carry the same service label merge into one timeline per service, with every event on one clock. You use two sources:
- prometheus_alerts polls Prometheus’s own alerts, every 30 seconds by default. Each active alert becomes one event with
event_typeset to the alert name,textset to its summary, its labels as Tares labels, and a syntheticstateoffiring,pendingorresolved. An alert fires once, re-emits only on a state change, and emits aresolvedevent when it clears. - loki reads log lines from a Loki instance, including Grafana Cloud. You select them with a LogQL query, and Tares polls every 5 seconds by default.
Prometheus keeps owning alerting. Tares ingests what fired, correlates it with the logs, and handles the waking. Nothing is re-thresholded. For the full pattern, see the Build an AI SRE guide.
Set it up
-
Install Tares and start it.
uv tool install tares # or: brew install glassflow/tap/tares tares up -
Add the alerts source. In the console, go to Sources, Add source, Prometheus alerts, enter the
urlplus any auth, and click Discover. It lists your alerting rules and the severities present. The equivalent source looks like this:- name: alerts connector: prometheus_alerts poll: 30s config: url: http://localhost:9090 severities: critical,warning # blank = all labels: - { name: severity, field: labels.severity, primary: true } - { name: state, field: state } -
Add the
servicelabel to the alerts source. Discover only proposes the labels every alert is guaranteed to carry,severityandstate. An alert’s own labels, such asserviceornamespace, exist only while the alert is firing. Once real alerts have been ingested, open the source’s Fields tab and promoteserviceto a label. Make it the primary label. Check Recent events to confirm alerts are arriving. The Prometheus alerts page covers each field. -
Add the Loki source under Sources, Add source. Set the
url, write aqueryin LogQL that selects the service’s logs, and addbearer_token, orusernameandpassword, ortenant_idif your Loki needs them. Give it aservicelabel, marked primary, with the same values your alerts use, soapi-serverin Loki matchesapi-serverin the alert. -
Create a trigger over both sources, keyed by
service, that fires when an alert event arrives. The AI SRE guide usessum(alert_active) > 0over 1m, per service. -
Pick who gets woken: a Tares agent, your own agent service over a webhook, or a Slack channel.
-
Open Explore, pick a service, and confirm the alert and the log lines appear together. To investigate interactively, run
tares mcpand ask your connected client what happened to that service. It reads the correlated timeline for the service.
What you get
- One timeline per service, with the firing alert and the Loki log lines merged on one clock.
- A single read that gives your agent the alert, its state and the surrounding logs, so the investigation starts from evidence instead of from queries against each system.
- Alerts that fire once per state change, plus a
resolvedevent when they clear, so the timeline is not flooded with repeats. - A trigger that wakes your agent when an alert lands, so nobody has to page it.
- Findings that your agent writes back onto the same service timeline, so the next investigation starts from the previous conclusion.
- The same data available to an MCP client for interactive questions.
When something else fits
- If you route alerts through Alertmanager and want it to push them to Tares, use the alertmanager connector instead of prometheus_alerts. The service label works the same way.
- If your logs come from a container on the same host, the docker_logs connector tails them directly. If you already run OpenTelemetry, OTLP carries logs, traces and metrics. You still key them by
service, and the Build an AI SRE guide shows the options side by side. - If you also need metrics on the timeline, add the prometheus connector with the same
servicelabel.