Repository navigation
feat(search_events): add metrics dataset support - #899
Closed
sentry-junior[bot] wants to merge 1 commit into
Closed
sentry-junior[bot] wants to merge 1 commit into
sentry-junior[bot] wants to merge 1 commit into
Conversation
Adds the 'metrics' dataset to the search_events tool, enabling the MCP
to query Sentry's transaction performance metrics (backed by
metrics_performance / snuba's MetricsQueryBuilder).
## What changed
### search-events/config.ts
- Added 'metrics' to DATASET SELECTION GUIDELINES in systemPrompt
- Updated systemPrompt return format to include 'metrics' as valid dataset
- Added NUMERIC_FIELDS for metrics (transaction.duration, web vitals)
- Added DATASET_FIELDS['metrics'] with transaction fields, web vitals,
and all supported aggregate functions (apdex, failure_rate, tpm, epm,
p50-p99, user_misery, avg, sum, count, count_unique)
- Added DATASET_EXAMPLES['metrics'] with 5 representative query patterns
- Added RECOMMENDED_FIELDS['metrics'] with throughput and latency defaults
### search-events/agent.ts
- Extended dataset enum to include 'metrics'
### search-events/utils.ts
- Extended fetchCustomAttributes signature to accept 'metrics'
- For metrics, falls back to listing 'events' tags (transaction-level)
- Extended createDatasetAttributesTool dataset enum to include 'metrics'
### search-events/formatters.ts
- Added formatMetricsResults() following existing formatter pattern
- Metrics results are always aggregate; outputs JSON block for table rendering
### search-events/handler.ts
- Imports formatMetricsResults
- Added 'metrics' to tool description
- Added 'metrics' case to the dataset switch
### api-client/client.ts
- Extended searchEvents() dataset type to include 'metrics'
- Routes 'metrics' through buildDiscoverApiQuery (same endpoint as errors)
with dataset=metrics query param
- Extended getEventsExplorerUrl() to handle 'metrics' via buildDiscoverUrl
- Extended buildDiscoverApiQuery() and buildDiscoverUrl() to accept
optional dataset override param
### mcp-server-mocks
- Added events-metrics.json and events-metrics-empty.json fixtures
- Added metrics mock handler in the /events/ path
### search-events.test.ts
- Added test: 'should handle metrics dataset queries for transaction performance'
verifying dataset=metrics is sent to API and results are formatted correctly
## Confirmed behaviors from getsentry/sentry
- src/sentry/snuba/utils.py maps 'metrics' -> metrics_performance
- src/sentry/search/events/datasets/metrics.py confirms apdex, failure_rate,
epm, p75, p95, p99 of transaction.duration as primary aggregates
- Uses /organizations/{org}/events/ with dataset=metrics (discover-style API)
dcramer
added a commit
that referenced
this pull request
Apr 14, 2026
Route newer span metrics queries through Sentry's tracemetrics dataset instead of the older metrics attempt from PR #899. Preserve raw aggregate sort expressions, fetch tracemetrics attributes, and generate Metrics page links for aggregate and sample results. Add mocks, formatter coverage, and docs for the tracemetrics dataset so search_events and list_events surface the current-generation span metrics correctly. Co-Authored-By: Codex <codex@openai.com>
dcramer
added a commit
that referenced
this pull request
Apr 15, 2026
Add support for Sentry's current-generation span metrics in search_events and list_events. The previous attempt in #899 targeted the wrong dataset. The current Sentry path uses dataset=tracemetrics on the events endpoint, raw metric aggregate expressions such as p95(value,http.request.duration,distribution,millisecond), and Metrics page URLs under /explore/metrics/. This updates the MCP query builder, formatting, mocks, tests, generated definitions, and docs to match that behavior. This also preserves raw aggregate sort expressions for tracemetrics so grouped metric queries keep working instead of being rewritten into Discover-style aliases. --------- Co-authored-by: Codex <codex@openai.com>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the
metricsdataset to thesearch_eventsMCP tool, enabling queries against Sentry's transaction performance metrics (backed bymetrics_performancein snuba).Previously the tool only knew about
spans,errors, andlogs. This PR makes the agent aware ofmetricsso it can answer questions like:Dataset confirmed from getsentry/sentry
src/sentry/snuba/utils.pymaps"metrics" -> metrics_performancesrc/sentry/search/events/datasets/metrics.pyconfirms supported aggregates:apdex,failure_rate,epm,p50-p99(transaction.duration),user_misery.Changes
config.ts: Addedmetricsto dataset selection prompt, NUMERIC_FIELDS, DATASET_FIELDS, DATASET_EXAMPLES, RECOMMENDED_FIELDSagent.ts: Extended dataset enum to includemetricsutils.ts: Extended fetchCustomAttributes + createDatasetAttributesTool enumformatters.ts: Added formatMetricsResults()handler.ts: Addedmetricsto tool description and switchclient.ts: Routesmetricsthrough discover API with dataset=metrics; extended buildDiscoverUrl and buildDiscoverApiQuery to accept dataset overridemcp-server-mocks: New fixtures + mock handler for dataset=metricssearch-events.test.ts: New test for metrics datasetTest results
All 804 tests pass. Lint clean.