Skip to content

Commit c1fb46c

Browse files
authored
Merge branch 'develop' into ci-yarn-deduplicate
2 parents 01469ad + 1e4362e commit c1fb46c

File tree

29 files changed

+333
-275
lines changed

29 files changed

+333
-275
lines changed

dev-packages/e2e-tests/test-applications/sveltekit-2-svelte-5/tests/performance.client.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -109,30 +109,6 @@ test.describe('client-specific performance events', () => {
109109
op: 'ui.svelte.init',
110110
origin: 'auto.ui.svelte',
111111
}),
112-
expect.objectContaining({
113-
data: { 'sentry.op': 'ui.svelte.update', 'sentry.origin': 'auto.ui.svelte' },
114-
description: '<components/+page>',
115-
op: 'ui.svelte.update',
116-
origin: 'auto.ui.svelte',
117-
}),
118-
expect.objectContaining({
119-
data: { 'sentry.op': 'ui.svelte.update', 'sentry.origin': 'auto.ui.svelte' },
120-
description: '<Component1>',
121-
op: 'ui.svelte.update',
122-
origin: 'auto.ui.svelte',
123-
}),
124-
expect.objectContaining({
125-
data: { 'sentry.op': 'ui.svelte.update', 'sentry.origin': 'auto.ui.svelte' },
126-
description: '<Component2>',
127-
op: 'ui.svelte.update',
128-
origin: 'auto.ui.svelte',
129-
}),
130-
expect.objectContaining({
131-
data: { 'sentry.op': 'ui.svelte.update', 'sentry.origin': 'auto.ui.svelte' },
132-
description: '<Component3>',
133-
op: 'ui.svelte.update',
134-
origin: 'auto.ui.svelte',
135-
}),
136112
]),
137113
);
138114
});

dev-packages/e2e-tests/test-applications/sveltekit-2/src/routes/components/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import Component2 from "./Component2.svelte";
66
import Component3 from "./Component3.svelte";
77
8-
Sentry.trackComponent({componentName: 'components/+page'})
8+
Sentry.trackComponent({componentName: 'components/+page', trackUpdates: true})
99
1010
</script>
1111
<h2>Demonstrating Component Tracking</h2>

dev-packages/e2e-tests/test-applications/sveltekit-2/src/routes/components/Component1.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Component2 from "./Component2.svelte";
33
import {trackComponent} from '@sentry/sveltekit';
44
5-
trackComponent({componentName: 'Component1'});
5+
trackComponent({componentName: 'Component1', trackUpdates: true});
66
77
</script>
88
<h3>Howdy, I'm component 1</h3>

dev-packages/e2e-tests/test-applications/sveltekit-2/src/routes/components/Component2.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Component3 from "./Component3.svelte";
33
import {trackComponent} from '@sentry/sveltekit';
44
5-
trackComponent({componentName: 'Component2'});
5+
trackComponent({componentName: 'Component2', trackUpdates: true});
66
</script>
77
<h3>Howdy, I'm component 2</h3>
88

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import * as Sentry from '@sentry/sveltekit';
3-
Sentry.trackComponent({componentName: 'Component3'});
3+
Sentry.trackComponent({componentName: 'Component3', trackUpdates: true});
44
</script>
55

66
<h3>Howdy, I'm component 3</h3>

dev-packages/node-integration-tests/suites/tracing/sample-rate-propagation/tracesSampler/server.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@ const Sentry = require('@sentry/node');
44
Sentry.init({
55
dsn: 'https://[email protected]/1337',
66
transport: loggingTransport,
7-
tracesSampler: ({ parentSampleRate }) => {
8-
if (parentSampleRate) {
9-
return parentSampleRate;
10-
}
11-
12-
return 0.69;
7+
tracesSampler: ({ inheritOrSampleWith }) => {
8+
return inheritOrSampleWith(0.69);
139
},
1410
});
1511

dev-packages/node-integration-tests/suites/tracing/sample-rate-propagation/tracesSampler/test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('parentSampleRate propagation with tracesSampler', () => {
1111
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0\.69/);
1212
});
1313

