Skip to content

feat(cross-events): Support metric cross event querying#113703

Merged
nsdeschenes merged 17 commits intomasterfrom
nd/EXP-895/feat-cross-events-enable-metric-cross-event-querying
Apr 24, 2026
Merged

feat(cross-events): Support metric cross event querying#113703
nsdeschenes merged 17 commits intomasterfrom
nd/EXP-895/feat-cross-events-enable-metric-cross-event-querying

Conversation

@nsdeschenes
Copy link
Copy Markdown
Contributor

@nsdeschenes nsdeschenes commented Apr 22, 2026

This PR adds in support for cross-event querying with the metrics dataset. As well, taken the time to move the cross-event stuff into it's own directory and files, as it was starting to balloon the size of the spans tab search section file.

Closes EXP-895

Example:

Screenshot 2026-04-23 at 10 37 36

nsdeschenes and others added 2 commits April 22, 2026 14:42
Let users pick Metrics as a third cross-event type in the Spans
explorer alongside Spans and Logs. Metrics rows render the existing
MetricSelector inline next to a search bar whose attributes are
scoped to the selected metric via createTraceMetricFilter, so users
see only attributes that co-occur with that metric.

The CrossEvent shape becomes a discriminated union so metrics rows
carry the selected TraceMetric (name, type, unit). useCrossEventQueries
builds a metricQuery array that prepends metric.name, metric.type, and
metric.unit (when present) onto the user's filter string, guaranteeing
the identity fields reach the backend on every request. The backend
metricQuery param is already accepted by useTraces, useExploreTracesTable
and useProgressiveQuery.

Refs EXP-895
Co-Authored-By: Claude <noreply@anthropic.com>
Emit cross_event_metric_query_count alongside the existing log and
span counters on trace.explorer.metadata so dashboards can see how
often the new metrics cross-event type is used.

Refs EXP-895
Co-Authored-By: Claude <noreply@anthropic.com>
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Apr 22, 2026

@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 22, 2026
Two related robustness fixes for the metrics cross-event flow:

- Guard `useCrossEventQueries` on `isCompleteTraceMetric(metric)` so a
  metric entry with an empty `type` no longer emits a malformed
  `metric.type:` filter. Previously only `metric.name` was checked.
- In `getCrossEventsFromLocation`, filter malformed entries instead of
  rejecting the whole array, so one bad entry can't drop sibling
  span/log cross-events.

Also adds `isCompleteTraceMetric` alongside `isEmptyTraceMetric` to make
the "complete enough to query" contract explicit for future consumers.
Pass the selected metric name as a namespace to the cross-event metrics
search query builder so `/recent-searches/` results are scoped to the
active metric. Disable the search query builder until a metric is
selected since recent searches require a namespace, and remount the
provider on metric change to avoid stale state.
Comment thread static/app/views/explore/hooks/useCrossEventQueries.spec.tsx Outdated
Move the cross event querying dropdown and cross event search bar
components out of spansTabSearchSection.tsx and into a dedicated
static/app/views/explore/spans/crossEvents/ directory. No behavior
change.
Group the metric.name, metric.type, and metric.unit filters for metric
cross-event queries in parentheses and append the user-provided query as
free text. This keeps the metric identity constraints intact when the
user query contains boolean operators that would otherwise bind to a
single filter.
Comment thread static/app/views/explore/hooks/useCrossEventQueries.tsx Outdated
nsdeschenes and others added 3 commits April 23, 2026 10:39
Knip flagged EMPTY_TRACE_METRIC as an unused export. It is only used
within the same module, so drop the export keyword.

Co-Authored-By: Claude <noreply@anthropic.com>
Replace the static crossEventDropdownItems constant with a
getCrossEventDropdownItems() helper so the item list can vary per
caller. No behavior change.

Co-Authored-By: Claude <noreply@anthropic.com>
…cess

Only show the Metrics option in the cross-event dropdown when the
organization has access to the trace metrics UI (canUseMetricsUI).

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread static/app/views/explore/spans/crossEvents/crossEventSearchBars.tsx Outdated
…rics access

The dataset CompactSelect in SpansTabCrossEventSearchBars hard-coded the
metrics option, letting users without the tracemetrics-enabled feature
switch an existing cross event to metrics and bypass the feature gate
applied to the add-dropdown. Route the dataset options through a
getCrossEventDatasetOptions helper that applies the same
canUseMetricsUI check.

Co-Authored-By: Claude <noreply@anthropic.com>
@nsdeschenes nsdeschenes marked this pull request as ready for review April 23, 2026 14:05
@nsdeschenes nsdeschenes requested review from a team as code owners April 23, 2026 14:05
Copy link
Copy Markdown
Member

@narsaynorath narsaynorath left a comment

Choose a reason for hiding this comment

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

Just a small update to use another helper, but otherwise lgtm 👍

Comment thread static/app/views/explore/hooks/useCrossEventQueries.tsx Outdated
Relocate the helper from the dashboards widget hook into
`views/explore/metrics/utils` so it can be shared by other explore
consumers without pulling a dependency on dashboards code.
…ric queries

Replace the inline metric identity filter logic in `useCrossEventQueries`
with the shared `createTraceMetricEventsFilter` helper so the unit-less
metric case is handled consistently (matching both `!has:metric.unit`
and `metric.unit:none`).
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.

Reviewed by Cursor Bugbot for commit 5a3918b. Configure here.

Comment thread static/app/views/explore/hooks/useCrossEventQueries.tsx Outdated
…ss-events-enable-metric-cross-event-querying

# Conflicts:
#	static/app/views/explore/metrics/metricGraph/index.tsx
#	static/app/views/explore/metrics/utils.tsx
…t search

addFreeText coerces its argument into a single FREE_TEXT token, which
formatString then wraps in quotes whenever the value contains spaces.
A user query like 'env:prod status:ok' was being serialized as a single
quoted free-text search instead of two ANDed filters.

Concatenate the identity filter and the user query as strings so the
backend receives each filter as its own token.
Comment thread static/app/views/explore/metrics/utils.tsx
@nsdeschenes nsdeschenes merged commit 0929e91 into master Apr 24, 2026
65 checks passed
@nsdeschenes nsdeschenes deleted the nd/EXP-895/feat-cross-events-enable-metric-cross-event-querying branch April 24, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants