From 17384719c5c472e9da4cb151be3ab01aeb4decdd Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 9 Sep 2021 09:15:30 -0400 Subject: [PATCH 1/2] fix(hub): Don't set lastEventID for transactions --- packages/hub/src/hub.ts | 2 +- packages/hub/test/hub.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/hub/src/hub.ts b/packages/hub/src/hub.ts index 84c2650c5311..28d8f8f26157 100644 --- a/packages/hub/src/hub.ts +++ b/packages/hub/src/hub.ts @@ -248,7 +248,7 @@ export class Hub implements HubInterface { * @inheritDoc */ public captureEvent(event: Event, hint?: EventHint): string { - const eventId = (this._lastEventId = uuid4()); + const eventId = event.type === 'transaction' ? uuid4() : (this._lastEventId = uuid4()); 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', () => { From 03ca166a0ccedb60b099574b588e1b067b9977c7 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 9 Sep 2021 09:32:44 -0400 Subject: [PATCH 2/2] Address PR review --- packages/hub/src/hub.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/hub/src/hub.ts b/packages/hub/src/hub.ts index 28d8f8f26157..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 = event.type === 'transaction' ? uuid4() : (this._lastEventId = uuid4()); + const eventId = uuid4(); + if (event.type !== 'transaction') { + this._lastEventId = eventId; + } + this._invokeClient('captureEvent', event, { ...hint, event_id: eventId,