Skip to content

build(replay): Provide full browser+tracing+replay bundle #6793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ module.exports = [
limit: '48 KB',
ignore: ['@sentry/browser', '@sentry/utils', '@sentry/core', '@sentry/types'],
},
{
name: '@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified)',
path: 'packages/tracing/build/bundles/bundle.tracing.replay.min.js',
gzip: true,
limit: '80 KB',
},
];
23 changes: 14 additions & 9 deletions packages/replay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,11 @@ replay.start();
## Loading Replay as a CDN Bundle

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

```js
// Browser SDK bundle
<script
src="https://browser.sentry-cdn.com/7.24.1/bundle.tracing.min.js"
crossorigin="anonymous"
></script>

// Replay integration bundle
<script
src="https://browser.sentry-cdn.com/7.24.1/replay.min.js"
Comment on lines -108 to -114
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Hmm it probably makes sense to show the full CDN bundle here but I'd like to keep the addon bundle around and documented (at least in docs) as I think some people might prefer it 🤔 Especially, if we're considering using the loader to lazy load it in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah, I guess the reason to use it is if you want replay but not tracing - fair! I can add both somehow - probably leave the "full" bundle on top and add a section below on standalone usage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added another section below 👍

src="https://browser.sentry-cdn.com/7.31.0/bundle.tracing.replay.min.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't comment there directly but:
L95-96: Let's remove the text as this doesn't apply anymore if we tell them in this snippet to use the full bundle.

crossorigin="anonymous"
></script>

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

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

Alternatively, you can also load the Replay integration separately from other bundles:

```html
<script
src="https://browser.sentry-cdn.com/7.31.0/bundle.min.js"
crossorigin="anonymous"
></script>
<script
src="https://browser.sentry-cdn.com/7.31.0/replay.min.js"
crossorigin="anonymous"
></script>
```

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.
Note that the two bundle versions always have to match.

Expand Down
26 changes: 26 additions & 0 deletions packages/tracing/rollup.bundle.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import replace from '@rollup/plugin-replace';

import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/index.js';

import pkg from './package.json';

const builds = [];

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

// Full bundle incl. replay only avaialable for es6
const replayBaseBundleConfig = makeBaseBundleConfig({
bundleType: 'standalone',
entrypoints: ['src/index.bundle.replay.ts'],
jsVersion: 'es6',
licenseTitle: '@sentry/tracing & @sentry/browser & @sentry/replay',
outputFileBase: () => 'bundles/bundle.tracing.replay',
includeReplay: true,
packageSpecificConfig: {
plugins: [
replace({
preventAssignment: true,
values: {
__SENTRY_REPLAY_VERSION__: JSON.stringify(pkg.version),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to ourselves: In the next version, we should get rid of this. By now all docs etc. point to importing replay directly from @sentry/browser, so this should always be in sync.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we document this here #5194 or in a new issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait you mean next version of the SDK, not next major version. Ignore me!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this needs to be in a major release. We're tracking this in #6366

},
}),
],
},
});

builds.push(...makeBundleConfigVariants(replayBaseBundleConfig));

export default builds;
7 changes: 7 additions & 0 deletions packages/tracing/src/index.bundle.replay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Replay } from '@sentry/browser';

import * as Sentry from './index.bundle';

Sentry.Integrations.Replay = Replay;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was the easiest/cleanest way I could find to handle this in a dedicated input file. Otherwise it gets quite messy when trying to do this inside of index.bundle.ts 😬

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This means we only have a single default export here, and can't do our usual import * as Sentry stuff. but since we only use this to generate the bundle, and there it works as expected, I'd say that's fine?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine and with this change, the full CDN bundle usage is identical to the addon bundle (docs).


export default Sentry;
7 changes: 6 additions & 1 deletion packages/tracing/src/index.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export {
export { SDK_VERSION } from '@sentry/browser';

import { Integrations as BrowserIntegrations } from '@sentry/browser';
import type { Integration } from '@sentry/types';
import { GLOBAL_OBJ } from '@sentry/utils';

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

const INTEGRATIONS = {
// For whatever reason, it does not recognize BrowserTracing or some of the BrowserIntegrations as Integration
const INTEGRATIONS: Record<
string,
Integration | typeof BrowserTracing | typeof BrowserIntegrations[keyof typeof BrowserIntegrations]
> = {
...windowIntegrations,
...BrowserIntegrations,
BrowserTracing,
Expand Down
19 changes: 19 additions & 0 deletions packages/tracing/test/index.bundle.replay.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Sentry from '../src/index.bundle.replay';

// Because of the way how we re-export stuff for the replay bundle, we only have a single default export
const { Integrations } = Sentry;

describe('Integrations export', () => {
it('is exported correctly', () => {
Object.keys(Integrations).forEach(key => {
// Skip BrowserTracing because it doesn't have a static id field.
if (key === 'BrowserTracing') {
return;
}

expect((Integrations[key] as any).id).toStrictEqual(expect.any(String));
});

expect(Integrations.Replay).toBeDefined();
});
});
6 changes: 3 additions & 3 deletions packages/tracing/test/index.bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ describe('Integrations export', () => {
return;
}

expect(Integrations[key as keyof Omit<typeof Integrations, 'BrowserTracing'>].id).toStrictEqual(
expect.any(String),
);
expect((Integrations[key] as any).id).toStrictEqual(expect.any(String));
});
});

expect(Integrations.Replay).toBeUndefined();
});
2 changes: 1 addition & 1 deletion packages/tracing/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// the fact that it introduces a dependency on `@sentry/browser` which doesn't exist anywhere else in the SDK, which
// then prevents us from building that and this at the same time when doing a parallellized build from the repo root
// level.
"exclude": ["src/index.bundle.ts"],
"exclude": ["src/index.bundle.ts", "src/index.bundle.replay.ts"],

"compilerOptions": {
"declaration": true,
Expand Down
9 changes: 7 additions & 2 deletions rollup/bundleHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import { mergePlugins } from './utils';
const BUNDLE_VARIANTS = ['.js', '.min.js', '.debug.min.js'];

export function makeBaseBundleConfig(options) {
const { bundleType, entrypoints, jsVersion, licenseTitle, outputFileBase, packageSpecificConfig } = options;
const { bundleType, entrypoints, jsVersion, licenseTitle, outputFileBase, packageSpecificConfig, includeReplay } =
options;

const nodeResolvePlugin = makeNodeResolvePlugin();
const sucrasePlugin = makeSucrasePlugin();
Expand All @@ -45,9 +46,13 @@ export function makeBaseBundleConfig(options) {
name: 'Sentry',
},
context: 'window',
plugins: [markAsBrowserBuildPlugin, excludeReplayPlugin],
plugins: [markAsBrowserBuildPlugin],
};

if (!includeReplay) {
standAloneBundleConfig.plugins.push(excludeReplayPlugin);
}

// used by `@sentry/integrations` and `@sentry/wasm` (bundles which need to be combined with a stand-alone SDK bundle)
const addOnBundleConfig = {
// These output settings are designed to mimic an IIFE. We don't use Rollup's `iife` format because we don't want to
Expand Down