From 8c777732a85e503ce1f5e8c5f7ac57fd63b6e172 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Mon, 16 Jan 2023 18:05:01 +0100 Subject: [PATCH 1/4] ref(replay): Send SDK version in Replay events --- packages/replay/jest.setup.ts | 5 +---- packages/replay/rollup.bundle.config.js | 14 -------------- packages/replay/rollup.npm.config.js | 13 ------------- packages/replay/src/types.ts | 4 ---- packages/replay/src/util/prepareReplayEvent.ts | 6 +++--- 5 files changed, 4 insertions(+), 38 deletions(-) diff --git a/packages/replay/jest.setup.ts b/packages/replay/jest.setup.ts index 640deeccf777..e2306175921c 100644 --- a/packages/replay/jest.setup.ts +++ b/packages/replay/jest.setup.ts @@ -1,13 +1,10 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { getCurrentHub } from '@sentry/core'; import type { ReplayRecordingData, Transport } from '@sentry/types'; -import {TextEncoder} from 'util'; +import { TextEncoder } from 'util'; import type { ReplayContainer, Session } from './src/types'; -// @ts-ignore TS error, this is replaced in prod builds bc of rollup -global.__SENTRY_REPLAY_VERSION__ = 'version:Test'; - (global as any).TextEncoder = TextEncoder; type MockTransport = jest.MockedFunction; diff --git a/packages/replay/rollup.bundle.config.js b/packages/replay/rollup.bundle.config.js index 46c987ac446a..75f240f85822 100644 --- a/packages/replay/rollup.bundle.config.js +++ b/packages/replay/rollup.bundle.config.js @@ -1,25 +1,11 @@ -import replace from '@rollup/plugin-replace'; - import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/index.js'; -import pkg from './package.json'; - const baseBundleConfig = makeBaseBundleConfig({ bundleType: 'addon', entrypoints: ['src/index.ts'], jsVersion: 'es6', licenseTitle: '@sentry/replay', outputFileBase: () => 'bundles/replay', - packageSpecificConfig: { - plugins: [ - replace({ - preventAssignment: true, - values: { - __SENTRY_REPLAY_VERSION__: JSON.stringify(pkg.version), - }, - }), - ], - }, }); const builds = makeBundleConfigVariants(baseBundleConfig); diff --git a/packages/replay/rollup.npm.config.js b/packages/replay/rollup.npm.config.js index ffb944b94e2b..57cc0bc5be3e 100644 --- a/packages/replay/rollup.npm.config.js +++ b/packages/replay/rollup.npm.config.js @@ -1,22 +1,9 @@ -import replace from '@rollup/plugin-replace'; - import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index'; -import pkg from './package.json'; - export default makeNPMConfigVariants( makeBaseNPMConfig({ hasBundles: true, packageSpecificConfig: { - plugins: [ - // TODO: Remove this - replay version will be in sync w/ SDK version - replace({ - preventAssignment: true, - values: { - __SENTRY_REPLAY_VERSION__: JSON.stringify(pkg.version), - }, - }), - ], output: { // set exports to 'named' or 'auto' so that rollup doesn't warn about // the default export in `worker/worker.js` diff --git a/packages/replay/src/types.ts b/packages/replay/src/types.ts index 356a3c1179fc..baa93edd2cad 100644 --- a/packages/replay/src/types.ts +++ b/packages/replay/src/types.ts @@ -29,10 +29,6 @@ export interface WorkerRequest { args: unknown[]; } -declare global { - const __SENTRY_REPLAY_VERSION__: string; -} - // PerformancePaintTiming and PerformanceNavigationTiming are only available with TS 4.4 and newer // Therefore, we're exporting them here to make them available in older TS versions export type PerformancePaintTiming = PerformanceEntry; diff --git a/packages/replay/src/util/prepareReplayEvent.ts b/packages/replay/src/util/prepareReplayEvent.ts index d9227f50cfca..c2b645e92bdc 100644 --- a/packages/replay/src/util/prepareReplayEvent.ts +++ b/packages/replay/src/util/prepareReplayEvent.ts @@ -30,12 +30,12 @@ export async function prepareReplayEvent({ // extract the SDK name because `client._prepareEvent` doesn't add it to the event const metadata = client.getSdkMetadata && client.getSdkMetadata(); - const name = (metadata && metadata.sdk && metadata.sdk.name) || 'sentry.javascript.unknown'; + const { name, version } = (metadata && metadata.sdk) || {}; preparedEvent.sdk = { ...preparedEvent.sdk, - version: __SENTRY_REPLAY_VERSION__, - name, + name: name || 'sentry.javascript.unknown', + version: version || '0.0.0', }; return preparedEvent; From 6d2297b681e22a56616200925c7aa47d8d6f5515 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 17 Jan 2023 10:49:06 +0100 Subject: [PATCH 2/4] adjust test --- .../test/unit/util/prepareReplayEvent.test.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/replay/test/unit/util/prepareReplayEvent.test.ts b/packages/replay/test/unit/util/prepareReplayEvent.test.ts index c16c4c0afbb7..0a278334de68 100644 --- a/packages/replay/test/unit/util/prepareReplayEvent.test.ts +++ b/packages/replay/test/unit/util/prepareReplayEvent.test.ts @@ -18,6 +18,19 @@ describe('Unit | util | prepareReplayEvent', () => { client = hub.getClient()!; scope = hub.getScope()!; + + jest.spyOn(client, 'getSdkMetadata').mockImplementation(() => { + return { + sdk: { + name: 'sentry.javascript.testSdk', + version: '1.0.0', + }, + }; + }); + }); + + afterEach(() => { + jest.clearAllMocks(); }); it('works', async () => { @@ -39,6 +52,8 @@ describe('Unit | util | prepareReplayEvent', () => { const replayEvent = await prepareReplayEvent({ scope, client, replayId, event }); + expect(client.getSdkMetadata).toHaveBeenCalledTimes(1); + expect(replayEvent).toEqual({ type: 'replay_event', timestamp: 1670837008.634, @@ -52,8 +67,8 @@ describe('Unit | util | prepareReplayEvent', () => { event_id: 'replay-ID', environment: 'production', sdk: { - name: 'sentry.javascript.unknown', - version: 'version:Test', + name: 'sentry.javascript.testSdk', + version: '1.0.0', }, sdkProcessingMetadata: {}, breadcrumbs: undefined, From 432e014028cdc3a501e0bf7e1598a1c0e002f6de Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 17 Jan 2023 11:31:35 +0100 Subject: [PATCH 3/4] adjust full CDN bundle config --- packages/tracing/rollup.bundle.config.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/packages/tracing/rollup.bundle.config.js b/packages/tracing/rollup.bundle.config.js index a5f7141b9b74..b4ac04aa8e76 100644 --- a/packages/tracing/rollup.bundle.config.js +++ b/packages/tracing/rollup.bundle.config.js @@ -1,9 +1,5 @@ -import replace from '@rollup/plugin-replace'; - import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/index.js'; -import pkg from './package.json'; - const builds = []; ['es5', 'es6'].forEach(jsVersion => { @@ -26,16 +22,6 @@ const replayBaseBundleConfig = makeBaseBundleConfig({ 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), - }, - }), - ], - }, }); builds.push(...makeBundleConfigVariants(replayBaseBundleConfig)); From 18146a7f8ca0dc5f460914134a595b11c4280a12 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Wed, 18 Jan 2023 13:42:17 +0100 Subject: [PATCH 4/4] add comment to rollup config --- packages/replay/rollup.npm.config.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/replay/rollup.npm.config.js b/packages/replay/rollup.npm.config.js index 57cc0bc5be3e..77934a115f87 100644 --- a/packages/replay/rollup.npm.config.js +++ b/packages/replay/rollup.npm.config.js @@ -8,6 +8,8 @@ export default makeNPMConfigVariants( // set exports to 'named' or 'auto' so that rollup doesn't warn about // the default export in `worker/worker.js` exports: 'named', + // set preserveModules to false because for Replay we actually want + // to bundle everything into one file. preserveModules: false, }, },