Skip to content

Commit 660d4bb

Browse files
authored
build(replay): Provide full browser+tracing+replay bundle (#6793)
1 parent 6227e44 commit 660d4bb

9 files changed

+89
-16
lines changed

.size-limit.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,10 @@ module.exports = [
7878
limit: '48 KB',
7979
ignore: ['@sentry/browser', '@sentry/utils', '@sentry/core', '@sentry/types'],
8080
},
81+
{
82+
name: '@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified)',
83+
path: 'packages/tracing/build/bundles/bundle.tracing.replay.min.js',
84+
gzip: true,
85+
limit: '80 KB',
86+
},
8187
];

packages/replay/README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,11 @@ replay.start();
9999
## Loading Replay as a CDN Bundle
100100

101101
As an alternative to the NPM package, you can load the Replay integration bundle from our CDN.
102-
Note that the Replay bundle **only contains the Replay integration** and not the entire Sentry SDK.
103-
You have to add it in addition to the Sentry Browser SDK bundle:
104102

105103
```js
106104
// Browser SDK bundle
107105
<script
108-
src="https://browser.sentry-cdn.com/7.24.1/bundle.tracing.min.js"
109-
crossorigin="anonymous"
110-
></script>
111-
112-
// Replay integration bundle
113-
<script
114-
src="https://browser.sentry-cdn.com/7.24.1/replay.min.js"
106+
src="https://browser.sentry-cdn.com/7.31.0/bundle.tracing.replay.min.js"
115107
crossorigin="anonymous"
116108
></script>
117109

@@ -132,6 +124,19 @@ Sentry.init({
132124

133125
The Replay initilialization [configuration](#configuration) options are identical to the options of the NPM package.
134126

127+
Alternatively, you can also load the Replay integration separately from other bundles:
128+
129+
```html
130+
<script
131+
src="https://browser.sentry-cdn.com/7.31.0/bundle.min.js"
132+
crossorigin="anonymous"
133+
></script>
134+
<script
135+
src="https://browser.sentry-cdn.com/7.31.0/replay.min.js"
136+
crossorigin="anonymous"
137+
></script>
138+
```
139+
135140
Please visit our [CDN bundle docs](https://docs.sentry.io/platforms/javascript/install/cdn/#available-bundles) to get the correct `integrity` checksums for your version.
136141
Note that the two bundle versions always have to match.
137142

packages/tracing/rollup.bundle.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import replace from '@rollup/plugin-replace';
2+
13
import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/index.js';
24

5+
import pkg from './package.json';
6+
37
const builds = [];
48

59
['es5', 'es6'].forEach(jsVersion => {
@@ -14,4 +18,26 @@ const builds = [];
1418
builds.push(...makeBundleConfigVariants(baseBundleConfig));
1519
});
1620

21+
// Full bundle incl. replay only avaialable for es6
22+
const replayBaseBundleConfig = makeBaseBundleConfig({
23+
bundleType: 'standalone',
24+
entrypoints: ['src/index.bundle.replay.ts'],
25+
jsVersion: 'es6',
26+
licenseTitle: '@sentry/tracing & @sentry/browser & @sentry/replay',
27+
outputFileBase: () => 'bundles/bundle.tracing.replay',
28+
includeReplay: true,
29+
packageSpecificConfig: {
30+
plugins: [
31+
replace({
32+
preventAssignment: true,
33+
values: {
34+
__SENTRY_REPLAY_VERSION__: JSON.stringify(pkg.version),
35+
},
36+
}),
37+
],
38+
},
39+
});
40+
41+
builds.push(...makeBundleConfigVariants(replayBaseBundleConfig));
42+
1743
export default builds;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Replay } from '@sentry/browser';
2+
3+
import * as Sentry from './index.bundle';
4+
5+
Sentry.Integrations.Replay = Replay;
6+
7+
export default Sentry;

packages/tracing/src/index.bundle.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export {
5353
export { SDK_VERSION } from '@sentry/browser';
5454

5555
import { Integrations as BrowserIntegrations } from '@sentry/browser';
56+
import type { Integration } from '@sentry/types';
5657
import { GLOBAL_OBJ } from '@sentry/utils';
5758

5859
import { BrowserTracing } from './browser';
@@ -67,7 +68,11 @@ if (GLOBAL_OBJ.Sentry && GLOBAL_OBJ.Sentry.Integrations) {
6768
windowIntegrations = GLOBAL_OBJ.Sentry.Integrations;
6869
}
6970

70-
const INTEGRATIONS = {
71+
// For whatever reason, it does not recognize BrowserTracing or some of the BrowserIntegrations as Integration
72+
const INTEGRATIONS: Record<
73+
string,
74+
Integration | typeof BrowserTracing | typeof BrowserIntegrations[keyof typeof BrowserIntegrations]
75+
> = {
7176
...windowIntegrations,
7277
...BrowserIntegrations,
7378
BrowserTracing,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Sentry from '../src/index.bundle.replay';
2+
3+
// Because of the way how we re-export stuff for the replay bundle, we only have a single default export
4+
const { Integrations } = Sentry;
5+
6+
describe('Integrations export', () => {
7+
it('is exported correctly', () => {
8+
Object.keys(Integrations).forEach(key => {
9+
// Skip BrowserTracing because it doesn't have a static id field.
10+
if (key === 'BrowserTracing') {
11+
return;
12+
}
13+
14+
expect((Integrations[key] as any).id).toStrictEqual(expect.any(String));
15+
});
16+
17+
expect(Integrations.Replay).toBeDefined();
18+
});
19+
});

packages/tracing/test/index.bundle.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ describe('Integrations export', () => {
88
return;
99
}
1010

11-
expect(Integrations[key as keyof Omit<typeof Integrations, 'BrowserTracing'>].id).toStrictEqual(
12-
expect.any(String),
13-
);
11+
expect((Integrations[key] as any).id).toStrictEqual(expect.any(String));
1412
});
1513
});
14+
15+
expect(Integrations.Replay).toBeUndefined();
1616
});

packages/tracing/tsconfig.types.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// the fact that it introduces a dependency on `@sentry/browser` which doesn't exist anywhere else in the SDK, which
66
// then prevents us from building that and this at the same time when doing a parallellized build from the repo root
77
// level.
8-
"exclude": ["src/index.bundle.ts"],
8+
"exclude": ["src/index.bundle.ts", "src/index.bundle.replay.ts"],
99

1010
"compilerOptions": {
1111
"declaration": true,

rollup/bundleHelpers.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import { mergePlugins } from './utils';
2323
const BUNDLE_VARIANTS = ['.js', '.min.js', '.debug.min.js'];
2424

2525
export function makeBaseBundleConfig(options) {
26-
const { bundleType, entrypoints, jsVersion, licenseTitle, outputFileBase, packageSpecificConfig } = options;
26+
const { bundleType, entrypoints, jsVersion, licenseTitle, outputFileBase, packageSpecificConfig, includeReplay } =
27+
options;
2728

2829
const nodeResolvePlugin = makeNodeResolvePlugin();
2930
const sucrasePlugin = makeSucrasePlugin();
@@ -45,9 +46,13 @@ export function makeBaseBundleConfig(options) {
4546
name: 'Sentry',
4647
},
4748
context: 'window',
48-
plugins: [markAsBrowserBuildPlugin, excludeReplayPlugin],
49+
plugins: [markAsBrowserBuildPlugin],
4950
};
5051

52+
if (!includeReplay) {
53+
standAloneBundleConfig.plugins.push(excludeReplayPlugin);
54+
}
55+
5156
// used by `@sentry/integrations` and `@sentry/wasm` (bundles which need to be combined with a stand-alone SDK bundle)
5257
const addOnBundleConfig = {
5358
// These output settings are designed to mimic an IIFE. We don't use Rollup's `iife` format because we don't want to

0 commit comments

Comments
 (0)