()
| 22 | return { |
| 23 | name: INTEGRATION_NAME, |
| 24 | setup() { |
| 25 | const performance = getBrowserPerformanceAPI(); |
| 26 | if (!performance || !browserPerformanceTimeOrigin()) { |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | addPerformanceInstrumentationHandler('element', ({ entries }) => { |
| 31 | for (const entry of entries) { |
| 32 | const elementEntry = entry as PerformanceElementTiming; |
| 33 | |
| 34 | if (!elementEntry.identifier) { |
| 35 | continue; |
| 36 | } |
| 37 | |
| 38 | const identifier = elementEntry.identifier; |
| 39 | const paintType = elementEntry.name as 'image-paint' | 'text-paint' | undefined; |
| 40 | const renderTime = elementEntry.renderTime; |
| 41 | const loadTime = elementEntry.loadTime; |
| 42 | |
| 43 | const metricAttributes: Record<string, string | number> = { |
| 44 | 'sentry.origin': 'auto.ui.browser.element_timing', |
| 45 | 'ui.element.identifier': identifier, |
| 46 | }; |
| 47 | |
| 48 | if (paintType) { |
| 49 | metricAttributes['ui.element.paint_type'] = paintType; |
| 50 | } |
| 51 | |
| 52 | if (elementEntry.id) { |
| 53 | metricAttributes['ui.element.id'] = elementEntry.id; |
| 54 | } |
| 55 | |
| 56 | if (elementEntry.element) { |
| 57 | metricAttributes['ui.element.type'] = elementEntry.element.tagName.toLowerCase(); |
| 58 | } |
| 59 | |
| 60 | if (elementEntry.url) { |
| 61 | metricAttributes['ui.element.url'] = elementEntry.url; |
| 62 | } |
| 63 | |
| 64 | if (elementEntry.naturalWidth) { |
| 65 | metricAttributes['ui.element.width'] = elementEntry.naturalWidth; |
| 66 | } |
| 67 | |
| 68 | if (elementEntry.naturalHeight) { |
| 69 | metricAttributes['ui.element.height'] = elementEntry.naturalHeight; |
| 70 | } |
| 71 | |
| 72 | if (renderTime > 0) { |
| 73 | metrics.distribution(`ui.element.render_time`, renderTime, { |
| 74 | unit: 'millisecond', |
| 75 | attributes: metricAttributes, |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | if (loadTime > 0) { |
| 80 | metrics.distribution(`ui.element.load_time`, loadTime, { |
| 81 | unit: 'millisecond', |
nothing calls this directly
no test coverage detected