Skip to content

Commit 6a87ebe

Browse files
committed
fix meta tag precedence, add more tests, move some files and code around
1 parent f0df692 commit 6a87ebe

File tree

42 files changed

+648
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+648
-118
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Sentry.init({
77
integrations: [
88
Sentry.browserTracingIntegration({
99
linkPreviousTrace: 'in-memory',
10-
sampleLinkedTracesConsistently: true
10+
consistentTraceSampling: true,
1111
}),
1212
],
1313
tracePropagationTargets: ['someurl.com'],
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ const btn2 = document.getElementById('btn2');
44

55
btn1.addEventListener('click', () => {
66
Sentry.startNewTrace(() => {
7-
Sentry.startSpan({name: 'custom root span 1', op: 'custom'}, () => {});
7+
Sentry.startSpan({ name: 'custom root span 1', op: 'custom' }, () => {});
88
});
99
});
1010

1111
btn2.addEventListener('click', () => {
1212
Sentry.startNewTrace(() => {
13-
Sentry.startSpan({name: 'custom root span 2', op: 'custom'}, async () => {
13+
Sentry.startSpan({ name: 'custom root span 2', op: 'custom' }, async () => {
1414
await fetch('https://someUrl.com');
1515
});
1616
});
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import {
55
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
66
SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE,
77
} from '@sentry/core';
8-
9-
import { sentryTest } from '../../../../../utils/fixtures';
8+
import { sentryTest } from '../../../../../../utils/fixtures';
109
import {
1110
eventAndTraceHeaderRequestParser,
1211
shouldSkipTracingTest,
1312
waitForTransactionRequest,
14-
} from '../../../../../utils/helpers';
13+
} from '../../../../../../utils/helpers';
1514

16-
sentryTest.describe('When `sampleLinkedTracesConsistently` is `true`', () => {
15+
sentryTest.describe('When `consistentTraceSampling` is `true`', () => {
1716
sentryTest('Continues sampling decision from initial pageload', async ({ getLocalTestUrl, page }) => {
1817
if (shouldSkipTracingTest()) {
1918
sentryTest.skip();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Sentry.init({
77
integrations: [
88
Sentry.browserTracingIntegration({
99
linkPreviousTrace: 'in-memory',
10-
sampleLinkedTracesConsistently: true
10+
consistentTraceSampling: true,
1111
}),
1212
],
1313
tracePropagationTargets: ['someurl.com'],
1414
tracesSampleRate: 1,
1515
debug: true,
16-
sendClientReports: true
16+
sendClientReports: true,
1717
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ const btn2 = document.getElementById('btn2');
44

55
btn1.addEventListener('click', () => {
66
Sentry.startNewTrace(() => {
7-
Sentry.startSpan({name: 'custom root span 1', op: 'custom'}, () => {});
7+
Sentry.startSpan({ name: 'custom root span 1', op: 'custom' }, () => {});
88
});
99
});
1010

1111
btn2.addEventListener('click', () => {
1212
Sentry.startNewTrace(() => {
13-
Sentry.startSpan({name: 'custom root span 2', op: 'custom'}, async () => {
13+
Sentry.startSpan({ name: 'custom root span 2', op: 'custom' }, async () => {
1414
await fetch('https://someUrl.com');
1515
});
1616
});
Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { expect } from '@playwright/test';
22
import type { ClientReport } from '@sentry/core';
33
import { extractTraceparentData, parseBaggageHeader } from '@sentry/core';
4-
5-
import { sentryTest } from '../../../../../utils/fixtures';
4+
import { sentryTest } from '../../../../../../utils/fixtures';
65
import {
76
envelopeRequestParser,
87
getMultipleSentryEnvelopeRequests,
8+
hidePage,
99
shouldSkipTracingTest,
1010
waitForClientReportRequest,
11-
} from '../../../../../utils/helpers';
11+
} from '../../../../../../utils/helpers';
1212

1313
const metaTagSampleRand = 0.9;
1414
const metaTagSampleRate = 0.2;
1515
const metaTagTraceId = '12345678901234567890123456789012';
1616

17-
sentryTest.describe('When `sampleLinkedTracesConsistently` is `true` and page contains <meta> tags', () => {
17+
sentryTest.describe('When `consistentTraceSampling` is `true` and page contains <meta> tags', () => {
1818
sentryTest(
1919
'Continues negative sampling decision from meta tag across all traces and downstream propagations',
2020
async ({ getLocalTestUrl, page }) => {
@@ -81,18 +81,7 @@ sentryTest.describe('When `sampleLinkedTracesConsistently` is `true` and page co
8181
});
8282

8383
await sentryTest.step('Client report', async () => {
84-
await page.evaluate(() => {
85-
Object.defineProperty(document, 'visibilityState', {
86-
configurable: true,
87-
get: function () {
88-
return 'hidden';
89-
},
90-
});
91-
92-
// Dispatch the visibilitychange event to notify listeners
93-
document.dispatchEvent(new Event('visibilitychange'));
94-
});
95-
84+
await hidePage(page);
9685
const clientReport = envelopeRequestParser<ClientReport>(await clientReportPromise);
9786
expect(clientReport).toEqual({
9887
timestamp: expect.any(Number),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
7+
integrations: [
8+
Sentry.browserTracingIntegration({
9+
linkPreviousTrace: 'session-storage',
10+
consistentTraceSampling: true,
11+
}),
12+
],
13+
tracePropagationTargets: ['someurl.com'],
14+
tracesSampler: ({ inheritOrSampleWith }) => {
15+
return inheritOrSampleWith(0);
16+
},
17+
debug: true,
18+
sendClientReports: true,
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="sentry-trace" content="a2345678901234567890123456789012-1234567890123456-1" />
6+
<meta
7+
name="baggage"
8+
content="sentry-trace_id=a2345678901234567890123456789012,sentry-sample_rate=0.2,sentry-sampled=true,sentry-transaction=my-transaction,sentry-public_key=public,sentry-release=1.0.0,sentry-environment=prod,sentry-sample_rand=0.12"
9+
/>
10+
</head>
11+
<body>
12+
<h1>Another Page</h1>
13+
<a href="./page-2.html">Go To the next page</a>
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)