Skip to content

Events endpoint: missing metricsEnhanced dataset and meta.units in response type #71

@MathurAditya724

Description

@MathurAditya724

Summary

The queryExploreEventsInTableFormat SDK function wraps GET /api/0/organizations/{org}/events/, but its OpenAPI spec has two gaps that prevent the Sentry CLI from using it for the sentry explore command. The CLI currently drops down to raw HTTP via apiRequestToRegion() in src/lib/api/discover.ts to work around both issues.

Gap 1: metricsEnhanced missing from dataset enum

The spec declares the dataset query parameter as:

'discover' | 'errors' | 'logs' | 'profile_functions' | 'spans' | 'transactions' | 'uptime_results'

The Sentry backend also accepts metricsEnhanced (used by the Explore Metrics UI for tracemetrics queries — sum(value, metric_name, metric_type, unit) format). The CLI maps --dataset metrics to metricsEnhanced at the API level.

Passing dataset: "metricsEnhanced" to the SDK function is a type error, so the CLI can't use the SDK for metrics queries.

replays may also be missing — the CLI uses it for --dataset replays on the same endpoint.

Gap 2: meta.units missing from response type

The actual API response includes meta.units — a Record<string, string | null> mapping field names to their unit (e.g., "millisecond", "none"). The SDK's OrganizationEventsResponseDict type does not include it:

SDK type:

meta: {
  fields: { [key: string]: string };
  datasetReason?: string;
  isMetricsData?: boolean;
  isMetricsExtractedData?: boolean;
};

Actual API response also includes:

meta: {
  // ...above fields...
  units?: { [key: string]: string | null };
};

The CLI uses meta.units for dashboard widget formatting and metric metadata extraction. Without it in the SDK type, callers need manual type augmentation or a separate Zod schema.

Impact

The CLI's src/lib/api/discover.ts uses raw apiRequestToRegion() with a hand-written EventsTableResponseSchema instead of the SDK's queryExploreEventsInTableFormat. This is inconsistent with other API modules (logs.ts, issues.ts, events.ts, etc.) that already use the SDK.

Similarly, src/lib/api/dashboards.ts uses raw requests for the same endpoint for widget table/timeseries queries.

Expected behavior

  1. Add metricsEnhanced (and replays if valid) to the dataset enum for queryExploreEventsInTableFormat and queryExploreEventsInTimeseriesFormat
  2. Add units?: { [key: string]: string | null } to the meta object in OrganizationEventsResponseDict

Workaround

The CLI maintains a custom Zod schema EventsTableResponseSchema in src/types/dashboard.ts and calls the API directly: https://github.com/getsentry/cli/blob/main/src/lib/api/discover.ts

Metadata

Metadata

Labels

No labels
No labels
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions