Skip to content

feat(browser)!: Extract performance.{mark,measure} spans into new userTimingSpansIntegration - #22554

Merged
msonnb merged 12 commits into
developfrom
ms/performance-mark-measure
Jul 28, 2026
Merged

feat(browser)!: Extract performance.{mark,measure} spans into new userTimingSpansIntegration#22554
msonnb merged 12 commits into
developfrom
ms/performance-mark-measure

Conversation

@msonnb

@msonnb msonnb commented Jul 23, 2026

Copy link
Copy Markdown
Member

What?

browserTracingIntegration no longer captures performance.mark() / performance.measure() spans by default. This behavior moves into a new opt-in userTimingSpansIntegration, and the ignorePerformanceApiSpans option is replaced by the integration's ignore option.

// before
Sentry.init({
  integrations: [
    Sentry.browserTracingIntegration({ ignorePerformanceApiSpans: ['third-party-mark'] }),
  ],
});

// after
Sentry.init({
  integrations: [
    Sentry.browserTracingIntegration(),
    Sentry.userTimingSpansIntegration({ ignore: ['third-party-mark'] }),
  ],
});

Why?

User Timing spans are useful for some apps and pure noise for others (browser extensions and third-party libraries emit their own mark/measure entries). Bundling them into browserTracingIntegration meant everyone paid the bundle-size and span-volume cost whether they wanted the data or not, and the only escape hatch was an ignore-list. Making it a separate, explicitly-added integration means you opt in when you want it, and it drops out of the tree-shaken bundle when you don't.

Closes #22352

@msonnb

msonnb commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

bugbot run

Comment thread packages/browser-utils/src/metrics/userTimingSpans.ts Outdated
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.84 kB - -
@sentry/browser - with treeshaking flags 28.05 kB - -
@sentry/browser (incl. Tracing) 47.12 kB -0.62% -290 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 47.13 kB -0.62% -292 B 🔽
@sentry/browser (incl. Tracing, Profiling) 51.83 kB -0.61% -318 B 🔽
@sentry/browser (incl. Tracing, Replay) 86.43 kB -0.36% -311 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.86 kB -0.39% -291 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 91.15 kB -0.36% -323 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 103.79 kB -0.31% -313 B 🔽
@sentry/browser (incl. Feedback) 47.15 kB - -
@sentry/browser (incl. sendFeedback) 34.68 kB - -
@sentry/browser (incl. FeedbackAsync) 39.78 kB +0.03% +8 B 🔺
@sentry/browser (incl. Metrics) 30.91 kB - -
@sentry/browser (incl. Logs) 31.14 kB - -
@sentry/browser (incl. Metrics & Logs) 31.82 kB - -
@sentry/react 31.63 kB - -
@sentry/react (incl. Tracing) 49.35 kB -0.57% -282 B 🔽
@sentry/vue 34.76 kB - -
@sentry/vue (incl. Tracing) 49.08 kB -0.59% -288 B 🔽
@sentry/svelte 29.87 kB - -
CDN Bundle 31.89 kB +0.02% +5 B 🔺
CDN Bundle (incl. Tracing) 47.47 kB -0.62% -293 B 🔽
CDN Bundle (incl. Logs, Metrics) 33.44 kB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 48.84 kB -0.6% -293 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 72.8 kB +0.01% +6 B 🔺
CDN Bundle (incl. Tracing, Replay) 85.11 kB -0.34% -287 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.4 kB -0.32% -273 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 90.87 kB -0.32% -289 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.19 kB -0.3% -277 B 🔽
CDN Bundle - uncompressed 95.11 kB +0.03% +24 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 142.33 kB -0.63% -897 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.82 kB +0.03% +24 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.31 kB -0.61% -897 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.58 kB +0.02% +24 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 261.58 kB -0.35% -897 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 265.55 kB -0.34% -897 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.29 kB -0.33% -897 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.24 kB -0.33% -897 B 🔽
@sentry/nextjs (client) 51.94 kB -0.54% -282 B 🔽
@sentry/sveltekit (client) 47.54 kB -0.62% -293 B 🔽
@sentry/core/server 79.78 kB +0.02% +10 B 🔺
@sentry/core/browser 51.61 kB +0.02% +9 B 🔺
@sentry/node 121.06 kB +0.01% +1 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 166 B - -
@sentry/node - without tracing 84.48 kB +0.01% +1 B 🔺
@sentry/aws-serverless 92.7 kB +0.01% +1 B 🔺
@sentry/cloudflare (withSentry) - minified 197.51 kB - -
@sentry/cloudflare (withSentry) 485.76 kB - -

View base workflow run

@msonnb
msonnb marked this pull request as ready for review July 24, 2026 06:45
@msonnb
msonnb requested a review from a team as a code owner July 24, 2026 06:45
@msonnb
msonnb requested review from Lms24 and logaretm and removed request for a team July 24, 2026 06:45
Comment thread packages/browser-utils/src/metrics/userTiming.ts
@msonnb
msonnb marked this pull request as draft July 24, 2026 07:15
@msonnb
msonnb marked this pull request as ready for review July 24, 2026 08:29
@msonnb
msonnb force-pushed the ms/performance-mark-measure branch from 06b5536 to f28a18c Compare July 24, 2026 14:14
Comment thread packages/browser-utils/src/metrics/userTiming.ts

