-
-
Couldn't load subscription status.
- Fork 1.7k
Description
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.
sentry-javascript/packages/hub/src/hub.ts
Line 188 in 1bf9883
| 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
sentry-javascript/packages/core/src/baseclient.ts
Lines 115 to 126 in 9e87bf9
| 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
sentry-javascript/packages/browser/src/eventbuilder.ts
Lines 20 to 31 in 9e87bf9
| 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
sentry-javascript/packages/core/src/baseclient.ts
Lines 499 to 509 in 9e87bf9
| 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()), |