Skip to content

feat(cli): add event analytics command for dropped events - #1812

Merged
BYK merged 5 commits into
mainfrom
sarajmanes/dain-1940-event-analytics
Nov 5, 2026
Merged

BYK merged 5 commits into
mainfrom
sarajmanes/dain-1940-event-analytics

Conversation

@manessaraj

@manessaraj manessaraj commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Adds sentry event analytics, which reports events Sentry received but dropped before storage (rate-limited, filtered, invalid, abuse, client-discarded, cardinality-limited), one row per outcome and reason with each slice's share of total volume. It is the CLI counterpart to the find_dropped_events MCP tool, so an agent or a person working headless can see data-fidelity gaps without the web UI.

This reopens the work previously attempted in #1579, redone from scratch. The earlier attempt duplicated the dropped-events schema and dataset handling inside the CLI, which drifted from the MCP implementation and drew repeated review. The redo instead reuses the now-shared pieces that landed since then — the buildDatasetParser dataset map in lib/datasets.ts (so metrics normalizes to tracemetrics at parse time) and the find_dropped_events MCP feedback on response shape and tags — and builds on the standard command, target, and completion primitives rather than hand-rolled ones. The schema treats tags as optional, matching the endpoint and the MCP tool.

Verified end-to-end against production (project 1): the command resolves the project, fetches dropped events, and renders both the grouped human table and the JSON array, across the errors and spans datasets.

Refs DAIN-1940

@vercel

vercel Bot commented Nov 2, 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 Nov 5, 2026 10:28am UTC

Request Review

@linear-code

linear-code Bot commented Nov 2, 2026

Copy link
Copy Markdown

DAIN-1940

@manessaraj
manessaraj force-pushed the sarajmanes/dain-1940-event-analytics branch from 91a4f3d to 870b28e Compare November 4, 2026 15:08
sentry-junior[bot]
sentry-junior Bot previously requested changes Nov 4, 2026

@sentry-junior sentry-junior 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.

First-pass review on behalf of @BYK, checked against his feedback on #1579 and #1559 and the recent CLI standardisation work (reviewed at 870b28e).

Most of the earlier feedback is addressed. The name is now event analytics. Examples moved to docs.examples. Datasets go through the shared buildDatasetParser. The JSON output is flat rows with an item schema, so --fields outcome,reason,events works. The project ID is resolved strictly through fetchProjectId. Nice work on the redo.

Requesting changes for these:

  • @sentry/api already has this endpoint. lib/api/dropped-events.ts says it is "Not yet in @sentry/api", but listOrganizationEventsDropped, ListOrganizationEventsDroppedResponse and vListOrganizationEventsDroppedResponse are all in the catalog's @sentry/api. packages/cli/AGENTS.md says to use the SDK types instead of redundant Valibot schemas, and BYK made the same point on #1559 ("we should use them from there not repeat types across repos"). The local response schema in types/dropped-events.ts duplicates the SDK's.
  • The output schema is in its own module. AGENTS.md says src/output-schemas/ has one module per top-level command, so DroppedEventRowSchema belongs in output-schemas/event.ts. Its API fields (outcome, reason, category, tags) should come from the generated valibot entries, as project.ts does with vOrganizationProjectResponseDict.item.entries.
  • --period is back to a local 24h default. The earlier commit that switched it to LIST_PERIOD_FLAG / PERIOD_ALIASES was lost in the force-push. BYK asked on #1559 for the default to match the rest of the CLI, and attribute, span, trace, replay and agent-conversation list all use the shared 7d flag.

I'm pushing a commit for all three right after this review:

  • getDroppedEvents calls listOrganizationEventsDropped through getOrgSdkConfig + unwrapResult, like lib/api/issue-tags.ts.
  • types/dropped-events.ts and output-schemas/dropped-events.ts are gone. The row schema lives in output-schemas/event.ts, built from vListOrganizationEventsDroppedResponse, and outcomeLabel moved into the formatter.
  • Sentry only added tags in getsentry/sentry#127850. The summarizer still defaults them to [] for older self-hosted servers, and a formatter test covers that.
  • --period uses the shared flag again. The skill reference is regenerated.

