Skip to content

fix(replay): Ensure we do not set replayId on dsc if replay is disabled #7939

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 1 commit into from
Apr 24, 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
5 changes: 0 additions & 5 deletions packages/browser-integration-tests/suites/replay/dsc/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@ Sentry.init({
replaysSessionSampleRate: 0.0,
replaysOnErrorSampleRate: 1.0,
});

Sentry.configureScope(scope => {
scope.setUser({ id: 'user123', segment: 'segmentB' });
scope.setTransactionName('testTransactionDSC');
});
48 changes: 48 additions & 0 deletions packages/browser-integration-tests/suites/replay/dsc/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from '@playwright/test';
import type * as Sentry from '@sentry/browser';
import type { EventEnvelopeHeaders } from '@sentry/types';

import { sentryTest } from '../../../utils/fixtures';
Expand All @@ -9,6 +10,8 @@ import {
} from '../../../utils/helpers';
import { getReplaySnapshot, shouldSkipReplayTest, waitForReplayRunning } from '../../../utils/replayHelpers';

type TestWindow = Window & { Sentry: typeof Sentry; Replay: Sentry.Replay };

sentryTest('should add replay_id to dsc of transactions', async ({ getLocalTestPath, page, browserName }) => {
// This is flaky on webkit, so skipping there...
if (shouldSkipReplayTest() || shouldSkipTracingTest() || browserName === 'webkit') {
Expand All @@ -18,6 +21,13 @@ sentryTest('should add replay_id to dsc of transactions', async ({ getLocalTestP
const url = await getLocalTestPath({ testDir: __dirname });
await page.goto(url);

await page.evaluate(() => {
(window as unknown as TestWindow).Sentry.configureScope(scope => {
scope.setUser({ id: 'user123', segment: 'segmentB' });
scope.setTransactionName('testTransactionDSC');
});
});

const envHeader = await getFirstSentryEnvelopeRequest<EventEnvelopeHeaders>(page, url, envelopeHeaderRequestParser);

await waitForReplayRunning(page);
Expand All @@ -35,3 +45,41 @@ sentryTest('should add replay_id to dsc of transactions', async ({ getLocalTestP
replay_id: replay.session?.id,
});
});

sentryTest(
'should not add replay_id to dsc of transactions if replay is not enabled',
async ({ getLocalTestPath, page, browserName }) => {
// This is flaky on webkit, so skipping there...
if (shouldSkipReplayTest() || shouldSkipTracingTest() || browserName === 'webkit') {
sentryTest.skip();
}

const url = await getLocalTestPath({ testDir: __dirname });
await page.goto(url);

await page.evaluate(() => {
(window as unknown as TestWindow).Replay.stop();

(window as unknown as TestWindow).Sentry.configureScope(scope => {
scope.setUser({ id: 'user123', segment: 'segmentB' });
scope.setTransactionName('testTransactionDSC');
});
});

const envHeader = await getFirstSentryEnvelopeRequest<EventEnvelopeHeaders>(page, url, envelopeHeaderRequestParser);

await waitForReplayRunning(page);
const replay = await getReplaySnapshot(page);

expect(replay.session?.id).toBeDefined();

expect(envHeader.trace).toBeDefined();
expect(envHeader.trace).toEqual({
environment: 'production',
user_segment: 'segmentB',
sample_rate: '1',
trace_id: expect.any(String),
public_key: 'public',
});
},
);
2 changes: 1 addition & 1 deletion packages/replay/src/util/addGlobalListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function addGlobalListeners(replay: ReplayContainer): void {
client.on('afterSendEvent', handleAfterSendEvent(replay));
client.on('createDsc', (dsc: DynamicSamplingContext) => {
const replayId = replay.getSessionId();
if (replayId) {
if (replayId && replay.isEnabled()) {
dsc.replay_id = replayId;
}
});
Expand Down