Incident Detection Patterns

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.

Detecting Incidents from Metrics

Threshold-Based Alerts on Single Time Series

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:

When to use:

Anomaly Detection Using Historical Baselines

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:

When to use:

Detecting Incidents from Logs

Pattern-Based Event Detection

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:

When to use:

Log-Based Correlation with Metric Context

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:

When to use:

Detecting Incidents from Traces

End-to-End Latency Thresholds

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:

When to use:

Correlation of Multiple Traces

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:

When to use:

Detecting Incidents from Multiple Sources

Composite Alerting Across Metrics, Logs, and Traces

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:

When to use:

Incident Detection with Stateful Correlation

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:

When to use:

Summary: Selecting the Right Pattern

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.