Skip to content

fix(sentry): handle REST issue event formatting#1342

Merged
aaight merged 2 commits into
devfrom
fix/sentry-event-detail-rest-format
May 11, 2026
Merged

fix(sentry): handle REST issue event formatting#1342
aaight merged 2 commits into
devfrom
fix/sentry-event-detail-rest-format

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented May 11, 2026

Summary

Fixes https://linear.app/issue/MNG-665

This PR makes GetAlertingEventDetail tolerant of Sentry's REST issue-event response shape so object-array tags and REST aliases no longer crash formatting before agents can see the alert details.

Changes

  • Widens Sentry event/frame types to include REST fields such as id, eventID, dateCreated, entries, object-array tags, request entries, and frame aliases like lineNo, inApp, absPath, and source context.
  • Normalizes event formatting for tag tuples, tag objects, tag maps, event ID/timestamp/release aliases, exception/breadcrumb/request entries, REST stack frame aliases, and compact event context output.
  • Adds regression tests for REST-shaped Sentry issue events, legacy tag shapes, event-list ID aliases, and the mocked getSentryEventDetail() core path.
  • Updates the alerting gadget architecture docs to describe stacktrace, tags, breadcrumbs, request data, context, and the Sentry REST issue-event source shape.

Verification

  • npx vitest run --project unit-core tests/unit/gadgets/sentry/format.test.ts tests/unit/gadgets/sentry/getSentryEventDetail.test.ts tests/unit/sentry/client.test.ts
  • npm run lint:fix
  • npm run lint (passes; reports existing warning-level findings in unrelated files)
  • npm run typecheck
  • npm test
  • npm run build
  • node bin/cascade-tools.js alerting get-alerting-event --organizationId mongrel --issueId 119054737 --eventId latest returned success: true and formatted stacktrace/tags/breadcrumbs/context.

Notes

A bare cascade-tools ... smoke before building this checkout used the installed PATH binary and reproduced the original iterable error. After npm run build, node bin/cascade-tools.js ... exercised this branch's local dist/ and succeeded.

🕵️ codex · gpt-5.5 · run details

@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

❌ Patch coverage is 74.83444% with 38 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/gadgets/sentry/core/format.ts 74.83% 35 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

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

Summary

Requesting changes for one REST-shape gap: request query parameters from Sentry issue-event entries are still dropped.

Code Issues

Should Fix

  • src/gadgets/sentry/core/format.ts:194getEventRequest() returns the REST request entry, but appendEventRequest() only reads query_string / queryString. Sentry's Retrieve an Issue Event response puts request query params under data.query as tuple pairs, so a real REST event in that shape renders only the method and URL and loses the query values agents need. Please widen SentryRequest and format query arrays/maps, with a regression test using that REST shape.

Verification

  • npx vitest run --project unit-core tests/unit/gadgets/sentry/format.test.ts tests/unit/gadgets/sentry/getSentryEventDetail.test.ts tests/unit/sentry/client.test.ts

🕵️ codex · gpt-5.5 · run details

Comment thread src/gadgets/sentry/core/format.ts Outdated
lines.push(`${event.request.method ?? 'GET'} ${event.request.url}`);
if (event.request.query_string) lines.push(`Query: ${event.request.query_string}`);
lines.push(`${request.method ?? 'GET'} ${request.url}`);
const query = request.query_string ?? request.queryString;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This still misses Sentry's REST request query shape. The issue-event API returns request entry data with query tuple pairs, not queryString; those parameters are currently omitted. Please normalize query here too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed! Added a query field to SentryRequest typed as string | Array<[string, string]> | Record<string, string> to cover Sentry's REST issue-event shape. Extracted a normalizeRequestQuery() helper that:

  1. Tries query_string / queryString first (existing aliases)
  2. Falls through to query — serializing tuple pairs as key=value&..., records the same way, or passing a plain string as-is

appendEventRequest now calls this helper so tuple-pair query params from REST events are rendered in the Query: line. Four new regression tests cover: tuple-pairs, record shape, plain-string passthrough, and the precedence rule (query_string wins over query). All 28 targeted tests pass.

Widens SentryRequest with a `query` field (tuple pairs | record | string)
to cover Sentry's Retrieve-an-Issue-Event REST shape where query params
are returned under `data.query` rather than `queryString`. Adds
normalizeRequestQuery() helper that falls back from query_string/queryString
to the tuple-pairs/record/string shape, and regression tests for each
variant plus the precedence rule.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

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

LGTM - the formatter now handles the REST issue-event shapes from the work item, including object tags, entry-based exception/breadcrumb/request data, request query tuples/maps, frame aliases, and compact context output. Targeted unit verification passed locally:
RUN v3.2.4 /workspace/cascade-cascade-1778507589998

✓ |unit-core| tests/unit/gadgets/sentry/format.test.ts (7 tests) 3ms
✓ |unit-core| tests/unit/gadgets/sentry/getSentryEventDetail.test.ts (2 tests) 3ms

Test Files 2 passed (2)
Tests 9 passed (9)
Start at 13:56:51
Duration 304ms (transform 156ms, setup 34ms, collect 148ms, tests 7ms, environment 0ms, prepare 101ms) (28 tests).

🕵️ codex · gpt-5.5 · run details

@aaight aaight merged commit c7bfc92 into dev May 11, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants