Skip to content

ref: Pass optional span attributes directly instead of conditional spreads - #25878

Merged
mydea merged 2 commits into
developfrom
ref/inline-optional-span-attributes
Oct 30, 2026
Merged

mydea merged 2 commits into
developfrom
ref/inline-optional-span-attributes

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Why: SentrySpan.setAttribute drops undefined values, and SpanAttributes already allows undefined. That makes patterns like ...(provider ? { [GEN_AI_PROVIDER_NAME]: provider } : {}) unnecessary when the attributes are passed at span creation, so this passes the value directly. It also trims the browser bundle a little.

I only changed attribute objects passed when a span is created, where the condition just checks the value itself. I left these alone on purpose:

  • setAttributes on spans that already exist. There, undefined deletes the attribute (for example the nextjs/ember/tanstack route updates and the MCP initialize update).
  • sentry.op / sentry.origin / sentry.segment.name.source. An explicit undefined overrides the core defaults (the effect tracer already has a comment about this).
  • Values typed string | null (sveltekit route.id). null is not a valid attribute value.
  • Ember route names and Angular decorator component names, where '' is a real case that should stay omitted. Ember has tests for this.
  • Non-attribute objects (envelope headers, HTTP headers, MCP helpers typed Record<string, string | number>) and conditions on something other than the value, like hasSpanStreaming, recordInputs or source === 'route'.

Unsure about: a falsy check like x ? {…} : {} also skipped ''. Now an empty string would be set as an attribute. I don't think that can happen at the sites I changed, but it's worth a quick look.

via Francesco Gringl-Novy.

--

View Junior Session [Sentry]

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 06eb2d3 (PR test merge using develop at 365e761)

Against: 365e761 (develop) · base run #64341

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.39 kB - -
@sentry/browser - with treeshaking flags 28.53 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.42 kB - -
@sentry/browser (incl. Tracing) 52.7 kB -0.02% -8 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 52.71 kB -0.02% -6 B 🔽
@sentry/browser (incl. Tracing, Profiling) 55.68 kB -0.02% -6 B 🔽
@sentry/browser (incl. Tracing, Replay) 93.01 kB -0.01% -4 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.6 kB -0.01% -3 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 97.75 kB -0.01% -6 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 110.74 kB -0.01% -6 B 🔽
@sentry/browser (incl. Feedback) 47.97 kB - -
@sentry/browser (incl. sendFeedback) 35.49 kB - -
@sentry/browser (incl. FeedbackAsync) 40.6 kB - -
@sentry/browser (incl. Metrics) 31.42 kB - -
@sentry/browser (incl. Logs) 31.72 kB - -
@sentry/browser (incl. Metrics & Logs) 32.44 kB - -
@sentry/react 32.27 kB - -
@sentry/react (incl. Tracing) 55.07 kB -0.01% -5 B 🔽
@sentry/vue 38.66 kB -0.01% -1 B 🔽
@sentry/vue (incl. Tracing) 55.72 kB -0.02% -9 B 🔽
@sentry/svelte 30.42 kB - -
@sentry/remix (Remix 3 client bundle) 57.79 kB -0.02% -11 B 🔽
CDN Bundle 32.18 kB - -
CDN Bundle (incl. Tracing) 53.23 kB -0.01% -3 B 🔽
CDN Bundle (incl. Logs, Metrics) 34.45 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.17 kB -0.01% -3 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 75.86 kB - -
CDN Bundle (incl. Tracing, Replay) 91.44 kB -0.01% -2 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.38 kB -0.01% -2 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 97.56 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.55 kB -0.01% -3 B 🔽
CDN Bundle - uncompressed 94.62 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.58 kB -0.02% -17 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.09 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.31 kB -0.02% -17 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.65 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 279.27 kB -0.01% -17 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 284.99 kB -0.01% -17 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 292.97 kB -0.01% -17 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.69 kB -0.01% -17 B 🔽
@sentry/nextjs (client) 57.87 kB -0.03% -17 B 🔽
@sentry/sveltekit (client) 53.22 kB -0.01% -5 B 🔽
@sentry/core/server 44.24 kB - -
@sentry/core/browser 13.93 kB - -
@sentry/node 154.91 kB -0.06% -87 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.08 kB - -
@sentry/node - without tracing 96.23 kB +0.02% +13 B 🔺
@sentry/node - without channel injection 135.32 kB -0.08% -101 B 🔽
@sentry/aws-serverless 104.42 kB +0.02% +17 B 🔺
@sentry/cloudflare (withSentry) - minified 197.89 kB -0.02% -34 B 🔽
@sentry/cloudflare (withSentry) 491.86 kB -0.02% -66 B 🔽
@sentry/nextjs/cloudflare (withSentry) - minified 218.31 kB -0.02% -34 B 🔽

View base workflow run

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 2 not successful, 55 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E node-anthropic-send-to-sentry (latest) Test (optional) Failing after 3m Details
❌ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Failing after 2m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E node-eve Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 25s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 28s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 17s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 28s Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 50s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 24s Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 30s Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-send-to-sentry (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 17s Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E node-anthropic-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 24s Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 16s Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 47s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 25s Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 58s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 21s Details

@mydea mydea self-assigned this Oct 30, 2026
…reads

Span attributes that are undefined are dropped when the span is created,
so wrapping them in conditional spreads is unnecessary.

Co-Authored-By: Francesco Gringl-Novy <francesco.novy@sentry.io>
@sentry-junior
sentry-junior Bot force-pushed the ref/inline-optional-span-attributes branch from 81c531f to 29a5eea Compare October 30, 2026 10:22
@mydea
mydea marked this pull request as ready for review October 30, 2026 10:25
@mydea
mydea requested review from a team as code owners October 30, 2026 10:25
@mydea
mydea requested review from andreiborza, chargome, isaacs, logaretm, msonnb and nicohrubec and removed request for a team October 30, 2026 10:25
// No conventional attribute for this; it is the only way to tell a compaction turn from a
// user-facing one.
...(observation.purpose ? { 'flue.turn.purpose': observation.purpose } : {}),
'flue.turn.purpose': observation.purpose,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unrelated, but i guess we should add this to conventions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah, worth looking into. may remove/change this here: #25869

Comment thread packages/react/src/profiler.tsx Resolved
Comment thread packages/svelte/src/performance.ts Resolved
Comment thread packages/vue/src/tracing.ts Resolved
@mydea
mydea merged commit b0560b7 into develop Oct 30, 2026
392 of 394 checks passed
@mydea
mydea deleted the ref/inline-optional-span-attributes branch October 30, 2026 11:06
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.

2 participants