Skip to content

Commit f8b74f0

Browse files
authored
feat(tracing): Expose BrowserTracing in non-tracing bundles (#7479)
1 parent 572e4f5 commit f8b74f0

27 files changed

+287
-169
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
"karma-firefox-launcher": "^1.1.0",
9898
"lerna": "6.5.0-alpha.2",
9999
"madge": "4.0.2",
100-
"magic-string": "^0.27.0",
101100
"mocha": "^6.1.4",
102101
"nodemon": "^2.0.16",
103102
"npm-run-all": "^4.1.5",
@@ -108,7 +107,6 @@
108107
"rollup": "^2.67.1",
109108
"rollup-plugin-cleanup": "3.2.1",
110109
"rollup-plugin-license": "^2.6.1",
111-
"rollup-plugin-modify": "^3.0.0",
112110
"rollup-plugin-terser": "^7.0.2",
113111
"rollup-plugin-typescript2": "^0.31.2",
114112
"sinon": "^7.3.2",

packages/browser-integration-tests/suites/replay/replayShim/test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ sentryTest(
3030
await forceFlushReplay();
3131

3232
expect(requestCount).toBe(0);
33-
expect(consoleMessages).toEqual([
34-
'You are using new Replay() even though this bundle does not include the replay integration.',
35-
]);
33+
expect(consoleMessages).toEqual(['You are using new Replay() even though this bundle does not include replay.']);
3634
},
3735
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
sampleRate: 1,
8+
integrations: [new Sentry.Integrations.BrowserTracing()],
9+
});
10+
11+
// This should not fail
12+
Sentry.addTracingExtensions();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<button onclick="console.log('Test log')">Click me</button>
8+
</body>
9+
</html>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../utils/fixtures';
4+
5+
sentryTest(
6+
'exports a shim Integrations.BrowserTracing integration for non-tracing bundles',
7+
async ({ getLocalTestPath, page }) => {
8+
const bundle = process.env.PW_BUNDLE;
9+
const tracingOnly = Boolean(process.env.PW_TRACING_ONLY);
10+
11+
if (!bundle || !bundle.startsWith('bundle_') || tracingOnly) {
12+
sentryTest.skip();
13+
}
14+
15+
const consoleMessages: string[] = [];
16+
page.on('console', msg => consoleMessages.push(msg.text()));
17+
18+
let requestCount = 0;
19+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
20+
requestCount++;
21+
return route.fulfill({
22+
status: 200,
23+
contentType: 'application/json',
24+
body: JSON.stringify({ id: 'test-id' }),
25+
});
26+
});
27+
28+
const url = await getLocalTestPath({ testDir: __dirname });
29+
30+
await page.goto(url);
31+
32+
expect(requestCount).toBe(0);
33+
expect(consoleMessages).toEqual([
34+
'You are using new BrowserTracing() even though this bundle does not include tracing.',
35+
]);
36+
},
37+
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
sampleRate: 1,
8+
integrations: [new Sentry.BrowserTracing()],
9+
});
10+
11+
// This should not fail
12+
Sentry.addTracingExtensions();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<button onclick="console.log('Test log')">Click me</button>
8+
</body>
9+
</html>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../utils/fixtures';
4+
5+
sentryTest('exports a shim BrowserTracing integration for non-tracing bundles', async ({ getLocalTestPath, page }) => {
6+
const bundle = process.env.PW_BUNDLE;
7+
const tracingOnly = Boolean(process.env.PW_TRACING_ONLY);
8+
9+
if (!bundle || !bundle.startsWith('bundle_') || tracingOnly) {
10+
sentryTest.skip();
11+
}
12+
13+
const consoleMessages: string[] = [];
14+
page.on('console', msg => consoleMessages.push(msg.text()));
15+
16+
let requestCount = 0;
17+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
18+
requestCount++;
19+
return route.fulfill({
20+
status: 200,
21+
contentType: 'application/json',
22+
body: JSON.stringify({ id: 'test-id' }),
23+
});
24+
});
25+
26+
const url = await getLocalTestPath({ testDir: __dirname });
27+
28+
await page.goto(url);
29+
30+
expect(requestCount).toBe(0);
31+
expect(consoleMessages).toEqual([
32+
'You are using new BrowserTracing() even though this bundle does not include tracing.',
33+
]);
34+
});

packages/browser/rollup.bundle.config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ const builds = [];
55
['es5', 'es6'].forEach(jsVersion => {
66
const baseBundleConfig = makeBaseBundleConfig({
77
bundleType: 'standalone',
8-
entrypoints: ['src/index.ts'],
8+
entrypoints: ['src/index.bundle.ts'],
99
jsVersion,
1010
licenseTitle: '@sentry/browser',
11-
includeReplay: 'shim',
1211
outputFileBase: () => `bundles/bundle${jsVersion === 'es5' ? '.es5' : ''}`,
1312
});
1413

@@ -18,11 +17,10 @@ const builds = [];
1817
// Full bundle incl. replay only available for es6
1918
const replayBaseBundleConfig = makeBaseBundleConfig({
2019
bundleType: 'standalone',
21-
entrypoints: ['src/index.ts'],
20+
entrypoints: ['src/index.bundle.replay.ts'],
2221
jsVersion: 'es6',
2322
licenseTitle: '@sentry/browser & @sentry/replay',
2423
outputFileBase: () => 'bundles/bundle.replay',
25-
includeReplay: true,
2624
});
2725

2826
builds.push(...makeBundleConfigVariants(replayBaseBundleConfig));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export * from './exports';
2+
3+
import { Integrations as CoreIntegrations } from '@sentry/core';
4+
import type { Integration } from '@sentry/types';
5+
6+
import { WINDOW } from './helpers';
7+
import * as BrowserIntegrations from './integrations';
8+
9+
let windowIntegrations = {};
10+
11+
// This block is needed to add compatibility with the integrations packages when used with a CDN
12+
if (WINDOW.Sentry && WINDOW.Sentry.Integrations) {
13+
windowIntegrations = WINDOW.Sentry.Integrations;
14+
}
15+
16+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
17+
const INTEGRATIONS: Record<string, new (...args: any[]) => Integration> = {
18+
...windowIntegrations,
19+
...CoreIntegrations,
20+
...BrowserIntegrations,
21+
};
22+
23+
export { INTEGRATIONS as Integrations };

0 commit comments

Comments
 (0)