Create a Metric Alert Rule for an Organization

Go to Product

Create a new metric alert rule for the given organization.

A metric alert rule is a configuration that defines the conditions for triggering an alert. It specifies the metric type, function, time interval, and threshold values that determine when an alert should be triggered. Metric alert rules are used to monitor and notify you when certain metrics, like error count, latency, or failure rate, cross a predefined threshold. These rules help you proactively identify and address issues in your project.

Metric Alert Rule Types

Below are the types of metric alert rules you can create and the parameter values required to set them up. All other parameters can be customized based on how you want the alert rule to work. Scroll down to Body Parameters for more information. Visit the Alert Types docs for more details on each metric alert rule type.

Number of Errors

  • eventTypes: Any of error or default.
{
    "queryType": 0,
    "dataset": "events",
    "aggregate": "count()",
    "eventTypes": ["error", "default"]
}

Users Experiencing Errors

  • eventTypes: Any of error or default.
{
    "queryType": 0,
    "dataset": "events",
    "aggregate": "count_unique(user)"
}

Crash Free Session Rate

{
    "queryType": 2,
    "dataset": "metrics",
    "aggregate": "percentage(sessions_crashed, sessions) AS _crash_rate_alert_aggregate"
}

Crash Free User Rate

{
    "queryType": 2,
    "dataset": "metrics",
    "aggregate": "percentage(users_crashed, users) AS _crash_rate_alert_aggregate"
}

Throughput

{
    "queryType": 1,
    "dataset": "transactions",
    "aggregate": "count()"
}

Transaction Duration

  • dataset: If a custom percentile is used, dataset is transactions. Otherwise, dataset is generic_metrics.
  • aggregate: Valid values are avg(transaction.duration), p50(transaction.duration), p75(transaction.duration), p95(transaction.duration), p99(transaction.duration), p100(transaction.duration), and percentile(transaction.duration,x), where x is your custom percentile.
{
    "queryType": 1,
    "dataset": "generic_metrics",
    "aggregate": "avg(transaction.duration)"
}

Apdex

  • aggregate: apdex(x) where x is the value of the Apdex score.
{
    "queryType": 1,
    "dataset": "transactions",
    "aggregate": "apdex(300)"
}

Failure Rate

{
    "queryType": 1,
    "dataset": "transactions",
    "aggregate": "failure_rate()"
}

Largest Contentful Paint

  • dataset: If a custom percentile is used, dataset is transactions. Otherwise, dataset is generic_metrics.
  • aggregate: Valid values are avg(measurements.lcp), p50(measurements.lcp), p75(measurements.lcp), p95(measurements.lcp), p99(measurements.lcp), p100(measurements.lcp), and percentile(measurements.lcp,x), where x is your custom percentile.
{
    "queryType": 1,
    "dataset": "generic_metrics",
    "aggregate": "p50(measurements.lcp)"
}

First Input Delay

  • dataset: If a custom percentile is used, dataset is transactions. Otherwise, dataset is generic_metrics.
  • aggregate: Valid values are avg(measurements.fid), p50(measurements.fid), p75(measurements.fid), p95(measurements.fid), p99(measurements.fid), p100(measurements.fid), and percentile(measurements.fid,x), where x is your custom percentile.
{
    "queryType": 1,
    "dataset": "generic_metrics",
    "aggregate": "p100(measurements.fid)"
}

Cumulative Layout Shift

  • dataset: If a custom percentile is used, dataset is transactions. Otherwise, dataset is generic_metrics.
  • aggregate: Valid values are avg(measurements.cls), p50(measurements.cls), p75(measurements.cls), p95(measurements.cls), p99(measurements.cls), p100(measurements.cls), and percentile(measurements.cls,x), where x is your custom percentile.
{
    "queryType": 1,
    "dataset": "transactions",
    "aggregate": "percentile(measurements.cls,0.2)"
}

