-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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(browser): Refactor browser integrations to use processEvent
#9022
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the id for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is used to identify which event processor dropped an event (possibly). It's optional, but figured it's good form to add this for all our own event processors! |
||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually figured this prob. makes sense as
preprocess
, as we may want to generally run this before all other processing, as the other processings may want to access the request?