Skip to content

Commit

Permalink
Replay cater for event processor returning null (getsentry#6576)
Browse files Browse the repository at this point in the history
Fix an issue in replay's event creation function where an error is thrown if an event processor (called via `client._prepareEvent`) returns null.
  • Loading branch information
timfish authored Dec 21, 2022
1 parent 2794b68 commit 4b19b05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 6 additions & 0 deletions packages/replay/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,12 @@ export class ReplayContainer implements ReplayContainerInterface {
};

const replayEvent = await getReplayEvent({ scope, client, replayId, event: baseEvent });

if (!replayEvent) {
__DEBUG_BUILD__ && logger.error('[Replay] An event processor returned null, will not send replay.');
return;
}

replayEvent.tags = {
...replayEvent.tags,
sessionSampleRate: this._options.sessionSampleRate,
Expand Down
22 changes: 12 additions & 10 deletions packages/replay/src/util/getReplayEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@ export async function getReplayEvent({
scope: Scope;
replayId: string;
event: Event;
}): Promise<Event> {
}): Promise<Event | null> {
// XXX: This event does not trigger `beforeSend` in SDK
// @ts-ignore private api
const preparedEvent: Event = await client._prepareEvent(event, { event_id }, scope);
const preparedEvent: Event | null = await client._prepareEvent(event, { event_id }, scope);

// extract the SDK name because `client._prepareEvent` doesn't add it to the event
const metadata = client.getOptions() && client.getOptions()._metadata;
const { name } = (metadata && metadata.sdk) || {};
if (preparedEvent) {
// extract the SDK name because `client._prepareEvent` doesn't add it to the event
const metadata = client.getOptions() && client.getOptions()._metadata;
const { name } = (metadata && metadata.sdk) || {};

preparedEvent.sdk = {
...preparedEvent.sdk,
version: __SENTRY_REPLAY_VERSION__,
name,
};
preparedEvent.sdk = {
...preparedEvent.sdk,
version: __SENTRY_REPLAY_VERSION__,
name,
};
}

return preparedEvent;
}

0 comments on commit 4b19b05

Please sign in to comment.