Skip to content

Commit 1249496

Browse files
authored
ref(replay): Send SDK version in Replay events (#6814)
Since we now export Replay via the Browser SDK we can now send the SDK version instead of the Replay package.json version, allowing us to get rid of the custom rollup config to inject said version.
1 parent fdf9ff8 commit 1249496

File tree

7 files changed

+23
-54
lines changed

7 files changed

+23
-54
lines changed

packages/replay/jest.setup.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
22
import { getCurrentHub } from '@sentry/core';
33
import type { ReplayRecordingData, Transport } from '@sentry/types';
4-
import {TextEncoder} from 'util';
4+
import { TextEncoder } from 'util';
55

66
import type { ReplayContainer, Session } from './src/types';
77

8-
// @ts-ignore TS error, this is replaced in prod builds bc of rollup
9-
global.__SENTRY_REPLAY_VERSION__ = 'version:Test';
10-
118
(global as any).TextEncoder = TextEncoder;
129

1310
type MockTransport = jest.MockedFunction<Transport['send']>;

packages/replay/rollup.bundle.config.js

-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
import replace from '@rollup/plugin-replace';
2-
31
import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/index.js';
42

5-
import pkg from './package.json';
6-
73
const baseBundleConfig = makeBaseBundleConfig({
84
bundleType: 'addon',
95
entrypoints: ['src/index.ts'],
106
jsVersion: 'es6',
117
licenseTitle: '@sentry/replay',
128
outputFileBase: () => 'bundles/replay',
13-
packageSpecificConfig: {
14-
plugins: [
15-
replace({
16-
preventAssignment: true,
17-
values: {
18-
__SENTRY_REPLAY_VERSION__: JSON.stringify(pkg.version),
19-
},
20-
}),
21-
],
22-
},
239
});
2410

2511
const builds = makeBundleConfigVariants(baseBundleConfig);

packages/replay/rollup.npm.config.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1-
import replace from '@rollup/plugin-replace';
2-
31
import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index';
42

5-
import pkg from './package.json';
6-
73
export default makeNPMConfigVariants(
84
makeBaseNPMConfig({
95
hasBundles: true,
106
packageSpecificConfig: {
11-
plugins: [
12-
// TODO: Remove this - replay version will be in sync w/ SDK version
13-
replace({
14-
preventAssignment: true,
15-
values: {
16-
__SENTRY_REPLAY_VERSION__: JSON.stringify(pkg.version),
17-
},
18-
}),
19-
],
207
output: {
218
// set exports to 'named' or 'auto' so that rollup doesn't warn about
229
// the default export in `worker/worker.js`
2310
exports: 'named',
11+
// set preserveModules to false because for Replay we actually want
12+
// to bundle everything into one file.
2413
preserveModules: false,
2514
},
2615
},

packages/replay/src/types.ts

-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ export interface WorkerRequest {
2929
args: unknown[];
3030
}
3131

32-
declare global {
33-
const __SENTRY_REPLAY_VERSION__: string;
34-
}
35-
3632
// PerformancePaintTiming and PerformanceNavigationTiming are only available with TS 4.4 and newer
3733
// Therefore, we're exporting them here to make them available in older TS versions
3834
export type PerformancePaintTiming = PerformanceEntry;

packages/replay/src/util/prepareReplayEvent.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ export async function prepareReplayEvent({
3030

3131
// extract the SDK name because `client._prepareEvent` doesn't add it to the event
3232
const metadata = client.getSdkMetadata && client.getSdkMetadata();
33-
const name = (metadata && metadata.sdk && metadata.sdk.name) || 'sentry.javascript.unknown';
33+
const { name, version } = (metadata && metadata.sdk) || {};
3434

3535
preparedEvent.sdk = {
3636
...preparedEvent.sdk,
37-
version: __SENTRY_REPLAY_VERSION__,
38-
name,
37+
name: name || 'sentry.javascript.unknown',
38+
version: version || '0.0.0',
3939
};
4040

4141
return preparedEvent;

packages/replay/test/unit/util/prepareReplayEvent.test.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ describe('Unit | util | prepareReplayEvent', () => {
1818

1919
client = hub.getClient()!;
2020
scope = hub.getScope()!;
21+
22+
jest.spyOn(client, 'getSdkMetadata').mockImplementation(() => {
23+
return {
24+
sdk: {
25+
name: 'sentry.javascript.testSdk',
26+
version: '1.0.0',
27+
},
28+
};
29+
});
30+
});
31+
32+
afterEach(() => {
33+
jest.clearAllMocks();
2134
});
2235

2336
it('works', async () => {
@@ -39,6 +52,8 @@ describe('Unit | util | prepareReplayEvent', () => {
3952

4053
const replayEvent = await prepareReplayEvent({ scope, client, replayId, event });
4154

55+
expect(client.getSdkMetadata).toHaveBeenCalledTimes(1);
56+
4257
expect(replayEvent).toEqual({
4358
type: 'replay_event',
4459
timestamp: 1670837008.634,
@@ -52,8 +67,8 @@ describe('Unit | util | prepareReplayEvent', () => {
5267
event_id: 'replay-ID',
5368
environment: 'production',
5469
sdk: {
55-
name: 'sentry.javascript.unknown',
56-
version: 'version:Test',
70+
name: 'sentry.javascript.testSdk',
71+
version: '1.0.0',
5772
},
5873
sdkProcessingMetadata: {},
5974
breadcrumbs: undefined,

packages/tracing/rollup.bundle.config.js

-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import replace from '@rollup/plugin-replace';
2-
31
import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/index.js';
42

5-
import pkg from './package.json';
6-
73
const builds = [];
84

95
['es5', 'es6'].forEach(jsVersion => {
@@ -26,16 +22,6 @@ const replayBaseBundleConfig = makeBaseBundleConfig({
2622
licenseTitle: '@sentry/tracing & @sentry/browser & @sentry/replay',
2723
outputFileBase: () => 'bundles/bundle.tracing.replay',
2824
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-
},
3925
});
4026

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

0 commit comments

Comments
 (0)