Custom Metric

  • dataset: If a custom percentile is used, dataset is transactions. Otherwise, dataset is generic_metrics.
  • aggregate: Valid values are:
    • avg(x), where x is transaction.duration, measurements.cls, measurements.fcp, measurements.fid, measurements.fp, measurements.lcp, measurements.ttfb, or measurements.ttfb.requesttime.
    • p50(x), where x is transaction.duration, measurements.cls, measurements.fcp, measurements.fid, measurements.fp, measurements.lcp, measurements.ttfb, or measurements.ttfb.requesttime.
    • p75(x), where x is transaction.duration, measurements.cls, measurements.fcp, measurements.fid, measurements.fp, measurements.lcp, measurements.ttfb, or measurements.ttfb.requesttime.
    • p95(x), where x is transaction.duration, measurements.cls, measurements.fcp, measurements.fid, measurements.fp, measurements.lcp, measurements.ttfb, or measurements.ttfb.requesttime.
    • p99(x), where x is transaction.duration, measurements.cls, measurements.fcp, measurements.fid, measurements.fp, measurements.lcp, measurements.ttfb, or measurements.ttfb.requesttime.
    • p100(x), where x is transaction.duration, measurements.cls, measurements.fcp, measurements.fid, measurements.fp, measurements.lcp, measurements.ttfb, or measurements.ttfb.requesttime.
    • percentile(x,y), where x is transaction.duration, measurements.cls, measurements.fcp, measurements.fid, measurements.fp, measurements.lcp, measurements.ttfb, or measurements.ttfb.requesttime, and y is the custom percentile.
    • failure_rate()
    • apdex(x), where x is the value of the Apdex score.
    • count()
{
    "queryType": 1,
    "dataset": "generic_metrics",
    "aggregate": "p75(measurements.ttfb)"
}

Options

Organization Slug
The slug of the organization the resource belongs to.
Body

Request body which must comply to the following JSON Schema:

