Skip to content

Improve how eventIDs are created and propogated. #4571

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

Closed
AbhiPrasad opened this issue Feb 14, 2022 · 0 comments
Closed

Improve how eventIDs are created and propogated. #4571

AbhiPrasad opened this issue Feb 14, 2022 · 0 comments
Labels
Package: core Issues related to the Sentry Core SDK
Milestone

Comments

@AbhiPrasad
Copy link
Member

AbhiPrasad commented Feb 14, 2022

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()),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: core Issues related to the Sentry Core SDK
Projects
None yet
Development

No branches or pull requests

2 participants