Skip to content

Commit 9d1b35d

Browse files
authored
feat(browser): Add user agent to INP standalone span attributes (#12896)
Add the `window.navigator.userAgent` string as the [`user_agent.original`](https://opentelemetry.io/docs/specs/semconv/attributes-registry/user-agent/) attribute to INP standalone spans.
1 parent f9ab138 commit 9d1b35d

File tree

8 files changed

+14
-0
lines changed

8 files changed

+14
-0
lines changed

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-late/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ sentryTest('should capture an INP click event span after pageload', async ({ bro
7777
'sentry.sample_rate': 1,
7878
'sentry.source': 'custom',
7979
transaction: 'test-url',
80+
'user_agent.original': expect.stringContaining('Chrome'),
8081
},
8182
measurements: {
8283
inp: {

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-parametrized-late/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ sentryTest(
8080
'sentry.sample_rate': 1,
8181
'sentry.source': 'custom',
8282
transaction: 'test-route',
83+
'user_agent.original': expect.stringContaining('Chrome'),
8384
},
8485
measurements: {
8586
inp: {

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp-parametrized/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ sentryTest(
7676
'sentry.op': 'ui.interaction.click',
7777
'sentry.origin': 'auto.http.browser.inp',
7878
transaction: 'test-route',
79+
'user_agent.original': expect.stringContaining('Chrome'),
7980
},
8081
measurements: {
8182
inp: {

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-inp/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ sentryTest(
7777
'sentry.op': 'ui.interaction.click',
7878
'sentry.origin': 'auto.http.browser.inp',
7979
transaction: 'test-url',
80+
'user_agent.original': expect.stringContaining('Chrome'),
8081
},
8182
measurements: {
8283
inp: {

dev-packages/e2e-tests/test-applications/create-remix-app/tests/client-inp.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ test('sends an INP span during pageload', async ({ page }) => {
3030
'sentry.sample_rate': 1,
3131
'sentry.source': 'custom',
3232
replay_id: expect.any(String),
33+
'user_agent.original': expect.stringContaining('Chrome'),
3334
},
3435
description: 'body > div > input#exception-button[type="button"]',
3536
op: 'ui.interaction.click',
@@ -81,6 +82,7 @@ test('sends an INP span after pageload', async ({ page }) => {
8182
'sentry.sample_rate': 1,
8283
'sentry.source': 'custom',
8384
replay_id: expect.any(String),
85+
'user_agent.original': expect.stringContaining('Chrome'),
8486
},
8587
description: 'body > div > input#exception-button[type="button"]',
8688
op: 'ui.interaction.click',
@@ -125,6 +127,7 @@ test('sends an INP span during navigation', async ({ page }) => {
125127
transaction: 'routes/user.$id',
126128
'sentry.exclusive_time': expect.any(Number),
127129
replay_id: expect.any(String),
130+
'user_agent.original': expect.stringContaining('Chrome'),
128131
},
129132
description: '<unknown>',
130133
op: 'ui.interaction.click',
@@ -178,6 +181,7 @@ test('sends an INP span after navigation', async ({ page }) => {
178181
replay_id: expect.any(String),
179182
'sentry.sample_rate': 1,
180183
'sentry.source': 'custom',
184+
'user_agent.original': expect.stringContaining('Chrome'),
181185
},
182186
description: '<unknown>',
183187
op: 'ui.interaction.click',

dev-packages/e2e-tests/test-applications/react-17/tests/transactions.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ test('sends an INP span', async ({ page }) => {
8282
transaction: '/',
8383
'sentry.exclusive_time': expect.any(Number),
8484
replay_id: expect.any(String),
85+
'user_agent.original': expect.stringContaining('Chrome'),
8586
},
8687
description: 'body > div#root > input#exception-button[type="button"]',
8788
op: 'ui.interaction.click',

dev-packages/e2e-tests/test-applications/react-router-6/tests/transactions.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ test('sends an INP span', async ({ page }) => {
8282
transaction: '/',
8383
'sentry.exclusive_time': expect.any(Number),
8484
replay_id: expect.any(String),
85+
'user_agent.original': expect.stringContaining('Chrome'),
8586
},
8687
description: 'body > div#root > input#exception-button[type="button"]',
8788
op: 'ui.interaction.click',

packages/browser-utils/src/metrics/inp.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '@sentry/core';
1313
import type { Integration, Span, SpanAttributes } from '@sentry/types';
1414
import { browserPerformanceTimeOrigin, dropUndefinedKeys, htmlTreeAsString } from '@sentry/utils';
15+
import { WINDOW } from '../types';
1516
import {
1617
addInpInstrumentationHandler,
1718
addPerformanceInstrumentationHandler,
@@ -129,6 +130,9 @@ function _trackINP(): () => void {
129130
user: userDisplay || undefined,
130131
profile_id: profileId || undefined,
131132
replay_id: replayId || undefined,
133+
// INP score calculation in the sentry backend relies on the user agent
134+
// to account for different INP values being reported from different browsers
135+
'user_agent.original': WINDOW.navigator && WINDOW.navigator.userAgent,
132136
});
133137

134138
const span = startInactiveSpan({

0 commit comments

Comments
 (0)