{
  "required" : [ "aggregate", "name", "projects", "query", "thresholdType", "timeWindow", "triggers" ],
  "type" : "object",
  "properties" : {
    "name" : {
      "maxLength" : 64,
      "type" : "string",
      "description" : "The name for the rule, which has a maximimum length of 64 characters."
    },
    "aggregate" : {
      "type" : "string",
      "description" : "A string representing the aggregate function used in this alert rule. Valid aggregate functions are `count`, `count_unique`, `percentage`, `avg`, `apdex`, `failure_rate`, `p50`, `p75`, `p95`, `p99`, `p100`, and `percentile`. See [Metric Alert Rule Types](#metric-alert-rule-types) for valid configurations."
    },
    "timeWindow" : {
      "type" : "integer",
      "description" : "The time period to aggregate over.\n\n* `1` - 1 minute\n* `5` - 5 minutes\n* `10` - 10 minutes\n* `15` - 15 minutes\n* `30` - 30 minutes\n* `60` - 1 hour\n* `120` - 2 hours\n* `240` - 4 hours\n* `1440` - 24 hours",
      "enum" : [ 1, 5, 10, 15, 30, 60, 120, 240, 1440 ]
    },
    "projects" : {
      "type" : "array",
      "description" : "Metric alerts are currently limited to one project. The array should contain a single slug, representing the project to filter by.",
      "items" : {
        "type" : "string"
      }
    },
    "query" : {
      "type" : "string",
      "description" : "An event search query to subscribe to and monitor for alerts. For example, to filter transactions so that only those with status code 400 are included, you could use `\"query\": \"http.status_code:400\"`. Use an empty string for no filter."
    },
    "thresholdType" : {
      "type" : "integer",
      "description" : "The comparison operator for the critical and warning thresholds. The comparison operator for the resolved threshold is automatically set to the opposite operator. When a percentage change threshold is used, `0` is equivalent to \"Higher than\" and `1` is equivalent to \"Lower than\".\n\n* `0` - Above\n* `1` - Below",
      "enum" : [ 0, 1 ]
    },
    "triggers" : {
      "type" : "array",
      "description" : "\nA list of triggers, where each trigger is an object with the following fields:\n- `label`: One of `critical` or `warning`. A `critical` trigger is always required.\n- `alertThreshold`: The value that the subscription needs to reach to trigger the\nalert rule.\n- `actions`: A list of actions that take place when the threshold is met. Set as an empty list if no actions are to take place.\n```json\ntriggers: [\n    {\n        \"label\": \"critical\",\n        \"alertThreshold\": 50,\n        \"actions\": [\n            {\n                \"type\": \"slack\",\n                \"targetType\": \"specific\",\n                \"targetIdentifier\": \"#get-crit\",\n                \"inputChannelId\": 2454362\n                \"integrationId\": 653532,\n            }\n        ]\n    },\n    {\n        \"label\": \"warning\",\n        \"alertThreshold\": 25,\n        \"actions\": []\n    }\n]\n```\nMetric alert rule trigger actions follow the following structure:\n- `type`: The type of trigger action. Valid values are `email`, `slack`, `msteams`, `pagerduty`, `sentry_app`, `sentry_notification`, and `opsgenie`.\n- `targetType`: The type of target the notification will be sent to. Valid values are `specific` (`targetIdentifier` is a direct reference used by the service, like an email address or a Slack channel ID), `user` (`targetIdentifier` is a Sentry user ID), `team` (`targetIdentifier` is a Sentry team ID), and `sentry_app` (`targetIdentifier` is a SentryApp ID).\n- `targetIdentifier`: The ID of the target. This must be an integer for PagerDuty and Sentry apps, and a string for all others. Examples of appropriate values include a Slack channel name (`#my-channel`), a user ID, a team ID, a Sentry app ID, etc.\n- `inputChannelId`: The ID of the Slack channel. This is only used for the Slack action, and can be used as an alternative to providing the `targetIdentifier`.\n- `integrationId`: The integration ID. This is required for every action type excluding `email` and `sentry_app.`\n- `sentryAppId`: The ID of the Sentry app. This is required when `type` is `sentry_app`.\n",
      "items" : { }
    },
    "environment" : {
      "type" : "string",
      "description" : "The name of the environment to filter by. Defaults to all environments.",
      "nullable" : true
    },
    "dataset" : {
      "type" : "string",
      "description" : "The name of the dataset that this query will be executed on. Valid values are `events`, `transactions`, `metrics`, `sessions`, and `generic-metrics`. Defaults to `events`. See [Metric Alert Rule Types](#metric-alert-rule-types) for valid configurations."
    },
    "queryType" : {
      "type" : "integer",
      "description" : "The type of query. If no value is provided, `queryType` is set to the default for the specified `dataset.` See [Metric Alert Rule Types](#metric-alert-rule-types) for valid configurations.\n\n* `0` - event.type:error\n* `1` - event.type:transaction\n* `2` - None",
      "enum" : [ 0, 1, 2 ]
    },
    "eventTypes" : {
      "type" : "array",
      "description" : "List of event types that this alert will be related to. Valid values are `default` (events captured using [Capture Message](/product/sentry-basics/integrate-backend/capturing-errors/#capture-message)), `error` and `transaction`.",
      "items" : {
        "type" : "string"
      }
    },
    "comparisonDelta" : {
      "type" : "integer",
      "description" : "An optional int representing the time delta to use as the comparison period, in minutes. Required when using a percentage change threshold (\"x%\" higher or lower compared to `comparisonDelta` minutes ago). A percentage change threshold cannot be used for [Crash Free Session Rate](#crash-free-session-rate) or [Crash Free User Rate](#crash-free-user-rate)."
    },
    "resolveThreshold" : {
      "type" : "number",
      "description" : "Optional value that the metric needs to reach to resolve the alert. If no value is provided, this is set automatically based on the lowest severity trigger's `alertThreshold`. For example, if the alert is set to trigger at the warning level when the number of errors is above 50, then the alert would be set to resolve when there are less than 50 errors. If `thresholdType` is `0`, `resolveThreshold` must be greater than the critical threshold, otherwise, it must be less than the critical threshold.",
      "format" : "double"
    },
    "owner" : {
      "type" : "string",
      "description" : "The ID of the team or user that owns the rule.",
      "nullable" : true
    }
  }
}
Result Format
Specify how the response should be mapped to the table output. The following formats are available:
  • Structured Table: Returns a parsed table with data split into rows and columns.
    • Environment:
    • Projects:
    • Query Type:
    • Resolve Threshold:
    • Dataset:
    • Threshold Type:
    • Event Types:
    • Owner:
    • Original Alert Rule Id:
    • Comparison Delta:
    • Snooze:
    • Id:
    • Name:
    • Organization Id:
    • Query:
    • Aggregate:
    • Time Window:
    • Triggers:
    • Date Modified:
    • Date Created:
    • Created By:
  • Raw Response: Returns the raw response in a single row with the following columns:
    • body: Response body
    • status: HTTP status code

Input Ports

Icon
Configuration data.

Output Ports

Icon
Result of the request depending on the selected Result Format.
Icon
Configuration data (this is the same as the input port; it is provided as passthrough for sequentially chaining nodes to declutter your workflow connections).

Popular Predecessors

  • No recommendations found

Popular Successors

  • No recommendations found

Views

This node has no views

Workflows

  • No workflows found

Links

Developers

You want to see the source code for this node? Click the following button and we’ll use our super-powers to find it for you.