@sentry/replay 0.6.6 → 0.6.7-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/config/types/jest.config.d.ts +3 -0
  2. package/dist/config/types/jest.setup.d.ts +32 -0
  3. package/dist/config/types/src/blockAllMedia.test.d.ts +1 -0
  4. package/dist/config/types/src/coreHandlers/getBreadcrumbHandler.d.ts +3 -0
  5. package/dist/config/types/src/coreHandlers/getSpanHandler.d.ts +5 -0
  6. package/dist/config/types/src/coreHandlers/handleDom.d.ts +1 -0
  7. package/dist/config/types/src/coreHandlers/handleFetch.d.ts +19 -0
  8. package/dist/config/types/src/coreHandlers/handleFetch.test.d.ts +1 -0
  9. package/dist/config/types/src/coreHandlers/handleHistory.d.ts +7 -0
  10. package/dist/config/types/src/coreHandlers/handleScope-unit.test.d.ts +1 -0
  11. package/dist/config/types/src/coreHandlers/handleScope.d.ts +2 -0
  12. package/dist/config/types/src/coreHandlers/handleScope.test.d.ts +1 -0
  13. package/dist/config/types/src/coreHandlers/handleXhr.d.ts +21 -0
  14. package/dist/config/types/src/createPerformanceEntry.d.ts +43 -0
  15. package/dist/config/types/src/createPerformanceEntry.test.d.ts +1 -0
  16. package/dist/config/types/src/eventBuffer.d.ts +45 -0
  17. package/dist/config/types/src/eventBuffer.test.d.ts +1 -0
  18. package/dist/config/types/src/flags.d.ts +2 -0
  19. package/dist/config/types/src/flush.test.d.ts +1 -0
  20. package/dist/config/types/src/index-captureOnlyOnError.test.d.ts +1 -0
  21. package/dist/config/types/src/index-noSticky.test.d.ts +1 -0
  22. package/dist/config/types/src/index-sampling.test.d.ts +1 -0
  23. package/dist/config/types/src/index.d.ts +245 -0
  24. package/dist/config/types/src/index.test.d.ts +1 -0
  25. package/dist/config/types/src/multiple-instances.test.d.ts +1 -0
  26. package/dist/config/types/src/session/Session.d.ts +63 -0
  27. package/dist/config/types/src/session/Session.test.d.ts +1 -0
  28. package/dist/config/types/src/session/constants.d.ts +6 -0
  29. package/dist/config/types/src/session/createSession.d.ts +19 -0
  30. package/dist/config/types/src/session/createSession.test.d.ts +1 -0
  31. package/dist/config/types/src/session/deleteSession.d.ts +4 -0
  32. package/dist/config/types/src/session/deleteSession.test.d.ts +1 -0
  33. package/dist/config/types/src/session/fetchSession.d.ts +5 -0
  34. package/dist/config/types/src/session/fetchSession.test.d.ts +1 -0
  35. package/dist/config/types/src/session/getSession.d.ts +28 -0
  36. package/dist/config/types/src/session/getSession.test.d.ts +1 -0
  37. package/dist/config/types/src/session/index.d.ts +1 -0
  38. package/dist/config/types/src/session/saveSession.d.ts +2 -0
  39. package/dist/config/types/src/session/saveSession.test.d.ts +1 -0
  40. package/dist/config/types/src/stop.test.d.ts +1 -0
  41. package/dist/config/types/src/types.d.ts +105 -0
  42. package/dist/config/types/src/util/addInternalBreadcrumb.d.ts +5 -0
  43. package/dist/config/types/src/util/captureInternalException.d.ts +4 -0
  44. package/dist/config/types/src/util/createBreadcrumb.d.ts +4 -0
  45. package/dist/config/types/src/util/createPayload.d.ts +5 -0
  46. package/dist/config/types/src/util/dedupePerformanceEntries.d.ts +10 -0
  47. package/dist/config/types/src/util/dedupePerformanceEntries.test.d.ts +1 -0
  48. package/dist/config/types/src/util/isExpired.d.ts +5 -0
  49. package/dist/config/types/src/util/isExpired.test.d.ts +1 -0
  50. package/dist/config/types/src/util/isIngestHost.d.ts +4 -0
  51. package/dist/config/types/src/util/isInternal.d.ts +5 -0
  52. package/dist/config/types/src/util/isSampled.d.ts +7 -0
  53. package/dist/config/types/src/util/isSampled.test.d.ts +1 -0
  54. package/dist/config/types/src/util/isSessionExpired.d.ts +5 -0
  55. package/dist/config/types/src/util/isSessionExpired.test.d.ts +1 -0
  56. package/dist/config/types/src/util/logger.d.ts +12 -0
  57. package/dist/config/types/test/fixtures/performanceEntry/lcp.d.ts +1 -0
  58. package/dist/config/types/test/fixtures/performanceEntry/navigation.d.ts +1 -0
  59. package/dist/config/types/test/fixtures/performanceEntry/resource.d.ts +1 -0
  60. package/dist/config/types/test/index.d.ts +3 -0
  61. package/dist/config/types/test/mocks/mockRrweb.d.ts +15 -0
  62. package/dist/config/types/test/mocks/mockSdk.d.ts +10 -0
  63. package/dist/index.es.js +17 -3
  64. package/dist/index.js +17 -3
  65. package/dist/index.js.map +1 -1
  66. package/dist/types/src/session/constants.d.ts +1 -0
  67. package/dist/types/src/util/isSessionExpired.d.ts +1 -1
  68. package/package.json +1 -1
