Comprehensive guide to incident detection patterns for production observability and monitoring systems.
Incident detection is the process of identifying when a system has deviated from expected behavior—whether a service is down, a metric is trending, or a log pattern signals a recurring failure. It matters when observability data is available but not yet actionable: when engineers must distinguish true incidents from noise, and when delays in detection lead to longer outages. This page details the patterns engineers use to detect incidents effectively, focusing on the practical choices, pitfalls, and workflows that shape detection quality.
A metric threshold alert triggers when a single time-series value crosses a fixed boundary. The most common variant uses a sliding window to compute a statistic, such as average or median, and compares it to a threshold.
alert:
name: "CPU usage too high"
query: "avg(cpu_usage) by (service, instance)"
window: "5m"
threshold: {
type: "absolute",
value: 85.0
}
duration: "10m"
evaluation: "every 1m"
The window defines the aggregation period, threshold.value sets the baseline, and duration ensures the condition persists before triggering. evaluation controls how often the alert checks for a new state.
Key failure modes:
absolute threshold without accounting for baseline drift: a service that spikes from 50% to 85% CPU during peak hours fails to alert, despite being overloaded.duration with window: a 5-minute window with 10-minute duration means the alert checks every minute over the past five minutes, but requires ten consecutive minutes of high CPU.evaluation to match the alert’s purpose: a 10-minute duration alert evaluated every 5 minutes may miss a spike that lasts 8 minutes.When to use:
Instead of fixed thresholds, anomaly detection compares the current value to a learned historical pattern.
alert:
name: "Unusual traffic in user-service"
query: "avg(requests_per_minute) by (service)"
window: "1h"
anomaly:
method: "z-score",
history: "7d",
z_threshold: 2.5,
min_samples: 10
The history window defines the period from which to compute the baseline. The z-score method calculates the mean and standard deviation of the metric over that history, flags values beyond z_threshold standard deviations as anomalies.
Critical subtleties:
min_samples prevents spurious alerts when historical data is sparse. A 7-day history with only 48 data points may produce unreliable statistics.z-score assumes normal distribution; long tails or seasonality (e.g., daily traffic cycles) can cause false positives.method: "seasonal_decompose" is more robust: it separates trend, seasonality, and residual, then applies anomaly detection on the residual.When to use:
A log-based incident is triggered when a specific log pattern appears in a stream or collection.
event:
name: "Failed login with multiple retries"
pattern: "Failed login for user \\w+ after [0-9]+ attempts"
stream: "auth-service.log"
frequency: "5m"
min_matches: 3
window: "1h"
condition: "all"
The pattern is a regular expression applied to log lines. frequency controls how often to scan for matches. min_matches and window define when a pattern constitutes a distinct incident.
Common pitfalls:
condition: "any" when all is intended: a login failure event with three matching logs in one minute is detected, but only one of the three is needed.Failed login.* matches all login-related logs but fails to distinguish common failures from critical ones.When to use:
When a log pattern is detected, enrich it with metric context to distinguish transient issues from systemic ones.
alert:
name: "High error rate in payment-service"
query: "avg(errors_per_minute) by (service)"
threshold: {
type: "percentile",
p: 95,
value: 10.0
}
correlation: {
log: "payment-service.log",
pattern: "Transaction failed: [^\\n]+",
join: {
metric: "service=payment-service",
time: "5m"
},
enrich: [
"user_id",
"payment_method",
"error_code"
]
}
The join field aligns log events with metric data by time window and service. enrich adds fields from the log line into the alert metadata.
Failure modes:
time window: a 5-minute time window may miss a log event that occurs at 14:02:30 but the metric window spans 14:00–14:05.metric and log service names exactly: payment-service vs payment-service with capitalization mismatch.enrich fields being missed because the log line does not contain the expected key.When to use:
An end-to-end trace incident occurs when a request spans multiple services and exceeds a latency threshold.
trace:
name: "Slow checkout flow"
service: "checkout-service"
operation: "process-order"
threshold: {
type: "percentile",
p: 99,
value: 2000
}
window: "10m"
duration: "5m"
min_spans: 10
The threshold is evaluated over spans in the service with operation. window defines the time range for span collection. duration ensures the threshold is sustained. min_spans ensures the incident is not based on a few isolated traces.
Critical nuances:
p: 99 is not the same as p: 99.0; precision matters when comparing values.window and duration can be configured independently: a 10-minute window with 5-minute duration means a trace is included if its start time is within the last 10 minutes, and it must have a 99th percentile latency of 2 seconds over the past 5 minutes.min_spans prevents alerting on a single trace that is slow but not representative.When to use:
An incident is detected when multiple related traces show similar patterns—e.g., high latency in one service coinciding with high error rate in another.
correlation:
name: "Checkout flow failure with database timeout"
queries: [
{
service: "checkout-service",
operation: "process-order",
metric: "latency",
threshold: { type: "p99", value: 2000 }
},
{
service: "user-service",
operation: "get-user-profile",
metric: "error_rate",
threshold: { type: "absolute", value: 5.0 }
}
],
join: {
time: "2m",
service: "checkout-service"
},
condition: "all",
duration: "15m"
queries define individual trace-based alerts. join aligns the traces across services by time window and service identity. condition determines whether all or any queries must be true.
Common missteps:
join.time with duration but not aligning the start times: traces may be joined but the condition is evaluated at different intervals.condition: "any" when all is expected: a 10-minute window with 99th percentile latency in checkout is sufficient, even if the user service is performing well.duration long enough: a 5-minute duration alert may miss a 12-minute trace that started early and ended late.When to use:
When a single source is insufficient, engineers combine alerts from multiple domains.
composite:
name: "User sign-up flow degradation"
sources: [
{
type: "metric",
query: "avg(signup_latency) by (region)",
threshold: { type: "p95", value: 3000 },
duration: "10m"
},
{
type: "log",
stream: "signup-service.log",
pattern: "Signup failed: [^\\n]+",
frequency: "2m",
min_matches: 5,
window: "15m"
},
{
type: "trace",
service: "signup-service",
operation: "create-user",
metric: "error_rate",
threshold: { type: "absolute", value: 3.0 }
}
],
condition: "all",
timeout: "30m"
Each source contributes a sub-alert. condition defines how the composite alert is triggered: all requires every source to be active, any triggers on any one. timeout ensures the incident remains open for at least that duration.
Sharp edges:
timeout is not the same as duration: duration applies to each source, while timeout applies to the entire composite alert.frequency in log sources can conflict with window: a 2-minute frequency scan may overlap with a 15-minute window, leading to redundant detections.condition: "all" with timeout: "30m" means the alert is open for 30 minutes after all sources have been satisfied.When to use:
An incident is not just a signal—it is a state that evolves.
incident:
name: "Database cluster outage"
detection: {
metric: "cluster_status",
log: "db-cluster.log",
trace: "db-query-latency"
},
state: {
initial: "detected",
transitions: [
{
from: "detected",
to: "confirmed",
condition: "all",
duration: "5m"
},
{
from: "confirmed",
to: "escalated",
condition: "any",
threshold: { metric: "latency", p: 99, value: 5000 }
}
],
actions: [
{
event: "confirmed",
run: "send-slack-alert",
payload: {
channel: "#incident-db",
text: "Database cluster confirmed outage"
}
},
{
event: "escalated",
run: "create-jira-ticket",
payload: {
project: "infra",
summary: "Escalated DB outage",
description: "Latency >5s for 99th percentile"
}
}
]
}
The state machine tracks the incident’s life. Each transition defines a condition and a duration. actions are triggered on state changes.
Failure modes:
duration not being enforced: an incident reaches confirmed but the state is not held for 5 minutes.condition: "any" in transitions when all is needed: a single metric or log event is enough to escalate, even if others are still stable.actions not being idempotent: a Slack alert is sent multiple times when the incident transitions multiple times.When to use:
Use threshold-based alerts for simple, stable metrics. Use anomaly detection when baselines vary. Use log pattern matching when error details are embedded in text. Use trace-based detection when end-to-end performance is critical. Combine all three for composite, evolving incidents. Always define window, duration, and evaluation precisely. Never assume a system’s default behavior. The best incident detection patterns are not just defined—they are tuned, validated, and maintained.
This page was rewritten on 17 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy