Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
ref(replay): Send SDK version in Replay events
  • Loading branch information
Lms24 committed Jan 18, 2023
commit 8c777732a85e503ce1f5e8c5f7ac57fd63b6e172
5 changes: 1 addition & 4 deletions packages/replay/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -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<Transport['send']>;
Expand Down
14 changes: 0 additions & 14 deletions packages/replay/rollup.bundle.config.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
13 changes: 0 additions & 13 deletions packages/replay/rollup.npm.config.js
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
4 changes: 0 additions & 4 deletions packages/replay/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions packages/replay/src/util/prepareReplayEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Copy link
Member

Choose a reason for hiding this comment

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

Just to be sure, version will already have been replaced somewhere else here, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, version is set automatically during SDK initialization:

options._metadata.sdk = options._metadata.sdk || {
name: 'sentry.javascript.react',
packages: [
{
name: 'npm:@sentry/react',
version: SDK_VERSION,
},
],

The reason for providing the fallback here is that users can potentially delete it or use a custom or an old client that doesn't yet have getSdkMetadata.

};

return preparedEvent;
Expand Down