Skip to content

fix(formatting): read camelCase metric alert evidence and link to breach data - #1715

Open
sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/metric-issue-alert-context
Open

sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/metric-issue-alert-context

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #1087.

Metric issue output only showed the evaluated value and threshold. The event API camelCases the whole occurrence payload (convert_dict_key_case(occurrence.to_dict(), snake_to_camel_case) in sentry's api/serializers/models/event.py). The formatter from #1129 read snake_case keys (data_sources, query_obj, snuba_query, alert_id), so the dataset, aggregate, query, interval and environment never rendered. Only single-word keys like value and conditions matched. The #1129 tests used hand-written snake_case fixtures, so they passed anyway.

Agents also had no next step. The Response Notes suggested stacktrace and trace lookups, which don't apply to metric issues: the event's trace context comes from the monitor evaluation, not from the data that crossed the threshold.

Changes

  • Read dataSources[].queryObj.snubaQuery, detectorId and the legacy alertId.
  • Show the Metric Monitor ID, a readable dataset label (Errors, Logs, Spans or Application metrics, following the UI's getDetectorDataset mapping) and the evaluated window (timeWindow before the occurrence).
  • For metric issues, Response Notes now include:
    • get_metric_monitor_details(organizationSlug, monitorId) for the monitor configuration and connected Alerts.
    • A ready-to-run search_errors, search_logs, search_traces or search_metrics call, chosen by dataset. It is pre-filled with the monitor's query plus an environment: filter, the project, and a relative period that reaches back to the evaluated window. The window's start and end are shown next to it.
  • Add an opt-in showArguments to formatToolCallInstruction so these notes print the full call. Previously it ignored arguments.
  • Rebuild the metric tests from the real camelCased event shape, and add Response Notes coverage.

Example (logs monitor)

**Monitor ID**: 1234567
**Dataset**: Logs
**Aggregate**: count(message)
**Query**: `severity:error`
**Interval**: 3600 second(s)
**Environment**: prod
**Evaluated Window**: 2026-10-28T10:39:52.000Z to 2026-10-28T11:39:52.000Z
**Evaluated Value**: 4988
**Threshold**: above 4000
...
- Metric Monitor configuration and connected Alerts: Use the Sentry tool `get_metric_monitor_details(organizationSlug='sentry', monitorId='1234567')`
- Logs matched by the monitor query: Use the Sentry tool `search_logs(organizationSlug='sentry', projectSlug='seer', query='severity:error environment:prod', period='16h')`, then focus on 2026-10-28T10:39:52.000Z to 2026-10-28T11:39:52.000Z

Notes

  • The search call is left out for transactions, generic_metrics and crash-free (metrics/sessions) monitors. Their query syntax doesn't map cleanly onto the current search tools. The monitor ID and details note still render.
  • The search tools only accept a relative period, so the call can return data after the breach too. That's why the note gives the exact window to focus on.
  • The fixture shape comes from the sentry serializers (EvidenceData in workflow_engine/handlers/detector/base.py, DataSourceSerializer and SnubaQuerySerializer). It has not been checked against a captured production payload.

Tests

  • pnpm exec vitest run in packages/mcp-core: 1886 passed, 6 skipped
  • tsc --noEmit (mcp-core), oxlint, oxfmt --check, ast-grep on changed files: clean

via Dhrumil.

--

View Junior Session [Sentry]

…ach data

Metric issue output only showed the evaluated value and threshold. The
event API camelCases the whole occurrence payload, but the formatter read
snake_case keys (`data_sources`, `query_obj`, `snuba_query`, `alert_id`),
so dataset, aggregate, query, interval and environment never rendered.
Only single-word keys like `value` and `conditions` matched.

- Read `dataSources[].queryObj.snubaQuery`, `detectorId` and `alertId`.
- Show the Metric Monitor ID, a readable dataset label and the evaluated
  window.
- Replace the stacktrace and trace hints in Response Notes with
  `get_metric_monitor_details` and a pre-filled `search_errors`,
  `search_logs`, `search_traces` or `search_metrics` call for the
  monitor's query, environment and a period covering the breach.
- Rebuild the metric tests from the real camelCased event shape.

Fixes #1087

Co-Authored-By: Dhrumil Parekh <dhrumil.parekh@sentry.io>
@vercel

vercel Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Oct 29, 2026 3:04am UTC

Request Review

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a819d48. Configure here.

Comment thread packages/mcp-core/src/internal/formatting.ts
Sentry search binds implicit AND tighter than OR, so appending
`environment:` to an OR query only constrained its last term.

This branch was previously deployed

1 inactive deployment
Preview — 5dbee373 Deployed Oct 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metric issue output missing alert rule details (query, aggregate, condition)

0 participants