Skip to content

docs: add tracemetrics dataset guidance and validate aggregate format#636

Merged
BYK merged 9 commits intomainfrom
docs/tracemetrics-guidance
Apr 2, 2026
Merged

docs: add tracemetrics dataset guidance and validate aggregate format#636
BYK merged 9 commits intomainfrom
docs/tracemetrics-guidance

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 2, 2026

Summary

  • Add comprehensive documentation for the tracemetrics dataset to prevent future agents from using the wrong query format
  • Add validateAggregateNames() guard that rejects span-style aggregates when --dataset tracemetrics is used
  • Document common dashboard widget mistakes in agent guidance

Context

While building the CLI Performance dashboard, several mistakes were made with custom metrics widgets that could have been prevented with better docs and validation:

  1. Used --dataset metrics with MRI format (d:custom/name@unit) instead of --dataset tracemetrics with comma-separated format (aggregation(value,name,type,unit)) — SDK v10+ emits trace_metric items, not standalone custom metrics
  2. Wrong MRI unit suffixes (e.g., @millisecond when SDK emits with no unit → @none) — caused "Internal Error" on every metrics widget
  3. Missing --limit on grouped widgets — API rejects grouped queries without limit
  4. --sort referencing fields not in --query — caused 400 errors (e.g., sorting by count() after removing it from aggregates)
  5. Tried to aggregate span attributes (avg:dsn.files_collected) — span attributes are metadata, not aggregatable measurements

Changes

File Change
docs/src/content/docs/agent-guidance.md Dataset selection guide, tracemetrics format table with examples, common dashboard widget mistakes
src/types/dashboard.ts isTracemetricsAggregate() validator + tracemetrics branch in validateAggregateNames()
AGENTS.md Lore entry documenting tracemetrics gotchas
plugins/sentry-cli/skills/sentry-cli/SKILL.md Auto-regenerated

Add comprehensive documentation for the tracemetrics dataset:
- Agent guidance with query format, parameter table, and examples
- Common dashboard widget mistakes section
- AGENTS.md lore entry for tracemetrics gotchas

Add validation in validateAggregateNames() that rejects span-style
aggregates (e.g., count(), p50(span.duration)) when --dataset
tracemetrics is used, with a helpful error message showing the
correct comma-separated format: aggregation(value,name,type,unit).

Key lessons encoded:
- tracemetrics uses aggregation(value,metric_name,metric_type,unit)
  NOT the MRI format d:custom/name@unit used by the metrics dataset
- The unit must match what the SDK emits (none if unspecified)
- --group-by always requires --limit
- --sort must reference a field present in --query
- Span attributes cannot be used as aggregate fields
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Telemetry

  • Add performance instrumentation and CLI Performance dashboard by BYK in #625
  • Upgrade Sentry SDK to 10.47.0 and enable runtime metrics by BYK in #622

Other

  • (auth) Show token expiry in days/weeks instead of raw hours by BYK in #620
  • (ci) Add delta patch generation for stable releases by BYK in #618
  • (dashboard) Render text widget markdown content in dashboard view by BYK in #624
  • (traces) Expose custom span attributes and improve agent guidance by BYK in #623
  • Improve unknown command UX with aliases, default routing, and suggestions by BYK in #635

Bug Fixes 🐛

Telemetry

  • Exclude OutputError from Sentry exception capture (CLI-PK) by BYK in #629
  • Derive environment from CLI_VERSION instead of NODE_ENV by BYK in #627

Other

  • (build) Use esbuild for binary bundling to fix minifier collision bug by BYK in #619
  • (ci) Restore GH_TOKEN for gh CLI steps in generate-patches by BYK in #634
  • (init) Prompt for team selection when user belongs to multiple teams by betegon in #621
  • (upgrade) Remove "What's new" header from changelog output by BYK in #626

Documentation 📚

  • Add tracemetrics dataset guidance and validate aggregate format by BYK in #636

Internal Changes 🔧

  • (deps) Upgrade @sentry/api from 0.54.0 to 0.94.0 by BYK in #630
  • Remove stale debug-level stderr assertions and fix logger state leak by BYK in #631
  • Regenerate skill files and command docs by github-actions[bot] in e01b2520

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/pr-preview/pr-636/

Built to branch gh-pages at 2026-04-02 09:42 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Codecov Results 📊

129 passed | Total: 129 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 85.71%. Project has 1353 uncovered lines.
❌ Project coverage is 95.54%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/types/dashboard.ts 16.67% ⚠️ 15 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    95.56%    95.54%    -0.02%
==========================================
  Files          205       205         —
  Lines        30270     30352       +82
  Branches         0         0         —
==========================================
+ Hits         28928     28999       +71
- Misses        1342      1353       +11
- Partials         0         0         —

Generated by Codecov Action

BYK and others added 5 commits April 2, 2026 08:52
…guidance to widget help

Remove the legacy 'metrics' dataset (MRI-based, d:custom/name@unit)
from WIDGET_TYPES, DATASET_SUPPORTED_DISPLAY_TYPES, widget help text,
agent guidance, and tests. The 'tracemetrics' dataset with its
comma-separated format is the correct choice for SDK v10+ custom
metrics.

Move dataset descriptions and tracemetrics query format docs into
the widget command's fullDescription so both humans and agents see
it via 'sentry dashboard widget --help'.
…rences --query

Add client-side validation that catches two common API errors early:

1. validateGroupByRequiresLimit: Widgets with --group-by must include
   --limit. The Sentry API rejects grouped widgets without a limit.
   Only fires for explicit --group-by, not auto-defaulted columns
   (e.g., issue dataset auto-defaults columns to ['issue']).

2. validateSortReferencesAggregate: The --sort expression must reference
   an aggregate present in --query. Prevents 400 errors from the API
   when sort references a field not in the widget's aggregates.

Both validations run in the add path (buildWidgetFromFlags) and edit
path (validateQueryConstraints), with the edit path only checking when
the user actively changes query/group-by/sort flags.
…elds

Add warnUnknownAggregateFields() that logs a warning when an aggregate
field doesn't match known aggregatable span fields (span.duration,
span.self_time, http.*, cache.* measurements). Span attributes like
dsn.files_collected or resolve.method are key-value metadata that
cannot be aggregated — they should be used in --where or --group-by.

Uses a warning (not error) because measurements are project-specific
and the known-good list may not be exhaustive.
- Fix validateQueryConstraints false positive: only check group-by+limit
  when user explicitly passes --group-by, not when merely changing --query
  on an existing grouped widget (which may have auto-defaulted columns)
- Fix orphaned JSDoc: move buildWidgetFromFlags doc comment to its
  actual function definition after the validation helpers were inserted
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

…fields

Functions like count_unique(transaction) and any(span.op) accept
non-numeric columns and should not trigger the span-attribute warning.
Only numeric aggregates (avg, sum, p50-p100, min, max, percentile)
require measurement fields.
@BYK BYK merged commit e378841 into main Apr 2, 2026
27 checks passed
@BYK BYK deleted the docs/tracemetrics-guidance branch April 2, 2026 10:30
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.

1 participant