Skip to content

feat(slack): Support unfurling Explore Metrics URLs in Slack#112706

Merged
DominikB2014 merged 5 commits intomasterfrom
dominikbuszowiecki/dain-1477-unfurl-metrics-explorer-urls-in-slack
Apr 14, 2026
Merged

feat(slack): Support unfurling Explore Metrics URLs in Slack#112706
DominikB2014 merged 5 commits intomasterfrom
dominikbuszowiecki/dain-1477-unfurl-metrics-explorer-urls-in-slack

Conversation

@DominikB2014
Copy link
Copy Markdown
Contributor

Add Slack unfurl support for Explore Metrics URLs (/explore/metrics/),
alongside the existing traces and logs support.

The metrics URL structure differs from traces/logs — it uses a single metric
JSON query param with nested aggregateFields containing the yAxes, rather
than separate visualize or aggregateField params. The handler parses this
structure and uses the tracemetrics dataset for the events-timeseries API call.

Supports both /organizations/{slug}/explore/metrics/ and customer domain
{slug}.sentry.io/explore/metrics/ URL formats.

Depends on #112677

Fixes DAIN-1477

@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 10, 2026

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 10, 2026
@DominikB2014 DominikB2014 force-pushed the dominikbuszowiecki/dain-1477-unfurl-metrics-explorer-urls-in-slack branch from ce16f61 to 0407014 Compare April 10, 2026 18:35
Comment thread src/sentry/integrations/slack/unfurl/explore.py
@DominikB2014 DominikB2014 force-pushed the dominikbuszowiecki/dain-1477-unfurl-metrics-explorer-urls-in-slack branch from 0407014 to f500974 Compare April 10, 2026 18:42
@DominikB2014 DominikB2014 force-pushed the dominikbuszowiecki/dain-1477-unfurl-metrics-explorer-urls-in-slack branch from f500974 to 65d0a7d Compare April 13, 2026 16:59
@DominikB2014
Copy link
Copy Markdown
Contributor Author

@cursor review

@DominikB2014 DominikB2014 requested a review from a team April 13, 2026 17:06
Add URL matching for /explore/metrics/ paths. The metrics URL uses a
single "metric" JSON param with nested aggregateFields, unlike traces
(visualize) and logs (aggregateField). The handler extracts yAxes from
the metric param and uses the tracemetrics dataset.

Refs LINEAR-DAIN-1477
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DominikB2014 DominikB2014 force-pushed the dominikbuszowiecki/dain-1477-unfurl-metrics-explorer-urls-in-slack branch from 65d0a7d to 26b61b5 Compare April 13, 2026 17:08
@DominikB2014 DominikB2014 marked this pull request as ready for review April 13, 2026 17:10
@DominikB2014 DominikB2014 requested review from a team as code owners April 13, 2026 17:10
Comment thread tests/sentry/integrations/slack/test_unfurl.py Outdated
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.

Nice. Just one comment about the wording of how to many metrics there are for clarity

Comment thread src/sentry/integrations/slack/unfurl/explore.py Outdated
Use getlist('metric') instead of get('metric') to handle multiple
metric params in the URL. Also replace raw 'tracemetrics' strings in
tests with SupportedTraceItemType.TRACEMETRICS for consistency with
other dataset assertions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread src/sentry/integrations/slack/unfurl/explore.py Outdated
Each metric URL param is a self-contained chart config with its own
query, yAxes, groupBy, and sort. Accumulating across all metric params
would mix unrelated data and produce incorrect chart results. Since we
only render one chart per unfurl, process only the first entry.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread src/sentry/integrations/slack/unfurl/explore.py Outdated
json.loads can return non-dict values (null, number, array) which
raise AttributeError on .get() calls. Add it to the except clause
to match how the visualize parsing handles similar edge cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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 1365696. Configure here.

Comment thread src/sentry/integrations/slack/unfurl/explore.py
The metric parsing loop extracted yAxes and groupBy but omitted
chartType, causing explicitly chosen chart types to be silently
ignored for metric unfurls. Now extracts it the same way the
visualize_fields loop does.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment on lines +301 to +304
if metric_query:
query["query"] = metric_query
if metric_sort_bys:
query.setlist("sort", metric_sort_bys)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Metric parameter parsing and override logic runs for all explore URL types, not just metrics, potentially causing incorrect query and sort overrides for traces or logs URLs.
Severity: LOW

Suggested Fix

Wrap the metric query and sort override logic in a conditional check to ensure it only executes when explore_dataset is SupportedTraceItemType.TRACEMETRICS. This will prevent the overrides from being applied to non-metric URL unfurls.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry/integrations/slack/unfurl/explore.py#L301-L304

Potential issue: The function `map_explore_query_args` unconditionally parses the
`metric` query parameter and applies its internal `query` and `aggregateSortBys` values.
This logic runs for all explore URL types, including traces and logs. If a traces or
logs URL contains a `metric` parameter (e.g., through URL manipulation or a frontend
bug), the `query` and `sort` values from the URL will be incorrectly overridden by the
values from the `metric` parameter. For example, a URL's `aggregateSort` parameter would
be ignored in favor of the `aggregateSortBys` from the `metric` JSON, leading to an
incorrect unfurl.

Did we get this right? 👍 / 👎 to inform future reviews.

@DominikB2014 DominikB2014 merged commit c426029 into master Apr 14, 2026
56 checks passed
@DominikB2014 DominikB2014 deleted the dominikbuszowiecki/dain-1477-unfurl-metrics-explorer-urls-in-slack branch April 14, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants