Skip to content

Improve how eventIDs are created and propogated. #4571

@AbhiPrasad

Description

@AbhiPrasad

Right now there's a lot of redundancy on how eventIDs are created and used. We can maybe simplify this to reduce bundle size.

hub.captureException first creates an eventID and passes it as a hint.

const eventId = (this._lastEventId = hint && hint.event_id ? hint.event_id : uuid4());

This then calls client.captureException which grabs the eventID from the hint, passes that hint down, overwrites the eventID, and then returns that

let eventId: string | undefined = hint && hint.event_id;
this._process(
this._getBackend()
.eventFromException(exception, hint)
.then(event => this._captureEvent(event, hint, scope))
.then(result => {
eventId = result;
}),
);
return eventId;

eventFromException sets the eventID on the event based on the hint

export function eventFromException(options: Options, exception: unknown, hint?: EventHint): PromiseLike<Event> {
const syntheticException = (hint && hint.syntheticException) || undefined;
const event = eventFromUnknownInput(exception, syntheticException, {
attachStacktrace: options.attachStacktrace,
});
addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
event.level = Severity.Error;
if (hint && hint.event_id) {
event.event_id = hint.event_id;
}
return resolvedSyncPromise(event);
}

client._captureEvent returns the id on the event

protected _captureEvent(event: Event, hint?: EventHint, scope?: Scope): PromiseLike<string | undefined> {
return this._processEvent(event, hint, scope).then(
finalEvent => {
return finalEvent.event_id;
},
reason => {
logger.error(reason);
return undefined;
},
);
}

client._processEvent prepares the event:

return this._prepareEvent(event, scope, hint)

which grabs the event id from the event, the hint, or generates a new one.

event_id: event.event_id || (hint && hint.event_id ? hint.event_id : uuid4()),

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: coreIssues related to the Sentry Core SDK

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions