Skip to content

API schema: type occurrence evidenceData per occurrence type (starting with metric issues) #129578

Closed

Description

@sentry-junior

Problem

In the public API schema, the serialized issue occurrence types evidenceData as dict[str, Any]. That's IssueOccurrenceResponse.evidenceData in src/sentry/issues/issue_occurrence.py. In the generated @sentry/api client (getsentry/sentry-api-schema) it becomes { [key: string]: unknown }, so API consumers get no type checking for evidence fields.

This caused a real bug in the Sentry MCP: getsentry/toolkit#1087, fixed in getsentry/toolkit#1715. The MCP read snake_case keys (data_sources, query_obj, snuba_query, time_window) from metric issue evidence. EventSerializer (src/sentry/api/serializers/models/event.py) recursively camelCases the occurrence with convert_dict_key_case(occurrence.to_dict(), snake_to_camel_case), so the API actually returns dataSources, queryObj, snubaQuery and timeWindow. The monitor's dataset, aggregate, query and interval silently disappeared, and the tests passed only because they used hand-written snake_case fixtures. A typed schema would have caught this at compile time.

Proposal

  • Type occurrence.evidenceData in the OpenAPI output per occurrence type, for example as a discriminated union on occurrence.type.
  • Start with metric issues (8001). The shape already exists as MetricIssueEvidenceData in src/sentry/incidents/grouptype.py: detectorId, value, conditions, and dataSources[].queryObj.snubaQuery.{dataset, aggregate, query, timeWindow, environment}.
  • Use the camelCase keys the serializer actually emits, not the snake_case dataclass fields. Otherwise the generated types repeat the same mismatch.
  • Related: detector dataSources is also Array<{ [key: string]: unknown }> in the generated client. See Use typed detector schemas from @sentry/api for metric monitors toolkit#1595.

Requested by Burak Yigit Kaya in Slack.

via @BYK.

--

View Session [Sentry]

Activity

  1. linear-code commented on Nov 2, 2026

    @linear-code
  2. added a commit that references this issue on Nov 2, 2026
    c571057
  3. added a commit that references this issue on Nov 3, 2026
    4ac783c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions