Skip to content
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

ref(replay): Export WINDOW within Replay instead of importing it from Browser #6386

Merged
merged 2 commits into from
Dec 2, 2022
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { GLOBAL_OBJ } from '@sentry/utils';

// exporting WINDOW from within the @sentry/replay instead of importing it from @sentry/browser
// this avoids the Browser package being bundled into the CDN bundle as well as a
// circular dependency between the Browser and Replay packages in the future
export const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;

export const REPLAY_SESSION_KEY = 'sentryReplaySession';
export const REPLAY_EVENT_NAME = 'replay_event';
export const RECORDING_EVENT_NAME = 'replay_recording';
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/src/createPerformanceEntry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WINDOW } from '@sentry/browser';
import { browserPerformanceTimeOrigin } from '@sentry/utils';
import { record } from 'rrweb';

import { WINDOW } from './constants';
import { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming } from './types';
import { isIngestHost } from './util/isIngestHost';

Expand Down
14 changes: 7 additions & 7 deletions packages/replay/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/* eslint-disable max-lines */ // TODO: We might want to split this file up
import { WINDOW } from '@sentry/browser';
import { addGlobalEventProcessor, getCurrentHub, Scope, setContext } from '@sentry/core';
import { Breadcrumb, Client, Event, Integration } from '@sentry/types';
import { addInstrumentationHandler, createEnvelope, logger } from '@sentry/utils';
import debounce from 'lodash.debounce';
import { PerformanceObserverEntryList } from 'perf_hooks';
import { EventType, record } from 'rrweb';

import { breadcrumbHandler } from './coreHandlers/breadcrumbHandler';
import { spanHandler } from './coreHandlers/spanHandler';
import { createMemoryEntry, createPerformanceEntries, ReplayPerformanceEntry } from './createPerformanceEntry';
import { createEventBuffer, IEventBuffer } from './eventBuffer';
import {
DEFAULT_ERROR_SAMPLE_RATE,
DEFAULT_SESSION_SAMPLE_RATE,
MAX_SESSION_LIFE,
REPLAY_EVENT_NAME,
SESSION_IDLE_DURATION,
VISIBILITY_CHANGE_TIMEOUT,
} from './session/constants';
WINDOW,
} from './constants';
import { breadcrumbHandler } from './coreHandlers/breadcrumbHandler';
import { spanHandler } from './coreHandlers/spanHandler';
import { createMemoryEntry, createPerformanceEntries, ReplayPerformanceEntry } from './createPerformanceEntry';
import { createEventBuffer, IEventBuffer } from './eventBuffer';
import { deleteSession } from './session/deleteSession';
import { getSession } from './session/getSession';
import { saveSession } from './session/saveSession';
import { Session } from './session/Session';
import type {
import {
AllPerformanceEntry,
InstrumentationTypeBreadcrumb,
InstrumentationTypeSpan,
Expand Down
4 changes: 1 addition & 3 deletions packages/replay/src/session/deleteSession.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { WINDOW } from '@sentry/browser';

import { REPLAY_SESSION_KEY } from './constants';
import { REPLAY_SESSION_KEY, WINDOW } from '../constants';

/**
* Deletes a session from storage
Expand Down
4 changes: 1 addition & 3 deletions packages/replay/src/session/fetchSession.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { WINDOW } from '@sentry/browser';

import { REPLAY_SESSION_KEY, WINDOW } from '../constants';
import { SampleRates } from '../types';
import { REPLAY_SESSION_KEY } from './constants';
import { Session } from './Session';

/**
Expand Down
4 changes: 1 addition & 3 deletions packages/replay/src/session/saveSession.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { WINDOW } from '@sentry/browser';

import { REPLAY_SESSION_KEY } from './constants';
import { REPLAY_SESSION_KEY, WINDOW } from '../constants';
import { Session } from './Session';

export function saveSession(session: Session): void {
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/src/util/isInternal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { WINDOW } from '@sentry/browser';

import { WINDOW } from '../constants';
import { isBrowser } from './isBrowser';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/src/util/isSessionExpired.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MAX_SESSION_LIFE } from '../session/constants';
import { MAX_SESSION_LIFE } from '../constants';
import { Session } from '../session/Session';
import { isExpired } from './isExpired';

Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/flush.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { WINDOW } from '@sentry/browser';
import * as SentryUtils from '@sentry/utils';
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';

import { SESSION_IDLE_DURATION, WINDOW } from '../../src/constants';
import { Replay } from './../../src';
import { createPerformanceEntries } from './../../src/createPerformanceEntry';
import { SESSION_IDLE_DURATION } from './../../src/session/constants';
import { useFakeTimers } from './../../test/utils/use-fake-timers';

useFakeTimers();
Expand Down
4 changes: 2 additions & 2 deletions packages/replay/test/unit/index-errorSampleRate.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
jest.unmock('@sentry/browser');

import { captureException, WINDOW } from '@sentry/browser';
import { captureException } from '@sentry/browser';
import { BASE_TIMESTAMP, RecordMock } from '@test';
import { PerformanceEntryResource } from '@test/fixtures/performanceEntry/resource';
import { resetSdkMock } from '@test/mocks';
import { DomHandler, MockTransportSend } from '@test/types';

import { REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
import { Replay } from './../../src';
import { REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT } from './../../src/session/constants';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/index-handleGlobalEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Error } from '@test/fixtures/error';
import { Transaction } from '@test/fixtures/transaction';
import { resetSdkMock } from '@test/mocks';

import { REPLAY_EVENT_NAME } from '../../src/constants';
import { Replay } from './../../src';
import { REPLAY_EVENT_NAME } from './../../src/session/constants';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/index-noSticky.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Transport } from '@sentry/types';
import * as SentryUtils from '@sentry/utils';
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';

import { SESSION_IDLE_DURATION, VISIBILITY_CHANGE_TIMEOUT } from '../../src/constants';
import { Replay } from './../../src';
import { SESSION_IDLE_DURATION, VISIBILITY_CHANGE_TIMEOUT } from './../../src/session/constants';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
jest.mock('./../../src/util/isInternal', () => ({
isInternal: jest.fn(() => true),
}));
import { WINDOW } from '@sentry/browser';
import { BASE_TIMESTAMP, RecordMock } from '@test';
import { PerformanceEntryResource } from '@test/fixtures/performanceEntry/resource';
import { resetSdkMock } from '@test/mocks';
import { DomHandler, MockTransportSend } from '@test/types';
import { EventType } from 'rrweb';

import { Replay } from '../../src';
import { MAX_SESSION_LIFE, REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT } from '../../src/session/constants';
import { MAX_SESSION_LIFE, REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
import { RecordingEvent } from '../../src/types';
import { useFakeTimers } from '../utils/use-fake-timers';

Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/session/Session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jest.mock('@sentry/utils', () => {
});

import * as Sentry from '@sentry/browser';
import { WINDOW } from '@sentry/browser';

import { WINDOW } from '../../../src/constants';
import { Session } from '../../../src/session/Session';

type CaptureEventMockType = jest.MockedFunction<typeof Sentry.captureEvent>;
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/session/createSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WINDOW } from '@sentry/browser';
import * as Sentry from '@sentry/core';

import { WINDOW } from '../../../src/constants';
import { createSession } from '../../../src/session/createSession';
import { saveSession } from '../../../src/session/saveSession';

Expand Down
4 changes: 1 addition & 3 deletions packages/replay/test/unit/session/deleteSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { WINDOW } from '@sentry/browser';

import { REPLAY_SESSION_KEY } from '../../../src/session/constants';
import { REPLAY_SESSION_KEY, WINDOW } from '../../../src/constants';
import { deleteSession } from '../../../src/session/deleteSession';

const storageEngine = WINDOW.sessionStorage;
Expand Down
4 changes: 1 addition & 3 deletions packages/replay/test/unit/session/fetchSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { WINDOW } from '@sentry/browser';

import { REPLAY_SESSION_KEY } from '../../../src/session/constants';
import { REPLAY_SESSION_KEY, WINDOW } from '../../../src/constants';
import { fetchSession } from '../../../src/session/fetchSession';

const oldSessionStorage = WINDOW.sessionStorage;
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/session/getSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { WINDOW } from '@sentry/browser';

import { WINDOW } from '../../../src/constants';
import * as CreateSession from '../../../src/session/createSession';
import * as FetchSession from '../../../src/session/fetchSession';
import { getSession } from '../../../src/session/getSession';
Expand Down
4 changes: 1 addition & 3 deletions packages/replay/test/unit/session/saveSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { WINDOW } from '@sentry/browser';

import { REPLAY_SESSION_KEY } from '../../../src/session/constants';
import { REPLAY_SESSION_KEY, WINDOW } from '../../../src/constants';
import { saveSession } from '../../../src/session/saveSession';
import { Session } from '../../../src/session/Session';

Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/stop.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { WINDOW } from '@sentry/browser';
import * as SentryUtils from '@sentry/utils';
// mock functions need to be imported first
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';

import { SESSION_IDLE_DURATION, WINDOW } from '../../src/constants';
import { Replay } from './../../src';
import { SESSION_IDLE_DURATION } from './../../src/session/constants';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down