Skip to content

Commit

Permalink
wip browser
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Sep 15, 2023
1 parent 72c09b7 commit 16a892a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 40 deletions.
81 changes: 42 additions & 39 deletions packages/replay/src/coreHandlers/handleGlobalEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,54 @@ export function handleGlobalEventListener(
): (event: Event, hint: EventHint) => Event | null {
const afterSendHandler = includeAfterSendEventHandling ? handleAfterSendEvent(replay) : undefined;

return (event: Event, hint: EventHint) => {
// Do nothing if replay has been disabled
if (!replay.isEnabled()) {
return event;
}
return Object.assign(
(event: Event, hint: EventHint) => {
// Do nothing if replay has been disabled
if (!replay.isEnabled()) {
return event;
}

if (isReplayEvent(event)) {
// Replays have separate set of breadcrumbs, do not include breadcrumbs
// from core SDK
delete event.breadcrumbs;
return event;
}
if (isReplayEvent(event)) {
// Replays have separate set of breadcrumbs, do not include breadcrumbs
// from core SDK
delete event.breadcrumbs;
return event;
}

// We only want to handle errors & transactions, nothing else
if (!isErrorEvent(event) && !isTransactionEvent(event)) {
return event;
}
// We only want to handle errors & transactions, nothing else
if (!isErrorEvent(event) && !isTransactionEvent(event)) {
return event;
}

// Unless `captureExceptions` is enabled, we want to ignore errors coming from rrweb
// As there can be a bunch of stuff going wrong in internals there, that we don't want to bubble up to users
if (isRrwebError(event, hint) && !replay.getOptions()._experiments.captureExceptions) {
__DEBUG_BUILD__ && logger.log('[Replay] Ignoring error from rrweb internals', event);
return null;
}
// Unless `captureExceptions` is enabled, we want to ignore errors coming from rrweb
// As there can be a bunch of stuff going wrong in internals there, that we don't want to bubble up to users
if (isRrwebError(event, hint) && !replay.getOptions()._experiments.captureExceptions) {
__DEBUG_BUILD__ && logger.log('[Replay] Ignoring error from rrweb internals', event);
return null;
}

// When in buffer mode, we decide to sample here.
// Later, in `handleAfterSendEvent`, if the replayId is set, we know that we sampled
// And convert the buffer session to a full session
const isErrorEventSampled = shouldSampleForBufferEvent(replay, event);
// When in buffer mode, we decide to sample here.
// Later, in `handleAfterSendEvent`, if the replayId is set, we know that we sampled
// And convert the buffer session to a full session
const isErrorEventSampled = shouldSampleForBufferEvent(replay, event);

// Tag errors if it has been sampled in buffer mode, or if it is session mode
// Only tag transactions if in session mode
const shouldTagReplayId = isErrorEventSampled || replay.recordingMode === 'session';
// Tag errors if it has been sampled in buffer mode, or if it is session mode
// Only tag transactions if in session mode
const shouldTagReplayId = isErrorEventSampled || replay.recordingMode === 'session';

if (shouldTagReplayId) {
event.tags = { ...event.tags, replayId: replay.getSessionId() };
}
if (shouldTagReplayId) {
event.tags = { ...event.tags, replayId: replay.getSessionId() };
}

// In cases where a custom client is used that does not support the new hooks (yet),
// we manually call this hook method here
if (afterSendHandler) {
// Pretend the error had a 200 response so we always capture it
afterSendHandler(event, { statusCode: 200 });
}
// In cases where a custom client is used that does not support the new hooks (yet),
// we manually call this hook method here
if (afterSendHandler) {
// Pretend the error had a 200 response so we always capture it
afterSendHandler(event, { statusCode: 200 });
}

return event;
};
return event;
},
{ id: 'Replay' },
);
}
7 changes: 6 additions & 1 deletion packages/replay/src/util/addGlobalListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ export function addGlobalListeners(replay: ReplayContainer): void {

// Tag all (non replay) events that get sent to Sentry with the current
// replay ID so that we can reference them later in the UI
addGlobalEventProcessor(handleGlobalEventListener(replay, !hasHooks(client)));
const eventProcessor = handleGlobalEventListener(replay, !hasHooks(client));
if (client && client.addEventProcessor) {
client.addEventProcessor(eventProcessor);
} else {
addGlobalEventProcessor(eventProcessor);
}

// If a custom client has no hooks yet, we continue to use the "old" implementation
if (hasHooks(client)) {
Expand Down
1 change: 1 addition & 0 deletions packages/replay/src/util/prepareReplayEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function prepareReplayEvent({
event,
{ event_id, integrations },
scope,
client,
)) as ReplayEvent | null;

// If e.g. a global event processor returned null
Expand Down

0 comments on commit 16a892a

Please sign in to comment.