@@ -0,0 +1,105 @@
1
+ import type { eventWithTime, recordOptions } from 'rrweb/typings/types';
2
+ export declare type RecordingEvent = eventWithTime;
3
+ export declare type RecordingOptions = recordOptions<eventWithTime>;
4
+ export declare type RecordedEvents = Uint8Array | string;
5
+ export declare type AllPerformanceEntry = PerformancePaintTiming | PerformanceResourceTiming | PerformanceNavigationTiming;
6
+ export interface SendReplayRequest {
7
+ endpoint: string;
8
+ events: RecordedEvents;
9
+ replayId: string;
10
+ segmentId: number;
11
+ includeReplayStartTimestamp: boolean;
12
+ }
13
+ export declare type InstrumentationTypeBreadcrumb = 'dom' | 'scope';
14
+ export declare type InstrumentationTypeSpan = 'fetch' | 'xhr' | 'history';
15
+ export declare type InstrumentationType = InstrumentationTypeBreadcrumb | InstrumentationTypeSpan | 'console' | 'error' | 'unhandledrejection';
16
+ /**
17
+ * The request payload to worker
18
+ */
19
+ export interface WorkerRequest {
20
+ id: number;
21
+ method: string;
22
+ args: any[];
23
+ }
24
+ declare global {
25
+ const __SENTRY_REPLAY_VERSION__: string;
26
+ }
27
+ /**
28
+ * The response from the worker
29
+ */
30
+ export interface WorkerResponse {
31
+ id: number;
32
+ method: string;
33
+ success: boolean;
34
+ response: string | Uint8Array;
35
+ }
36
+ export interface ReplayPluginOptions {
37
+ /**
38
+ * The amount of time to wait before sending a replay
39
+ */
40
+ flushMinDelay?: number;
41
+ /**
42
+ * The max amount of time to wait before sending a replay
43
+ */
44
+ flushMaxDelay?: number;
45
+ /**
46
+ * The amount of time to buffer the initial snapshot
47
+ */
48
+ initialFlushDelay?: number;
49
+ /**
50
+ * If false, will create a new session per pageload
51
+ */
52
+ stickySession?: boolean;
53
+ /**
54
+ * Attempt to use compression when web workers are available
55
+ *
56
+ * (default is true)
57
+ */
58
+ useCompression?: boolean;
59
+ /**
60
+ * Only capture replays when an error happens
61
+ */
62
+ captureOnlyOnError?: boolean;
63
+ /**
64
+ * The sampling rate for replays. 1.0 will record all replays, 0 will record none.
65
+ */
66
+ replaysSamplingRate?: number;
67
+ /**
68
+ * Mask all text in recordings. All text will be replaced with asterisks by default.
69
+ */
70
+ maskAllText?: boolean;
71
+ /**
72
+ * Block all media (e.g. images, svg, video) in recordings.
73
+ */
74
+ blockAllMedia?: boolean;
75
+ }
76
+ export interface ReplayConfiguration extends ReplayPluginOptions, RecordingOptions {
77
+ }
78
+ /**
79
+ * Some initial state captured before creating a root replay event
80
+ */
81
+ export interface InitialState {
82
+ timestamp: number;
83
+ url: string;
84
+ }
85
+ /**
86
+ * Additional context that will be sent w/ `replay_event`
87
+ */
88
+ export interface ReplayEventContext {
89
+ /**
90
+ * Set of Sentry error ids that have occurred during a replay segment
91
+ */
92
+ errorIds: Set<string>;
93
+ /**
94
+ * Set of Sentry trace ids that have occurred during a replay segment
95
+ */
96
+ traceIds: Set<string>;
97
+ /**
98
+ * Ordered list of URLs that have been visited during a replay segment
99
+ */
100
+ urls: string[];
101
+ /**
102
+ * The timestamp of the earliest event that has been added to event buffer. This can happen due to the Performance Observer which buffers events.
103
+ */
104
+ earliestEvent: number | null;
105
+ }
@@ -0,0 +1,5 @@
1
+ import { addBreadcrumb } from '@sentry/core';
2
+ /**
3
+ * Wrapper for core SDK's `addBreadcrumb` only when used on `sentry.io`
4
+ */
5
+ export declare function addInternalBreadcrumb(arg: Parameters<typeof addBreadcrumb>[0]): void;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Captures exceptions to Sentry only when it occurs on sentry.io
3
+ */
4
+ export declare function captureInternalException(err: Error): void;
@@ -0,0 +1,4 @@
1
+ import type { Breadcrumb } from '@sentry/types';
2
+ declare type RequiredProperties = 'category' | 'message';
3
+ export default function createBreadcrumb(breadcrumb: Pick<Breadcrumb, RequiredProperties> & Partial<Omit<Breadcrumb, RequiredProperties>>): Breadcrumb;
4
+ export {};
@@ -0,0 +1,5 @@
1
+ import { RecordedEvents } from '../types';
2
+ export declare function createPayload({ events, headers, }: {
3
+ events: RecordedEvents;
4
+ headers: Record<string, any>;
5
+ }): string | Uint8Array;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * There are some difficulties diagnosing why there are duplicate navigation
3
+ * entries. We've witnessed several intermittent results:
4
+ * - duplicate entries have duration = 0
5
+ * - duplicate entries are the same object reference
6
+ * - none of the above
7
+ *
8
+ * Compare the values of several keys to determine if the entries are duplicates or not.
9
+ */
10
+ export declare function dedupePerformanceEntries(currentList: PerformanceEntryList, newList: PerformanceEntryList): PerformancePaintTiming[];
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Given an initial timestamp and an expiry duration, checks to see if current
3
+ * time should be considered as expired.
4
+ */
5
+ export declare function isExpired(initialTime: null | number, expiry: undefined | number, targetTime?: number): boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Checks is `targetHost` is a Sentry ingestion host
3
+ */
4
+ export declare function isIngestHost(targetHost: string): boolean;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns true if we are currently recording an internal to Sentry replay
3
+ * (e.g. on https://sentry.io )
4
+ */
5
+ export declare function isInternal(): boolean;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Given a sample rate, returns true if replay should be sampled.
3
+ *
4
+ * 1.0 = 100% sampling
5
+ * 0.0 = 0% sampling
6
+ */
7
+ export declare function isSampled(sampleRate: number): boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { Session } from '../session/Session';
2
+ /**
3
+ * Checks to see if session is expired
4
+ */
5
+ export declare function isSessionExpired(session: Session, idleTimeout: number, targetTime?: number): boolean;
@@ -0,0 +1,12 @@
1
+ declare const logger: {
2
+ error: (...args: any[]) => any;
3
+ warn: (...args: any[]) => any;
4
+ log: (...args: any[]) => any;
5
+ disable(): void;
6
+ enable(): void;
7
+ info: (...args: unknown[]) => void;
8
+ debug: (...args: unknown[]) => void;
9
+ assert: (...args: unknown[]) => void;
10
+ trace: (...args: unknown[]) => void;
11
+ };
12
+ export { logger };
@@ -0,0 +1 @@
1
+ export declare function PerformanceEntryLcp(obj?: Partial<PerformancePaintTiming>): PerformancePaintTiming;
@@ -0,0 +1 @@
1
+ export declare function PerformanceEntryNavigation(obj?: Partial<PerformanceNavigationTiming>): PerformanceNavigationTiming;
@@ -0,0 +1 @@
1
+ export declare function PerformanceEntryResource(obj?: Partial<PerformanceResourceTiming>): PerformanceResourceTiming;
@@ -0,0 +1,3 @@
1
+ export * from './mocks/mockRrweb';
2
+ export * from './mocks/mockSdk';
3
+ export declare const BASE_TIMESTAMP: number;
@@ -0,0 +1,15 @@
1
+ import { jest } from '@jest/globals';
2
+ import { RecordingEvent } from '../../src/types';
3
+ declare type RecordAdditionalProperties = {
4
+ takeFullSnapshot: jest.Mock;
5
+ addCustomEvent: () => void;
6
+ freezePage: () => void;
7
+ mirror: unknown;
8
+ _emitter: (event: RecordingEvent, ...args: any[]) => void;
9
+ };
10
+ export declare type RecordMock = jest.MockedFunction<typeof rrweb.record> & RecordAdditionalProperties;
11
+ import * as rrweb from 'rrweb';
12
+ export declare function mockRrweb(): {
13
+ record: RecordMock;
14
+ };
15
+ export {};
@@ -0,0 +1,10 @@
1
+ import { BrowserOptions } from '@sentry/browser';
2
+ import { ReplayConfiguration } from '../../src/types';
3
+ interface MockSdkParams {
4
+ replayOptions?: ReplayConfiguration;
5
+ sentryOptions?: BrowserOptions;
6
+ }
7
+ export declare function mockSdk({ replayOptions, sentryOptions, }?: MockSdkParams): Promise<{
8
+ replay: import("../../src").Replay;
9
+ }>;
10
+ export {};
package/dist/index.es.js CHANGED
@@ -250,6 +250,8 @@ var REPLAY_EVENT_NAME = 'replay_event';
250
250
  var SESSION_IDLE_DURATION = 300000; // 5 minutes in ms
251
251
  // Grace period to keep a session when a user changes tabs or hides window
252
252
  var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
253
+ // The maximum length of a session
254
+ var MAX_SESSION_LIFE = 1800000; // 30 minutes
253
255
 
254
256
  /**
255
257
  * Deletes a session from storage
@@ -287,9 +289,14 @@ function isExpired(initialTime, expiry, targetTime) {
287
289
  /**
288
290
  * Checks to see if session is expired
289
291
  */
290
- function isSessionExpired(session, expiry, targetTime) {
292
+ function isSessionExpired(session, idleTimeout, targetTime) {
291
293
  if (targetTime === void 0) { targetTime = +new Date(); }
292
- return isExpired(session === null || session === void 0 ? void 0 : session.lastActivity, expiry, targetTime);
294
+ return (
295
+ // First, check that maximum session length has not been exceeded
296
+ isExpired(session.started, MAX_SESSION_LIFE, targetTime) ||
297
+ // check that the idle timeout has not been exceeded (i.e. user has
298
+ // performed an action within the last `idleTimeout` ms)
299
+ isExpired(session === null || session === void 0 ? void 0 : session.lastActivity, idleTimeout, targetTime));
293
300
  }
294
301
 
295
302
  function wrapLogger(logFn) {
@@ -1473,6 +1480,13 @@ var Replay = /** @class */ (function () {
1473
1480
  // requires coordination with frontend
1474
1481
  var isMs = event.timestamp > 9999999999;
1475
1482
  var timestampInMs = isMs ? event.timestamp : event.timestamp * 1000;
1483
+ // Throw out events that happen more than 5 minutes ago. This can happen if
1484
+ // page has been left open and idle for a long period of time and user
1485
+ // comes back to trigger a new session. The performance entries rely on
1486
+ // `performance.timeOrigin`, which is when the page first opened.
1487
+ if (timestampInMs + SESSION_IDLE_DURATION < new Date().getTime()) {
1488
+ return;
1489
+ }
1476
1490
  // Only record earliest event if a new session was created, otherwise it
1477
1491
  // shouldn't be relevant
1478
1492
  if (this.newSessionCreated &&
@@ -1701,7 +1715,7 @@ var Replay = /** @class */ (function () {
1701
1715
  timestamp = new Date().getTime();
1702
1716
  sdkInfo = {
1703
1717
  name: 'sentry.javascript.integration.replay',
1704
- version: "0.6.6",
1718
+ version: "0.6.7-0",
1705
1719
  };
1706
1720
  return [4 /*yield*/, new Promise(function (resolve) {
1707
1721
  var _a;
package/dist/index.js CHANGED
@@ -258,6 +258,8 @@ var REPLAY_EVENT_NAME = 'replay_event';
258
258
  var SESSION_IDLE_DURATION = 300000; // 5 minutes in ms
259
259
  // Grace period to keep a session when a user changes tabs or hides window
260
260
  var VISIBILITY_CHANGE_TIMEOUT = SESSION_IDLE_DURATION;
261
+ // The maximum length of a session
262
+ var MAX_SESSION_LIFE = 1800000; // 30 minutes
261
263
 
262
264
  /**
263
265
  * Deletes a session from storage
@@ -295,9 +297,14 @@ function isExpired(initialTime, expiry, targetTime) {
295
297
  /**
296
298
  * Checks to see if session is expired
297
299
  */
298
- function isSessionExpired(session, expiry, targetTime) {
300
+ function isSessionExpired(session, idleTimeout, targetTime) {
299
301
  if (targetTime === void 0) { targetTime = +new Date(); }
300
- return isExpired(session === null || session === void 0 ? void 0 : session.lastActivity, expiry, targetTime);
302
+ return (
303
+ // First, check that maximum session length has not been exceeded
304
+ isExpired(session.started, MAX_SESSION_LIFE, targetTime) ||
305
+ // check that the idle timeout has not been exceeded (i.e. user has
306
+ // performed an action within the last `idleTimeout` ms)
307
+ isExpired(session === null || session === void 0 ? void 0 : session.lastActivity, idleTimeout, targetTime));
301
308
  }
302
309
 
303
310
  function wrapLogger(logFn) {
@@ -1481,6 +1488,13 @@ var Replay = /** @class */ (function () {
1481
1488
  // requires coordination with frontend
1482
1489
  var isMs = event.timestamp > 9999999999;
1483
1490
  var timestampInMs = isMs ? event.timestamp : event.timestamp * 1000;
1491
+ // Throw out events that happen more than 5 minutes ago. This can happen if
1492
+ // page has been left open and idle for a long period of time and user
1493
+ // comes back to trigger a new session. The performance entries rely on
1494
+ // `performance.timeOrigin`, which is when the page first opened.
1495
+ if (timestampInMs + SESSION_IDLE_DURATION < new Date().getTime()) {
1496
+ return;
1497
+ }
1484
1498
  // Only record earliest event if a new session was created, otherwise it
1485
1499
  // shouldn't be relevant
1486
1500
  if (this.newSessionCreated &&
@@ -1709,7 +1723,7 @@ var Replay = /** @class */ (function () {
1709
1723
  timestamp = new Date().getTime();
1710
1724
  sdkInfo = {
1711
1725
  name: 'sentry.javascript.integration.replay',
1712
- version: "0.6.6",
1726
+ version: "0.6.7-0",
1713
1727
  };
1714
1728
  return [4 /*yield*/, new Promise(function (resolve) {
1715
1729
  var _a;