Still on you (@manessaraj): "analytics" only shows drops. On #1579 BYK asked to note adding accepted and other volumes, so that this becomes a real analytics command. The response already includes acceptedEvents, and share is computed against them, but they never appear in the output, and the PR doesn't link a follow-up. Either show the accepted total (for example as a row or a header line), or open a ticket and link it here.

The event, dropped-events API, and formatter tests pass with the fix commit, along with CLI typecheck and repo lint. I didn't run the full suite.

- getDroppedEvents uses listOrganizationEventsDropped with getOrgSdkConfig
  and unwrapResult instead of a hand-written request and response schema.
- The row schema moves to output-schemas/event.ts and takes its API fields
  from vListOrganizationEventsDroppedResponse. types/dropped-events.ts and
  output-schemas/dropped-events.ts are removed.
- Tags still default to [] for servers older than getsentry/sentry#127850.
- --period uses LIST_PERIOD_FLAG and PERIOD_ALIASES (7d default, -t).

Co-Authored-By: BYK <[email protected]>

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Jr is right :D

event analytics only listed drops, though the endpoint returns the
accepted volume and share was already computed against it. BYK asked on
#1579 for accepted volume so this is a real analytics command.

- Accepted volume comes first as its own outcome row (Sentry reports
  outcome and reason `accepted`, no tags). Drop rows follow, sorted as
  before.
- The human output shows accepted as a header line with no reason table.
- The "No dropped events" hint now fires when only accepted rows exist.
- The row schema, summarizer and formatter are renamed from DroppedEvent*
  to EventOutcome*, since rows are no longer only drops.

Co-Authored-By: BYK <[email protected]>
@sentry-junior

sentry-junior Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

On behalf of @BYK: I pushed f536c4c, which takes care of the last open item from the review ("analytics" only showing drops).

  • Accepted volume is now the first row. Sentry returns it with outcome and reason accepted and empty tags. The drop rows follow it, in the same order as before. share is still each slice's fraction of accepted + dropped, so the shares now add up to 100%.
  • In human output, accepted is one header line (Accepted: 9,500 (95.00%)) with no reason table. Each drop outcome keeps its header and table.
  • The No dropped events for <org>/<project>. hint now also shows when the only rows are accepted ones.
  • DroppedEventRow*, summarizeDroppedEvents and formatDroppedEvents are renamed to EventOutcome*, because the rows aren't only drops anymore. The file names stay the same since they match the events-dropped endpoint.
  • The brief, description, schema field descriptions and skill reference are updated and regenerated.

@manessaraj, if you'd rather show accepted a different way (for example as a header line only, with no JSON row), say so and I'll change it.

Verified: CLI tsc, repo pnpm run lint, and the event + formatter tests pass, including new tests for accepted ordering, rendering and the accepted-only hint. In the full CLI unit run, 11 tests fail (permission, auth-message and oauth tests). The same tests fail on the previous head without this change, so they're from the sandbox and not this PR.

The formatter renders accepted and dropped volume now, so the
dropped-events file name was stale next to the EventOutcome* exports.
lib/api/dropped-events.ts keeps its name: it wraps the events-dropped
endpoint (listOrganizationEventsDropped).

Co-Authored-By: BYK <[email protected]>
@BYK
BYK dismissed sentry-junior[bot]’s stale review November 5, 2026 10:52

did on behalf of me, now we're good

@BYK
BYK merged commit 586e6e0 into main Nov 5, 2026
27 checks passed
@BYK
BYK deleted the sarajmanes/dain-1940-event-analytics branch November 5, 2026 10:52

This branch was previously deployed

1 inactive deployment
Preview — 0a6ce7d1 Deployed Nov 5, 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.

2 participants