diff --git a/packages/hub/src/hub.ts b/packages/hub/src/hub.ts index 84c2650c5311..2c1f6b297faf 100644 --- a/packages/hub/src/hub.ts +++ b/packages/hub/src/hub.ts @@ -248,7 +248,11 @@ export class Hub implements HubInterface { * @inheritDoc */ public captureEvent(event: Event, hint?: EventHint): string { - const eventId = (this._lastEventId = uuid4()); + const eventId = uuid4(); + if (event.type !== 'transaction') { + this._lastEventId = eventId; + } + this._invokeClient('captureEvent', event, { ...hint, event_id: eventId, diff --git a/packages/hub/test/hub.test.ts b/packages/hub/test/hub.test.ts index 99b2b7623ebd..4e865fa10412 100644 --- a/packages/hub/test/hub.test.ts +++ b/packages/hub/test/hub.test.ts @@ -279,6 +279,29 @@ describe('Hub', () => { // @ts-ignore Says mock object is type unknown expect(spy.mock.calls[0][2].event_id).toBeTruthy(); }); + + test('sets lastEventId', () => { + const event: Event = { + extra: { b: 3 }, + }; + const hub = new Hub(); + const spy = jest.spyOn(hub as any, '_invokeClient'); + hub.captureEvent(event); + // @ts-ignore Says mock object is type unknown + expect(spy.mock.calls[0][2].event_id).toEqual(hub.lastEventId()); + }); + + test('transactions do not set lastEventId', () => { + const event: Event = { + extra: { b: 3 }, + type: 'transaction', + }; + const hub = new Hub(); + const spy = jest.spyOn(hub as any, '_invokeClient'); + hub.captureEvent(event); + // @ts-ignore Says mock object is type unknown + expect(spy.mock.calls[0][2].event_id).not.toEqual(hub.lastEventId()); + }); }); test('lastEventId should be the same as last created', () => {