MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / _addEvent

Function _addEvent

packages/replay-internal/src/util/addEvent.ts:51–107  ·  view source on GitHub ↗
(
  replay: ReplayContainer,
  event: RecordingEvent,
  isCheckout?: boolean,
)

Source from the content-addressed store, hash-verified

49}
50
51async function _addEvent(
52 replay: ReplayContainer,
53 event: RecordingEvent,
54 isCheckout?: boolean,
55): Promise<AddEventResult | null> {
56 const { eventBuffer } = replay;
57
58 if (!eventBuffer || (eventBuffer.waitForCheckout && !isCheckout)) {
59 return null;
60 }
61
62 const isBufferMode = replay.recordingMode === 'buffer';
63
64 try {
65 if (isCheckout && isBufferMode) {
66 eventBuffer.clear();
67 }
68
69 if (isCheckout) {
70 eventBuffer.hasCheckout = true;
71 eventBuffer.waitForCheckout = false;
72 }
73
74 const replayOptions = replay.getOptions();
75
76 const eventAfterPossibleCallback = maybeApplyCallback(event, replayOptions.beforeAddRecordingEvent);
77
78 if (!eventAfterPossibleCallback) {
79 return;
80 }
81
82 return await eventBuffer.addEvent(eventAfterPossibleCallback);
83 } catch (error) {
84 const isExceeded = error && error instanceof EventBufferSizeExceededError;
85 const reason = isExceeded ? 'eventBufferOverflow' : 'eventBufferError';
86 const client = getClient();
87
88 if (client) {
89 // We are limited in the drop reasons:
90 // https://github.com/getsentry/snuba/blob/6c73be60716c2fb1c30ca627883207887c733cbd/rust_snuba/src/processors/outcomes.rs#L39
91 const dropReason = isExceeded ? 'buffer_overflow' : 'internal_sdk_error';
92 client.recordDroppedEvent(dropReason, 'replay');
93 }
94
95 if (isExceeded && isBufferMode) {
96 // Clear buffer and wait for next checkout
97 eventBuffer.clear();
98 eventBuffer.waitForCheckout = true;
99
100 return null;
101 }
102
103 replay.handleException(error);
104
105 await replay.stop({ reason });
106 }
107}
108

Callers 2

addEventSyncFunction · 0.85
addEventFunction · 0.85

Calls 7

getClientFunction · 0.90
maybeApplyCallbackFunction · 0.85
clearMethod · 0.65
getOptionsMethod · 0.65
addEventMethod · 0.65
handleExceptionMethod · 0.65
stopMethod · 0.65

Tested by

no test coverage detected