Skip to content

fix(insights): Handle null span.group in Backend Insights widgets#112379

Merged
gggritso merged 5 commits intomasterfrom
georgegritsouk/dain-1467-backend-insights-crashes-and-does-not-render-fully-on
Apr 10, 2026
Merged

fix(insights): Handle null span.group in Backend Insights widgets#112379
gggritso merged 5 commits intomasterfrom
georgegritsouk/dain-1467-backend-insights-crashes-and-does-not-render-fully-on

Conversation

@gggritso
Copy link
Copy Markdown
Member

@gggritso gggritso commented Apr 7, 2026

A self-hosted user complained in getsentry/self-hosted#4262 that their Backend Insights view breaks when ingesting Otel data. This PR adds some guards to prevent this crash, but it doesn't necessarily guarantee a great experience, e.g.,

  • "Backend Insights" is on its way out, to be replaced with a pre-built dashboard. This hasn't been rolled out to self-hosted yet, so this user will have a somewhat different experience in the next few months if they upgrade
  • OTel data should go through Sentry enrichment, and get a span.group attribute, but decisions around OTel are changing! We might do less enrichment (or different enrichment) there

In the meantime, this PR makes two changes

  • asks for has:span.group to be present in a few widgets. This is a common pattern for us, and should work here, too
  • updates the types for the span.group property to mark it as possibly null and updates a bunch of usage

Fixes DAIN-1467

gggritso added 2 commits April 7, 2026 13:09
Widgets that query for span.group can receive null values from the
backend for OpenTelemetry-ingested spans, causing the page to crash.
Add has:span.group to the search queries in overviewTimeConsumingQueriesWidget
and overviewSlowNextjsSSRWidget, matching the pattern already used by
overviewSlowAssetsWidget and overviewSlowQueriesChartWidget.

Fixes DAIN-1467
Move SPAN_GROUP from NonNullableStringFields to NullableStringFields,
reflecting the reality that OpenTelemetry-ingested spans can have null
span.group values. This makes SpanResponse['span.group'] resolve to
string | null, letting TypeScript catch unsafe usages.

Fix all surfaced type errors by updating prop types to accept null and
adding null coalescing where values are passed to MutableSearch.
@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 7, 2026

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 7, 2026
@gggritso gggritso marked this pull request as ready for review April 7, 2026 19:24
@gggritso gggritso requested review from a team as code owners April 7, 2026 19:25
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.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Null group interpolated into navigation URL path
    • Added a guard in QueryClippedBox so the click handler returns early when group is null/undefined instead of navigating to a malformed span URL.

Create PR

Or push these changes by commenting:

@cursor push 00baa7392a
Preview (00baa7392a)
diff --git a/static/app/views/insights/common/components/fullSpanDescription.tsx b/static/app/views/insights/common/components/fullSpanDescription.tsx
--- a/static/app/views/insights/common/components/fullSpanDescription.tsx
+++ b/static/app/views/insights/common/components/fullSpanDescription.tsx
@@ -121,11 +121,16 @@
       clipHeight={500}
       buttonProps={{
         icon: <IconOpen />,
-        onClick: () =>
+        onClick: () => {
+          if (!group) {
+            return;
+          }
+
           navigate({
             pathname: `${databaseURL}/spans/span/${group}`,
             query: {...location.query, isExpanded: true},
-          }),
+          });
+        },
       }}
     >
       {children}

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Comment thread static/app/views/insights/common/components/fullSpanDescription.tsx
Don't show "View full query" link in QueryClippedBox when group is
null — navigating to /spans/span/null is not useful.
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 d011829. Configure here.

row.group can be null, so using it alone as a React key would cause
duplicate keys. Use group + operation + index as a composite key.
Copy link
Copy Markdown
Contributor

@nsdeschenes nsdeschenes left a comment

Choose a reason for hiding this comment

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

Just one small nit/question, all looks good tho 😄

const {query} = useTransactionNameQuery();

const fullQuery = `span.op:function.nextjs ${query}`;
const fullQuery = `has:span.group span.op:function.nextjs ${query}`;
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.

nit: Looking at .../widgets/overviewTimeConsumingQueriesWidget.tsx, you're using an enum value (has:${SpanFields.SPAN_GROUP}) whereas here you're using a raw string.

Is one better/preferred than the other?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's better to use the enum values because that makes it easier to find all usages of a specific attribute, but I always forget to do that! I can update

Use SpanFields.SPAN_GROUP and SpanFields.SPAN_OP instead of raw
strings in overviewSlowNextjsSSRWidget for consistency and to make
field usages easier to find via search.
@gggritso gggritso merged commit 5dc4ee4 into master Apr 10, 2026
61 of 62 checks passed
@gggritso gggritso deleted the georgegritsouk/dain-1467-backend-insights-crashes-and-does-not-render-fully-on branch April 10, 2026 15:57
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