Update a Metric Alert Rule
Updates a metric alert rule. See Metric Alert Rule Types under Create a Metric Alert Rule for an Organization to see valid request body configurations for different types of metric alert rule types.
Warning: Calling this endpoint fully overwrites the specified metric alert.
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.
Path Parameters
organization_id_or_slug
(string)REQUIREDThe id or slug of the organization the resource belongs to.
alert_rule_id
(integer)REQUIREDThe ID of the rule you'd like to query.
Body Parameters
name
(string)REQUIREDThe name for the rule.
aggregate
(string)REQUIREDA 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
, andpercentile
. See Metric Alert Rule Types under Create a Metric Alert Rule for valid configurations.timeWindow
(integer)REQUIREDThe time period to aggregate over.
1
- 1 minute5
- 5 minutes10
- 10 minutes15
- 15 minutes30
- 30 minutes60
- 1 hour120
- 2 hours240
- 4 hours1440
- 24 hours
projects
(array(string))REQUIREDThe names of the projects to filter by.
query
(string)REQUIREDAn 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
(integer)REQUIREDThe 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" and1
is equivalent to "Lower than".0
- Above1
- Below
triggers
(array(undefined))REQUIREDA list of triggers, where each trigger is an object with the following fields:
label
: One ofcritical
orwarning
. Acritical
trigger is always required.alertThreshold
: The value that the subscription needs to reach to trigger the alert rule.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.
Copiedtriggers: [ { "label": "critical", "alertThreshold": 100, "actions": [ { "type": "email", "targetType": "user", "targetIdentifier": "23489853", "inputChannelId": None "integrationId": None, "sentryAppId": None } ] }, { "label": "warning", "alertThreshold": 75, "actions": [] } ]
Metric alert rule trigger actions follow the following structure:
type
: The type of trigger action. Valid values areemail
,slack
,msteams
,pagerduty
,sentry_app
,sentry_notification
, andopsgenie
.targetType
: The type of target the notification will be sent to. Valid values arespecific
,user
,team
, andsentry_app
.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.inputChannelId
: The ID of the Slack channel. This is only used for the Slack action, and can be used as an alternative to providing thetargetIdentifier
.integrationId
: The integration ID. This is required for every action type exceptemail
andsentry_app.
sentryAppId
: The ID of the Sentry app. This is required whentype
issentry_app
.priority
: The severity of the Pagerduty alert or the priority of the Opsgenie alert (optional). Defaults for Pagerduty arecritical
for critical andwarning
for warning. Defaults for Opsgenie areP1
for critical andP2
for warning.
environment
(string)The name of the environment to filter by. Defaults to all environments.
dataset
(string)The name of the dataset that this query will be executed on. Valid values are
events
,transactions
,metrics
,sessions
, andgeneric-metrics
. Defaults toevents
. See Metric Alert Rule Types under Create a Metric Alert Rule for valid configurations.queryType
(integer)The type of query. If no value is provided,
queryType
is set to the default for the specifieddataset.
See Metric Alert Rule Types under Create a Metric Alert Rule for valid configurations.0
- event.type:error1
- event.type:transaction2
- None
eventTypes
(array(string))List of event types that this alert will be related to. Valid values are
default
(events captured using Capture Message),error
andtransaction
.comparisonDelta
(integer)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 or Crash Free User Rate.resolveThreshold
(number)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. IfthresholdType
is0
,resolveThreshold
must be greater than the critical threshold. Otherwise, it must be less than the critical threshold.owner
(string)The ID of the team or user that owns the rule.
monitorType
(integer)Monitor type represents whether the alert rule is actively being monitored or is monitored given a specific activation condition.
activationCondition
(integer)Optional int that represents a trigger condition for when to start monitoring
Scopes
<auth_token>
requires one of the following scopes:alert_rule:write
alerts:write
org:admin
org:write
curl https://sentry.io/api/0/organizations/{organization_id_or_slug}/alert-rules/{alert_rule_id}/ \ -H 'Authorization: Bearer <auth_token>' \ -X PUT \ -H 'Content-Type: application/json' \ -d '{}'
{
"id": "345989573",
"name": "P30 Transaction Duration",
"organizationId": "02403489017",
"queryType": 1,
"dataset": "transactions",
"query": "",
"aggregate": "percentile(transaction.duration,0.3)",
"thresholdType": 1,
"resolveThreshold": null,
"timeWindow": 60,
"environment": null,
"triggers": [
{
"id": "0543809890",
"alertRuleId": "345989573",
"label": "critical",
"thresholdType": 1,
"alertThreshold": 70,
"resolveThreshold": null,
"dateCreated": "2023-09-25T23:35:31.832084Z",
"actions": []
}
],
"projects": [
"backend"
],
"owner": "team:9390258908",
"originalAlertRuleId": null,
"comparisonDelta": 10080,
"dateModified": "2023-09-25T23:35:31.787866Z",
"dateCreated": "2023-09-25T23:35:31.787875Z",
"createdBy": {
"id": 902843590658,
"name": "Spongebob Squarepants",
"email": "spongebob.s@example.com"
},
"monitorType": 0,
"activations": []
}