-
Notifications
You must be signed in to change notification settings - Fork 54
docs(auto-monitor-setup): add upsert by external ID endpoint #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
galzilber
wants to merge
1
commit into
main
Choose a base branch
from
gz/add-pr-758-to-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
api-reference/auto-monitor-setups/upsert-an-auto-monitor-setup-by-external-id.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| --- | ||
| title: "Upsert an Auto Monitor Setup by External ID" | ||
| description: "Idempotently create or fully replace an auto monitor setup identified by external ID" | ||
| api: "PUT /v2/auto-monitor-setups/by-external-id/{external_id}" | ||
| --- | ||
|
|
||
| Idempotent full-replace of an auto monitor setup keyed by `external_id`. If no setup with the given `external_id` exists for the org/project, one is created and the response is `201 Created`. If a setup already exists, all fields in the body fully replace the existing record and the response is `200 OK`. | ||
|
|
||
| The `env_project_id` is preserved across updates — it is only set on the create branch. | ||
|
|
||
| <Note> | ||
| All API requests require authentication. Pass your API key as a Bearer token in the `Authorization` header. | ||
| See [Authentication](/api-reference/introduction) for details. | ||
| </Note> | ||
|
|
||
| ## Path Parameters | ||
|
|
||
| <ParamField path="external_id" type="string" required> | ||
| The external ID of the auto monitor setup to create or replace. | ||
|
|
||
| **Example:** `"my-agent-monitor-1"` | ||
| </ParamField> | ||
|
|
||
| ## Request Body | ||
|
|
||
| <ParamField body="selector" type="object[]" required> | ||
| An array of filter rules used to match spans. Each rule specifies an attribute key, a value to match, and a source indicating where the attribute lives. Only spans matching **all** provided rules will be evaluated. Must contain at least one filter. | ||
|
|
||
| Each rule has the following fields: | ||
|
|
||
| | Field | Type | Required | Description | | ||
| |-------|------|----------|-------------| | ||
| | `key` | string | Yes | The attribute key to filter on (e.g., `gen_ai.system`, `service.name`) | | ||
| | `value` | string | Conditional | The value to match against. **Required** for `equals`, `not_equals`, `contains`, `not_contains` operators | | ||
| | `values` | string[] | Conditional | List of values to match against. **Required** for `in`, `not_in` operators | | ||
| | `source` | string | Yes | Where the attribute lives: `span_attributes` or `resource_attributes` | | ||
| | `operator` | string | No | Comparison operator. Defaults to `equals`. One of: `equals`, `not_equals`, `contains`, `not_contains`, `exists`, `not_exists`, `in`, `not_in` | | ||
| </ParamField> | ||
|
|
||
| <ParamField body="evaluators" type="string[]"> | ||
| List of evaluator slugs to run on matched spans. One of `evaluators` or `evaluator_configs` is required. | ||
|
|
||
| **Example:** `["answer-relevancy", "toxicity-detector"]` | ||
|
|
||
| See the full list of available slugs in the [Evaluator Slugs](/evaluators/evaluator-slugs) reference. | ||
| </ParamField> | ||
|
|
||
| <ParamField body="evaluator_configs" type="object[]"> | ||
| Per-evaluator configuration, used in place of `evaluators` when you need to pass evaluator-specific options. One of `evaluators` or `evaluator_configs` is required. | ||
| </ParamField> | ||
|
|
||
| ## Example Request | ||
|
|
||
| ```bash | ||
| curl -X PUT https://api.traceloop.com/v2/auto-monitor-setups/by-external-id/my-agent-monitor-1 \ | ||
| -H "Authorization: Bearer YOUR_API_KEY" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "evaluators": ["answer-relevancy", "toxicity-detector"], | ||
| "selector": [ | ||
| {"key": "gen_ai.system", "value": "openai", "source": "span_attributes"}, | ||
| {"key": "gen_ai.request.model", "value": "gpt-4o", "source": "span_attributes"} | ||
| ] | ||
| }' | ||
| ``` | ||
|
|
||
| ## Response | ||
|
|
||
| ### 200 OK | ||
|
|
||
| Returned when an existing setup was replaced. The response body is the updated auto monitor setup. | ||
|
|
||
| ### 201 Created | ||
|
|
||
| Returned when a new setup was created. The response body is the newly created auto monitor setup. See the [Create endpoint](/api-reference/auto-monitor-setups/create-an-auto-monitor-setup) for the full response shape. | ||
|
|
||
| ```json | ||
| { | ||
| "id": "cmm...", | ||
| "external_id": "my-agent-monitor-1", | ||
| "org_id": "c108269c-...", | ||
| "project_id": "cm9v2g95l...", | ||
| "env_project_id": "cm9v2ga9i...", | ||
| "init_rules": [ | ||
| { | ||
| "key": "gen_ai.system", | ||
| "value": "openai", | ||
| "source": "span_attributes", | ||
| "operator": "equals" | ||
| }, | ||
| { | ||
| "key": "gen_ai.request.model", | ||
| "value": "gpt-4o", | ||
| "source": "span_attributes", | ||
| "operator": "equals" | ||
| } | ||
| ], | ||
| "evaluators": [ | ||
| { | ||
| "evaluator_type": "answer-relevancy", | ||
| "status": "pending" | ||
| }, | ||
| { | ||
| "evaluator_type": "toxicity-detector", | ||
| "status": "pending" | ||
| } | ||
| ], | ||
| "status": "pending", | ||
| "created_at": "2026-01-15T10:30:00Z", | ||
| "updated_at": "2026-01-15T10:30:00Z" | ||
| } | ||
| ``` | ||
|
|
||
| ### 400 Bad Request | ||
|
|
||
| Returned when the request body is invalid (e.g. empty `selector`, missing both `evaluators` and `evaluator_configs`, or an unknown evaluator slug). | ||
|
|
||
| ```json | ||
| { | ||
| "error": "selector must have at least 1 filter" | ||
| } | ||
| ``` | ||
|
|
||
| ### 500 Internal Server Error | ||
|
|
||
| ```json | ||
| { | ||
| "error": "internal server error" | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update