14-
test('should propagate sample_rate equivalent to sample rate returned by tracesSampler when there is no incoming sample rate', async () => {
14+
test('should propagate sample_rate equivalent to sample rate returned by tracesSampler when there is no incoming sample rate (1 -> because there is a positive sampling decision and inheritOrSampleWith was used)', async () => {
1515
const runner = createRunner(__dirname, 'server.js').start();
1616
const response = await runner.makeRequest('get', '/check', {
1717
headers: {
@@ -20,6 +20,30 @@ describe('parentSampleRate propagation with tracesSampler', () => {
2020
},
2121
});
2222

23+
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=1/);
24+
});
25+
26+
test('should propagate sample_rate equivalent to sample rate returned by tracesSampler when there is no incoming sample rate (0 -> because there is a negative sampling decision and inheritOrSampleWith was used)', async () => {
27+
const runner = createRunner(__dirname, 'server.js').start();
28+
const response = await runner.makeRequest('get', '/check', {
29+
headers: {
30+
'sentry-trace': '530699e319cc067ce440315d74acb312-414dc2a08d5d1dac-0',
31+
baggage: '',
32+
},
33+
});
34+
35+
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0/);
36+
});
37+
38+
test('should propagate sample_rate equivalent to sample rate returned by tracesSampler when there is no incoming sample rate (the fallback value -> because there is no sampling decision and inheritOrSampleWith was used)', async () => {
39+
const runner = createRunner(__dirname, 'server.js').start();
40+
const response = await runner.makeRequest('get', '/check', {
41+
headers: {
42+
'sentry-trace': '530699e319cc067ce440315d74acb312-414dc2a08d5d1dac',
43+
baggage: '',
44+
},
45+
});
46+
2347
expect((response as any).propagatedData.baggage).toMatch(/sentry-sample_rate=0\.69/);
2448
});
2549

packages/browser/src/client.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import type {
99
Scope,
1010
SeverityLevel,
1111
} from '@sentry/core';
12-
import { Client, applySdkMetadata, getSDKSource } from '@sentry/core';
12+
import {
13+
Client,
14+
addAutoIpAddressToSession,
15+
addAutoIpAddressToUser,
16+
applySdkMetadata,
17+
getSDKSource,
18+
} from '@sentry/core';
1319
import { eventFromException, eventFromMessage } from './eventbuilder';
1420
import { WINDOW } from './helpers';
1521
import type { BrowserTransportOptions } from './transports/types';
@@ -84,29 +90,8 @@ export class BrowserClient extends Client<BrowserClientOptions> {
8490
}
8591

8692
if (this._options.sendDefaultPii) {
87-
this.on('postprocessEvent', event => {
88-
if (event.user?.ip_address === undefined) {
89-
event.user = {
90-
...event.user,
91-
ip_address: '{{auto}}',
92-
};
93-
}
94-
});
95-
96-
this.on('beforeSendSession', session => {
97-
if ('aggregates' in session) {
98-
if (session.attrs?.['ip_address'] === undefined) {
99-
session.attrs = {
100-
...session.attrs,
101-
ip_address: '{{auto}}',
102-
};
103-
}
104-
} else {
105-
if (session.ipAddress === undefined) {
106-
session.ipAddress = '{{auto}}';
107-
}
108-
}
109-
});
93+
this.on('postprocessEvent', addAutoIpAddressToUser);
94+
this.on('beforeSendSession', addAutoIpAddressToSession);
11095
}
11196
}
11297

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export { hasTracingEnabled } from './utils/hasTracingEnabled';
7272
export { isSentryRequestUrl } from './utils/isSentryRequestUrl';
7373
export { handleCallbackErrors } from './utils/handleCallbackErrors';
7474
export { parameterize } from './utils/parameterize';
75+
export { addAutoIpAddressToSession, addAutoIpAddressToUser } from './utils/ipAddress';
7576
export {
7677
spanToTraceHeader,
7778
spanToJSON,

packages/core/src/tracing/sampling.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,24 @@ export function sampleSpan(
2727
// work; prefer the hook if so
2828
let sampleRate;
2929
if (typeof options.tracesSampler === 'function') {
30-
sampleRate = options.tracesSampler(samplingContext);
30+
sampleRate = options.tracesSampler({
31+
...samplingContext,
32+
inheritOrSampleWith: fallbackSampleRate => {
33+
// If we have an incoming parent sample rate, we'll just use that one.
34+
// The sampling decision will be inherited because of the sample_rand that was generated when the trace reached the incoming boundaries of the SDK.
35+
if (typeof samplingContext.parentSampleRate === 'number') {
36+
return samplingContext.parentSampleRate;
37+
}
38+
39+
// Fallback if parent sample rate is not on the incoming trace (e.g. if there is no baggage)
40+
// This is to provide backwards compatibility if there are incoming traces from older SDKs that don't send a parent sample rate or a sample rand. In these cases we just want to force either a sampling decision on the downstream traces via the sample rate.
41+
if (typeof samplingContext.parentSampled === 'boolean') {
42+
return Number(samplingContext.parentSampled);
43+
}
44+
45+
return fallbackSampleRate;
46+
},
47+
});
3148
localSampleRateWasApplied = true;
3249
} else if (samplingContext.parentSampled !== undefined) {
3350
sampleRate = samplingContext.parentSampled;

0 commit comments

Comments
 (0)