( replay: ReplayContainer, event: RecordingEvent, isCheckout?: boolean, )
| 49 | } |
| 50 | |
| 51 | async 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 |
no test coverage detected