Skip to content

Commit 1c97cbf

Browse files
fix(explore): use tracemetrics dataset instead of metricsEnhanced (#995)
`--dataset metrics` and `--metric` auto-resolver were sending `dataset=metricsEnhanced` to the Events API, which routes to the legacy `metrics_enhanced_performance` backend. SDK v10 trace metrics live in the `tracemetrics` dataset (backed by `TraceMetrics`), which is what the Sentry Explore Metrics UI uses. Switched all metrics-related API calls to `tracemetrics`. ## Testing `bun test test/commands/explore.test.ts` — 37/38 pass (1 pre-existing failure from missing `api-schema.json`). `bun test test/types/dashboard.test.ts` — 96/96 pass. `bun test test/commands/dashboard/resolve.test.ts` — 76/76 pass. `bun test test/lib/metrics-transform.test.ts` — 10/10 pass. Fixes #994 <!-- ## Plan Root cause: the Sentry Events API has two distinct dataset values for metrics: - `metricsEnhanced` → `metrics_enhanced_performance` (legacy DDM/release-health) - `tracemetrics` → `TraceMetrics` (SDK v10 trace metrics, used by Explore Metrics UI) The CLI was sending `metricsEnhanced` everywhere, which can't find SDK v10 metrics. Changes: 1. `src/commands/explore.ts` — DATASET_ALIASES maps `metrics` → `"tracemetrics"`, all internal comparisons updated 2. `src/lib/api/discover.ts` — `queryMetricsMeta` uses `dataset: "tracemetrics"` 3. `src/types/dashboard.ts` — `WIDGET_TYPE_TO_DATASET` maps `tracemetrics` → `"tracemetrics"` 4. Comments and tests updated to match -->
1 parent 95ff2e3 commit 1c97cbf

7 files changed

Lines changed: 24 additions & 25 deletions

File tree

src/commands/dashboard/resolve.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,7 @@ const DATASET_ALIASES: Record<string, string> = {
818818
transactions: "transaction-like",
819819
log: "logs",
820820
// `metrics` and `metricsEnhanced` both alias to the canonical `tracemetrics`.
821-
// `metricsEnhanced` is the value surfaced by the events API dataset param
822-
// (see WIDGET_TYPE_TO_DATASET in types/dashboard.ts) and may appear in docs.
821+
// `metricsEnhanced` is a legacy API synonym and may appear in older docs.
823822
metrics: "tracemetrics",
824823
metricsenhanced: "tracemetrics",
825824
};

src/commands/explore.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const DATASET_ALIASES: Record<string, string> = {
8585
error: "errors",
8686
spans: "spans",
8787
span: "spans",
88-
metrics: "metricsEnhanced",
88+
metrics: "tracemetrics",
8989
logs: "logs",
9090
log: "logs",
9191
replays: "replays",
@@ -113,7 +113,7 @@ const VALID_DATASETS = new Set([
113113

114114
/**
115115
* Reverse map from API-level dataset name → canonical user-facing name.
116-
* Used by pagination hints so they emit `--dataset metrics` not `--dataset metricsEnhanced`.
116+
* Used by pagination hints so they emit `--dataset metrics` not `--dataset tracemetrics`.
117117
*/
118118
const API_TO_USER_DATASET = new Map(
119119
Array.from(VALID_DATASETS, (name) => [DATASET_ALIASES[name] ?? name, name])
@@ -363,7 +363,7 @@ function appendFlagHints(
363363
const defaultSort =
364364
flags.dataset === "replays" ? DEFAULT_REPLAY_SORT : undefined;
365365
if (flags.dataset !== DEFAULT_DATASET) {
366-
// Emit user-facing name, not API-level name (e.g. "metrics" not "metricsEnhanced")
366+
// Emit user-facing name, not API-level name (e.g. "metrics" not "tracemetrics")
367367
const displayDataset =
368368
API_TO_USER_DATASET.get(flags.dataset) ?? flags.dataset;
369369
parts.push(`--dataset ${displayDataset}`);
@@ -412,7 +412,7 @@ function isTracemetricsAggregate(aggregate: string): boolean {
412412

413413
/**
414414
* Validate that aggregate fields use the tracemetrics format when querying
415-
* the `metricsEnhanced` dataset. Standard aggregates like `count()` or
415+
* the `tracemetrics` dataset. Standard aggregates like `count()` or
416416
* `avg(measurements.fcp)` are invalid — the API requires the four-part
417417
* comma-separated format: `aggregation(value,metric_name,metric_type,unit)`.
418418
*/
@@ -720,9 +720,9 @@ export const exploreCommand = buildListCommand("explore", {
720720

721721
// --metric auto mode: resolve metric name → tracemetrics aggregate
722722
if (flags.metric) {
723-
if (dataset !== "metricsEnhanced") {
723+
if (dataset !== "tracemetrics") {
724724
log.warn("--metric implies --dataset metrics; switching dataset.");
725-
dataset = "metricsEnhanced";
725+
dataset = "tracemetrics";
726726
}
727727

728728
// Use the user's --period for metadata discovery so older metrics are found
@@ -745,7 +745,7 @@ export const exploreCommand = buildListCommand("explore", {
745745
? fieldList.filter((f) => !isAggregate(f))
746746
: [];
747747
fieldList = [...groupByFields, aggField];
748-
} else if (dataset === "metricsEnhanced") {
748+
} else if (dataset === "tracemetrics") {
749749
if (!userSuppliedFields) {
750750
throw new ValidationError(
751751
"The metrics dataset requires --metric or explicit --field flags.\n\n" +

src/lib/api/discover.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export type MetricMeta = {
9696
/**
9797
* Discover available metrics for an org via the Events API.
9898
*
99-
* Queries `dataset=metricsEnhanced` with meta-fields (`metric.name`, etc.)
99+
* Queries `dataset=tracemetrics` with meta-fields (`metric.name`, etc.)
100100
* — the same technique the Sentry Explore Metrics UI uses.
101101
*
102102
* Auto-paginates to collect all available metrics (bounded by
@@ -116,7 +116,7 @@ export async function queryMetricsMeta(
116116

117117
const baseOptions: ExploreQueryOptions = {
118118
fields: ["metric.name", "metric.type", "metric.unit"],
119-
dataset: "metricsEnhanced",
119+
dataset: "tracemetrics",
120120
query,
121121
statsPeriod:
122122
options?.start || options?.end

src/lib/metrics-transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Transforms user-friendly metric names (e.g., `llm.token_usage`) into the
55
* four-part tracemetrics format required by the Sentry Events API when
6-
* querying `dataset=metricsEnhanced`: `aggregation(value,name,type,unit)`.
6+
* querying `dataset=tracemetrics`: `aggregation(value,name,type,unit)`.
77
*/
88

99
import type { MetricMeta } from "./api/discover.js";

src/types/dashboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ const WIDGET_TYPE_TO_DATASET: Record<string, string> = {
10021002
"error-events": "errors",
10031003
"transaction-like": "transactions",
10041004
logs: "logs",
1005-
tracemetrics: "metricsEnhanced",
1005+
tracemetrics: "tracemetrics",
10061006
};
10071007

10081008
/**

test/commands/explore.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ describe("sentry explore", () => {
510510
context,
511511
{
512512
...DEFAULT_FLAGS,
513-
dataset: "metricsEnhanced",
513+
dataset: "tracemetrics",
514514
field: ["title", "count()"],
515515
},
516516
"test-org/"
@@ -528,7 +528,7 @@ describe("sentry explore", () => {
528528
context,
529529
{
530530
...DEFAULT_FLAGS,
531-
dataset: "metricsEnhanced",
531+
dataset: "tracemetrics",
532532
field: [
533533
"gen_ai.request.model",
534534
"sum(value,llm.token_usage,distribution,none)",
@@ -539,7 +539,7 @@ describe("sentry explore", () => {
539539

540540
expect(queryEventsSpy).toHaveBeenCalledWith(
541541
"test-org",
542-
expect.objectContaining({ dataset: "metricsEnhanced" })
542+
expect.objectContaining({ dataset: "tracemetrics" })
543543
);
544544
});
545545

@@ -549,7 +549,7 @@ describe("sentry explore", () => {
549549

550550
const promise = func.call(
551551
context,
552-
{ ...DEFAULT_FLAGS, dataset: "metricsEnhanced" },
552+
{ ...DEFAULT_FLAGS, dataset: "tracemetrics" },
553553
"test-org/"
554554
);
555555

@@ -567,7 +567,7 @@ describe("sentry explore", () => {
567567
context,
568568
{
569569
...DEFAULT_FLAGS,
570-
dataset: "metricsEnhanced",
570+
dataset: "tracemetrics",
571571
field: ["gen_ai.request.model"],
572572
},
573573
"test-org/"
@@ -584,7 +584,7 @@ describe("sentry explore", () => {
584584
context,
585585
{
586586
...DEFAULT_FLAGS,
587-
dataset: "metricsEnhanced",
587+
dataset: "tracemetrics",
588588
metric: "llm.token_usage",
589589
},
590590
"test-org/"
@@ -598,7 +598,7 @@ describe("sentry explore", () => {
598598
"test-org",
599599
expect.objectContaining({
600600
fields: ["sum(value,llm.token_usage,distribution,none)"],
601-
dataset: "metricsEnhanced",
601+
dataset: "tracemetrics",
602602
})
603603
);
604604
});
@@ -611,7 +611,7 @@ describe("sentry explore", () => {
611611
context,
612612
{
613613
...DEFAULT_FLAGS,
614-
dataset: "metricsEnhanced",
614+
dataset: "tracemetrics",
615615
metric: "llm.token_usage",
616616
field: ["gen_ai.request.model"],
617617
},
@@ -637,7 +637,7 @@ describe("sentry explore", () => {
637637
context,
638638
{
639639
...DEFAULT_FLAGS,
640-
dataset: "metricsEnhanced",
640+
dataset: "tracemetrics",
641641
metric: "cache.hit_rate",
642642
agg: "avg",
643643
},
@@ -652,7 +652,7 @@ describe("sentry explore", () => {
652652
);
653653
});
654654

655-
test("--metric without --dataset metrics auto-switches to metricsEnhanced", async () => {
655+
test("--metric without --dataset metrics auto-switches to tracemetrics", async () => {
656656
resolveTargetSpy.mockResolvedValue({ org: "test-org" });
657657
const { context } = createContext();
658658

@@ -669,7 +669,7 @@ describe("sentry explore", () => {
669669
expect(queryEventsSpy).toHaveBeenCalledWith(
670670
"test-org",
671671
expect.objectContaining({
672-
dataset: "metricsEnhanced",
672+
dataset: "tracemetrics",
673673
fields: ["sum(value,llm.token_usage,distribution,none)"],
674674
})
675675
);

test/types/dashboard.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ describe("mapWidgetTypeToDataset", () => {
950950
expect(mapWidgetTypeToDataset("error-events")).toBe("errors");
951951
expect(mapWidgetTypeToDataset("transaction-like")).toBe("transactions");
952952
expect(mapWidgetTypeToDataset("logs")).toBe("logs");
953-
expect(mapWidgetTypeToDataset("tracemetrics")).toBe("metricsEnhanced");
953+
expect(mapWidgetTypeToDataset("tracemetrics")).toBe("tracemetrics");
954954
});
955955

956956
test("returns null for unsupported widget types", () => {

0 commit comments

Comments
 (0)