Skip to content

feat(browser): Track measure detail as span attributes #16240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 15, 2025

Conversation

AbhiPrasad
Copy link
Member

resolves #16237

The SDK automatically instruments the performance.measure API, but doesn't support detail, which is the way you can attach arbitrary data to performance.measure. Given you can see details in browser dev-tools, we should probably support it in the same way in Sentry.

https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure

detail docs: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceMeasure/detail

Detail is completely arbitrary, so we have to take care before parsing it. I have added tests accordingly.

@AbhiPrasad AbhiPrasad requested a review from a team May 8, 2025 23:56
@AbhiPrasad AbhiPrasad self-assigned this May 8, 2025
@AbhiPrasad AbhiPrasad requested review from mydea and andreiborza and removed request for a team May 8, 2025 23:56
Copy link

codecov bot commented May 9, 2025

❌ We are unable to process any of the uploaded JUnit XML files. Please ensure your files are in the right format.

Copy link
Contributor

github-actions bot commented May 9, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.98 kB - -
@sentry/browser - with treeshaking flags 23.64 kB - -
@sentry/browser (incl. Tracing) 38.39 kB +0.25% +94 B 🔺
@sentry/browser (incl. Tracing, Replay) 76.52 kB +0.12% +91 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.55 kB +0.14% +92 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 81.29 kB +0.11% +89 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 93.39 kB +0.11% +101 B 🔺
@sentry/browser (incl. Feedback) 40.78 kB - -
@sentry/browser (incl. sendFeedback) 28.72 kB - -
@sentry/browser (incl. FeedbackAsync) 33.6 kB - -
@sentry/react 25.8 kB - -
@sentry/react (incl. Tracing) 40.41 kB +0.23% +92 B 🔺
@sentry/vue 28.38 kB - -
@sentry/vue (incl. Tracing) 40.22 kB +0.26% +102 B 🔺
@sentry/svelte 24.02 kB - -
CDN Bundle 25.19 kB - -
CDN Bundle (incl. Tracing) 38.47 kB +0.4% +152 B 🔺
CDN Bundle (incl. Tracing, Replay) 74.26 kB +0.1% +68 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 79.7 kB +0.12% +91 B 🔺
CDN Bundle - uncompressed 73.55 kB - -
CDN Bundle (incl. Tracing) - uncompressed 113.95 kB +0.33% +367 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 227.92 kB +0.17% +367 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 240.75 kB +0.16% +367 B 🔺
@sentry/nextjs (client) 42.04 kB +0.22% +91 B 🔺
@sentry/sveltekit (client) 38.89 kB +0.25% +95 B 🔺
@sentry/node 158 kB -0.01% -2 B 🔽
@sentry/node - without tracing 97.9 kB - -
@sentry/aws-serverless 123.24 kB - -

View base workflow run

attributes[`sentry.browser.measure.detail.${key}`] = value as SpanAttributeValue;
} else {
try {
// This is user defined so we can't guarantee it's serializable
Copy link
Member

Choose a reason for hiding this comment

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

l: Can we instead just wrap the whole block inside of if (entry.detail) in a try-catch, maybe slightly less redundant?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we wrap everything in try catch it means we stop iterating through Object.entries(entry.detail), which means some valid attributes might not get serialized properly.

// https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure#detail
if (entry.detail) {
// Handle detail as an object
if (typeof entry.detail === 'object') {
Copy link

Choose a reason for hiding this comment

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

I would also ask to support arrays of primitives, here and as object props 🙏

Listing some things in spans is very useful, and SpanAttributeValue supports this.

Copy link
Member Author

Choose a reason for hiding this comment

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

We'll still handle this via serializing to JSON, so you'll get this in the UI. I'd rather not pay the bundle size cost of the extra array processing logic.

@AbhiPrasad AbhiPrasad enabled auto-merge (squash) May 14, 2025 23:19
@AbhiPrasad AbhiPrasad closed this May 14, 2025
auto-merge was automatically disabled May 14, 2025 23:50

Pull request was closed

@AbhiPrasad AbhiPrasad reopened this May 14, 2025
@AbhiPrasad AbhiPrasad merged commit fcdc4d7 into develop May 15, 2025
122 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-performance-measure-detail branch May 15, 2025 00:58
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.

Enrich attributes of Spans created from PerformanceMeasure events
3 participants