Create an alert rule
const url = 'http://localhost:8080/api/v1/projects/example/alert-rules';const options = { method: 'POST', headers: { cookie: 'cetra_session=<cetra_session>', 'Content-Type': 'application/json' }, body: '{"channel_ids":["2489E9AD-2EE2-8E00-8EC9-32D5F69181C0"],"condition":{"aggregation":"avg","comparator":"gt","filter":"example","issue_id":"2489E9AD-2EE2-8E00-8EC9-32D5F69181C0","metric":"error_rate","min_count":1,"score_name":"example","source_id":"2489E9AD-2EE2-8E00-8EC9-32D5F69181C0","target":"trace","threshold":1,"window":"1m"},"cooldown_s":1,"enabled":true,"name":"example","notify_while_firing":true}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url http://localhost:8080/api/v1/projects/example/alert-rules \ --header 'Content-Type: application/json' \ --cookie cetra_session=<cetra_session> \ --data '{ "channel_ids": [ "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0" ], "condition": { "aggregation": "avg", "comparator": "gt", "filter": "example", "issue_id": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "metric": "error_rate", "min_count": 1, "score_name": "example", "source_id": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "target": "trace", "threshold": 1, "window": "1m" }, "cooldown_s": 1, "enabled": true, "name": "example", "notify_while_firing": true }'Needs role member. The filter is checked by the query layer (400 invalid_filter). At most 100 rules per project (409). An enabled rule beyond the org’s plan limit is 403 plan_limit.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”Project UUID, URL-encoded org-slug/project-slug, or current.
Request Bodyrequired
Section titled “Request Bodyrequired”Body of POST /alert-rules.
object
At most 10 channels of this project. Default none.
The condition. Defaults are filled in.
object
score only. Default avg.
How the value is compared with threshold.
Filter DSL expression over traces. Absent means every trace.
issue_occurrences only: count one issue and the issues merged into it. Exactly one of
issue_id and source_id is set for that metric.
What is measured.
Fewer samples than this gives no_data. Not for cost or issue_occurrences. Defaults:
20, or 10 for score.
score only: the score name.
issue_occurrences only: count every issue of the source that is not ignored or merged,
and the issues merged into them.
latency_p95 only. Default trace.
Fraction for error_rate and pass_rate, USD for cost, milliseconds for latency_p95
(below the window length for a trace target), occurrences for issue_occurrences.
Sliding window.
300–604800. Default 3600.
Default true.
1–100 characters after trimming.
Default false.
Responses
Section titled “Responses”The created rule.
One alert rule (D-K-2, D-K-4).
object
Channels notified on fired, resolved and reminder events. Ordered by id.
What is measured and when it breaches, with defaults filled in.
object
score only. Default avg.
How the value is compared with threshold.
Filter DSL expression over traces. Absent means every trace.
issue_occurrences only: count one issue and the issues merged into it. Exactly one of
issue_id and source_id is set for that metric.
What is measured.
Fewer samples than this gives no_data. Not for cost or issue_occurrences. Defaults:
20, or 10 for score.
score only: the score name.
issue_occurrences only: count every issue of the source that is not ignored or merged,
and the issues merged into them.
latency_p95 only. Default trace.
Fraction for error_rate and pass_rate, USD for cost, milliseconds for latency_p95
(below the window length for a trace target), occurrences for issue_occurrences.
Sliding window.
Minimum seconds between two reminders while firing.
Creation time.
Disabled rules are not evaluated.
Rule id.
Sample count of the last successful evaluation.
Why the last evaluation failed. Absent after a successful one.
Last evaluation, successful or not.
Last fired event.
Value of the last successful evaluation.
Display name, unique in the project.
Send a reminder every cooldown_s while firing.
Current state.
Last change.
Example
{ "condition": { "aggregation": "avg", "comparator": "gt", "metric": "error_rate", "target": "trace", "window": "1m" }, "state": "ok"}The request is malformed or a filter is invalid.
RFC 7807 problem document.
Spec 09 § Conventions.
object
Machine-readable error code.
Extra explanation. Omitted when absent.
Field errors. Omitted when empty, because RFC 7807 clients expect the member to be absent.
One field that failed validation.
Spec 09 § Conventions.
object
Request field, query parameter, or expression the error refers to.
What is wrong with the field.
Location inside the field value, for filter and SQL errors.
object
1-based column number, in characters.
1-based line number, in characters.
HTTP status code.
Short human-readable summary, the reason phrase of status.
Problem type URI. Always about:blank in this version.
Example
{ "code": "bad_request"}No credentials, or the credentials are invalid.
RFC 7807 problem document.
Spec 09 § Conventions.
object
Machine-readable error code.
Extra explanation. Omitted when absent.
Field errors. Omitted when empty, because RFC 7807 clients expect the member to be absent.
One field that failed validation.
Spec 09 § Conventions.
object
Request field, query parameter, or expression the error refers to.
What is wrong with the field.
Location inside the field value, for filter and SQL errors.
object
1-based column number, in characters.
1-based line number, in characters.
HTTP status code.
Short human-readable summary, the reason phrase of status.
Problem type URI. Always about:blank in this version.
Example
{ "code": "bad_request"}The credentials do not allow this operation, or the organization’s plan does not include it (code plan_required).
RFC 7807 problem document.
Spec 09 § Conventions.
object
Machine-readable error code.
Extra explanation. Omitted when absent.
Field errors. Omitted when empty, because RFC 7807 clients expect the member to be absent.
One field that failed validation.
Spec 09 § Conventions.
object
Request field, query parameter, or expression the error refers to.
What is wrong with the field.
Location inside the field value, for filter and SQL errors.
object
1-based column number, in characters.
1-based line number, in characters.
HTTP status code.
Short human-readable summary, the reason phrase of status.
Problem type URI. Always about:blank in this version.
Example
{ "code": "bad_request"}The resource does not exist.
RFC 7807 problem document.
Spec 09 § Conventions.
object
Machine-readable error code.
Extra explanation. Omitted when absent.
Field errors. Omitted when empty, because RFC 7807 clients expect the member to be absent.
One field that failed validation.
Spec 09 § Conventions.
object
Request field, query parameter, or expression the error refers to.
What is wrong with the field.
Location inside the field value, for filter and SQL errors.
object
1-based column number, in characters.
1-based line number, in characters.
HTTP status code.
Short human-readable summary, the reason phrase of status.
Problem type URI. Always about:blank in this version.
Example
{ "code": "bad_request"}The request conflicts with the current state.
RFC 7807 problem document.
Spec 09 § Conventions.
object
Machine-readable error code.
Extra explanation. Omitted when absent.
Field errors. Omitted when empty, because RFC 7807 clients expect the member to be absent.
One field that failed validation.
Spec 09 § Conventions.
object
Request field, query parameter, or expression the error refers to.
What is wrong with the field.
Location inside the field value, for filter and SQL errors.
object
1-based column number, in characters.
1-based line number, in characters.
HTTP status code.
Short human-readable summary, the reason phrase of status.
Problem type URI. Always about:blank in this version.
Example
{ "code": "bad_request"}Too many requests.
RFC 7807 problem document.
Spec 09 § Conventions.
object
Machine-readable error code.
Extra explanation. Omitted when absent.
Field errors. Omitted when empty, because RFC 7807 clients expect the member to be absent.
One field that failed validation.
Spec 09 § Conventions.
object
Request field, query parameter, or expression the error refers to.
What is wrong with the field.
Location inside the field value, for filter and SQL errors.
object
1-based column number, in characters.
1-based line number, in characters.
HTTP status code.
Short human-readable summary, the reason phrase of status.
Problem type URI. Always about:blank in this version.
Example
{ "code": "bad_request"}The server is busy or a dependency is unavailable. Retry later.
RFC 7807 problem document.
Spec 09 § Conventions.
object
Machine-readable error code.
Extra explanation. Omitted when absent.
Field errors. Omitted when empty, because RFC 7807 clients expect the member to be absent.
One field that failed validation.
Spec 09 § Conventions.
object
Request field, query parameter, or expression the error refers to.
What is wrong with the field.
Location inside the field value, for filter and SQL errors.
object
1-based column number, in characters.
1-based line number, in characters.
HTTP status code.
Short human-readable summary, the reason phrase of status.
Problem type URI. Always about:blank in this version.
Example
{ "code": "bad_request"}