-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Changes from all commits
a414c4c
fbd9dbe
a4ce1cd
1023352
2b0037d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
/* eslint-disable max-lines */ | ||
import type { Measurements, Span, SpanAttributes, StartSpanOptions } from '@sentry/core'; | ||
import type { Measurements, Span, SpanAttributes, SpanAttributeValue, StartSpanOptions } from '@sentry/core'; | ||
import { | ||
browserPerformanceTimeOrigin, | ||
getActiveSpan, | ||
getComponentName, | ||
htmlTreeAsString, | ||
isPrimitive, | ||
parseUrl, | ||
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, | ||
setMeasurement, | ||
|
@@ -339,7 +340,7 @@ export function addPerformanceEntries(span: Span, options: AddPerformanceEntries | |
case 'mark': | ||
case 'paint': | ||
case 'measure': { | ||
_addMeasureSpans(span, entry, startTime, duration, timeOrigin); | ||
_addMeasureSpans(span, entry as PerformanceMeasure, startTime, duration, timeOrigin); | ||
|
||
// capture web vitals | ||
const firstHidden = getVisibilityWatcher(); | ||
|
@@ -421,7 +422,7 @@ export function addPerformanceEntries(span: Span, options: AddPerformanceEntries | |
*/ | ||
export function _addMeasureSpans( | ||
span: Span, | ||
entry: PerformanceEntry, | ||
entry: PerformanceMeasure, | ||
startTime: number, | ||
duration: number, | ||
timeOrigin: number, | ||
|
@@ -450,6 +451,34 @@ export function _addMeasureSpans( | |
attributes['sentry.browser.measure_start_time'] = measureStartTimestamp; | ||
} | ||
|
||
// 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') { | ||
for (const [key, value] of Object.entries(entry.detail)) { | ||
if (value && isPrimitive(value)) { | ||
attributes[`sentry.browser.measure.detail.${key}`] = value as SpanAttributeValue; | ||
} else { | ||
try { | ||
// This is user defined so we can't guarantee it's serializable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l: Can we instead just wrap the whole block inside of There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
attributes[`sentry.browser.measure.detail.${key}`] = JSON.stringify(value); | ||
} catch { | ||
// skip | ||
} | ||
} | ||
} | ||
} else if (isPrimitive(entry.detail)) { | ||
attributes['sentry.browser.measure.detail'] = entry.detail as SpanAttributeValue; | ||
} else { | ||
// This is user defined so we can't guarantee it's serializable | ||
try { | ||
attributes['sentry.browser.measure.detail'] = JSON.stringify(entry.detail); | ||
} catch { | ||
// skip | ||
} | ||
} | ||
} | ||
|
||
// Measurements from third parties can be off, which would create invalid spans, dropping transactions in the process. | ||
if (measureStartTimestamp <= measureEndTimestamp) { | ||
startAndEndSpan(span, measureStartTimestamp, measureEndTimestamp, { | ||
|
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.