@logaretm logaretm left a comment

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.

Minor stuff, proposing a rename and maybe an opportunity to align the origin with similar origins in the SDK.

Comment thread packages/browser-utils/src/metrics/userTiming.ts
const spanEndTimestamp = originalStartTimestamp + duration;

const attributes: SpanAttributes = {
[SENTRY_ORIGIN]: 'auto.resource.browser.metrics',

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.

l: Maybe we should have a better descriptive origin here, I know this is just an extraction PR but could be a good opportunity to do that? Unless product relies on this specific value. cc @Lms24

Since origins are supposed to inform the user which part of the SDK created this telemetry we could use: auto.browser.performance_timing or similar. What do you think?

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.

yup, agreed. Whatever name we settle on, we should reflect it in the origin. See: https://develop.sentry.dev/sdk/telemetry/traces/trace-origin/

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.

Then auto.browser.user_timing.{mark/measure}? or just auto.browser.user_timing?

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.

went for the more fine-grained auto.browser.user_timing.{mark|measure}

@Lms24 Lms24 left a comment

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.

One more suggestion: WDYT about removing setting the sentry-tracing-init mark? Feels like we're not better than some other libraries/scripts that emit their own marks into users' timelines.

The purpose of this mark was to know when the SDK initializes in comparison to the relative timestamps. With this integration only being optional, we loose the generated span in 99% of cases. I'd vote we remove it and - if it turns out this information would be good to have - we add back a 0-duration span instead.

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.

suggestion: wdyt about pulling all the usertiming tests out of the /metrics sub directory? Given this is now an integration, it could just live under tracing.

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.

+1 I think the browser metrics is a bloated term right now

Comment on lines +75 to +76
addPerformanceInstrumentationHandler('mark', handleEntries);
addPerformanceInstrumentationHandler('measure', handleEntries);

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.

we talked about the approach change compared to the browserTracing implementation offline.
We might miss certain emissions with the listener approach here as opposed to peformance.getEntries() that we previously caught (two scenarios: entries happening before Sentry.init, or right before the idle span ends).

Let's check if we can use the getEntries approach here easily (without cursor conflicts in browserTracing). If we can, I'd rather prefer this. We likely need another client hook (something like segmentSpanEnd that fires before afterSegmentSpanEnd, but feel free to come up with whatever makes sense here).

If it turns out there are issues with the getEntries approach, we can also stick with this approach.

@msonnb msonnb Jul 28, 2026

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.

i went with a beforeIdleSpanEnd hook in 88d45ad that runs before the idle span's ending logic, since (for now at least) there seem to be no other use cases for a beforeSegmentSpanEnd hook and it avoids deduplication logic.

we could now also remove—either here or in a follow up—the local idle span beforeSpanEnd callback in favor of this hook (it's only other usage is in browserTracingIntegration)

@msonnb
msonnb force-pushed the ms/performance-mark-measure branch from f28a18c to df7f7ce Compare July 28, 2026 09:00

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 df7f7ce. Configure here.

Comment thread packages/browser-utils/src/metrics/userTiming.ts Outdated
Comment thread packages/browser-utils/src/metrics/userTiming.ts

@Lms24 Lms24 left a comment

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.

One more request: Let's exclude this integration from the SDK CDN bundles. If we remove it from browserTracing and make it opt-in for SDKs in NPM, we might as well spare bundle users the bundle size.

Instead, should make it a pluggable integration (see CDN tab) that also ships its own CDN bundle, which users can register in addition to the main SDK bundle.

If you prefer, we can also tackle adding the CDN bundle in a follow-up. Happy to leave that up to you! But we should remove the integration from the SDK bundle in this one.

Comment thread packages/browser-utils/src/metrics/userTiming.ts
@msonnb

msonnb commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

One more request: Let's exclude this integration from the SDK CDN bundles. If we remove it from browserTracing and make it opt-in for SDKs in NPM, we might as well spare bundle users the bundle size.

Instead, should make it a pluggable integration (see CDN tab) that also ships its own CDN bundle, which users can register in addition to the main SDK bundle.

If you prefer, we can also tackle adding the CDN bundle in a follow-up. Happy to leave that up to you! But we should remove the integration from the SDK bundle in this one.

both done in 0b4721e and 8f7fa80 👍

@Lms24 Lms24 left a comment

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.

Nice, thanks for reworking the approach and handling the CDN integration bundle!

LGTM now! Last optional change: I think we can move the two remaining integration tests out of the /metrics sub dir and potentially group all user timing tests under /tracing/user-timing/*.

Good to go from my end, feel free to merge!

@msonnb
msonnb enabled auto-merge (squash) July 28, 2026 15:25
@msonnb
msonnb merged commit 48afe12 into develop Jul 28, 2026
524 of 528 checks passed
@msonnb
msonnb deleted the ms/performance-mark-measure branch July 28, 2026 15:51
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.

Stop emitting browser mark and measure spans by default

3 participants