Skip to content

Commit eedf4a5

Browse files
authored
feat(browser): Set user.ip_address explicitly to {{auto}} (#15008)
Part of getsentry/team-sdks#118 This is so far inferred at relay-side, which is pretty intransparent and potentially confusing. So instead, we want to explicitly set this in the SDK. If this is set to `null` it will not be inferred (which is kind of intransparent too, but...) This is set for: * error events (as `user.ip_address`) * transactions (as `user.ip_address`) * replay events (as `user.ip_address`) * profiles (as `user.ip_address`) * sessions (as `user.ip_address`) * session aggregates: as `attr.ip_address: '{{auto}}'` * standalone spans (not by default, but added to all standalone web vitals spans we emit, as `'client.address': '{{auto}}'` attribute)
1 parent 9cdf720 commit eedf4a5

File tree

30 files changed

+228
-13
lines changed

30 files changed

+228
-13
lines changed

dev-packages/browser-integration-tests/suites/feedback/attachTo/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ sentryTest('should capture feedback with custom button', async ({ getLocalTestUr
5757
event_id: expect.stringMatching(/\w{32}/),
5858
environment: 'production',
5959
tags: {},
60+
user: {
61+
ip_address: '{{auto}}',
62+
},
6063
sdk: {
6164
integrations: expect.arrayContaining(['Feedback']),
6265
version: expect.any(String),

dev-packages/browser-integration-tests/suites/feedback/captureFeedback/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => {
6969
'User-Agent': expect.stringContaining(''),
7070
},
7171
},
72+
user: {
73+
ip_address: '{{auto}}',
74+
},
7275
platform: 'javascript',
7376
});
7477
});

dev-packages/browser-integration-tests/suites/feedback/captureFeedbackAndReplay/hasSampling/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ sentryTest('should capture feedback', async ({ forceFlushReplay, getLocalTestUrl
103103
'User-Agent': expect.stringContaining(''),
104104
},
105105
},
106+
user: {
107+
ip_address: '{{auto}}',
108+
},
106109
platform: 'javascript',
107110
});
108111
});

dev-packages/browser-integration-tests/suites/feedback/captureFeedbackCsp/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => {
6969
'User-Agent': expect.stringContaining(''),
7070
},
7171
},
72+
user: {
73+
ip_address: '{{auto}}',
74+
},
7275
platform: 'javascript',
7376
});
7477
const cspViolation = await page.evaluate<boolean>('window.__CSPVIOLATION__');

dev-packages/browser-integration-tests/suites/manual-client/browser-context/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ sentryTest('allows to setup a client manually & capture exceptions', async ({ ge
3434
'User-Agent': expect.any(String),
3535
}),
3636
},
37+
user: {
38+
ip_address: '{{auto}}',
39+
},
3740
timestamp: expect.any(Number),
3841
environment: 'local',
3942
release: '0.0.1',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Sentry.setUser({
2+
id: 'foo',
3+
ip_address: null,
4+
});
5+
6+
Sentry.captureMessage('first_user');
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/core';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
6+
7+
sentryTest('should allow to set ip_address to null', async ({ getLocalTestUrl, page }) => {
8+
const url = await getLocalTestUrl({ testDir: __dirname });
9+
10+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
11+
12+
expect(eventData.message).toBe('first_user');
13+
expect(eventData.user).toEqual({
14+
id: 'foo',
15+
ip_address: null,
16+
});
17+
});

dev-packages/browser-integration-tests/suites/public-api/setUser/unset_user/test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ sentryTest('should unset user', async ({ getLocalTestUrl, page }) => {
1010
const eventData = await getMultipleSentryEnvelopeRequests<Event>(page, 3, { url });
1111

1212
expect(eventData[0].message).toBe('no_user');
13-
expect(eventData[0].user).toBeUndefined();
13+
expect(eventData[0].user).toEqual({ ip_address: '{{auto}}' });
1414

1515
expect(eventData[1].message).toBe('user');
16-
expect(eventData[1].user).toMatchObject({
16+
expect(eventData[1].user).toEqual({
1717
id: 'foo',
1818
ip_address: 'bar',
1919
other_key: 'baz',
2020
});
2121

2222
expect(eventData[2].message).toBe('unset_user');
23-
expect(eventData[2].user).toBeUndefined();
23+
expect(eventData[2].user).toEqual({
24+
ip_address: '{{auto}}',
25+
});
2426
});

dev-packages/browser-integration-tests/suites/public-api/setUser/update_user/test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ sentryTest('should update user', async ({ getLocalTestUrl, page }) => {
1010
const eventData = await getMultipleSentryEnvelopeRequests<Event>(page, 2, { url });
1111

1212
expect(eventData[0].message).toBe('first_user');
13-
expect(eventData[0].user).toMatchObject({
13+
expect(eventData[0].user).toEqual({
1414
id: 'foo',
1515
ip_address: 'bar',
1616
});
1717

1818
expect(eventData[1].message).toBe('second_user');
19-
expect(eventData[1].user).toMatchObject({
19+
expect(eventData[1].user).toEqual({
2020
id: 'baz',
21+
ip_address: '{{auto}}',
2122
});
2223
});

dev-packages/browser-integration-tests/suites/public-api/startSpan/standalone-mixed-transaction/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ sentryTest(
103103
headers: expect.any(Object),
104104
url: expect.any(String),
105105
},
106+
user: {
107+
ip_address: '{{auto}}',
108+
},
106109
sdk: expect.any(Object),
107110
spans: [
108111
{

0 commit comments

Comments
 (0)