From 99f9b5580d80b167e2d833fbc0e22972ab59b016 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 9 Sep 2021 09:54:48 -0400 Subject: [PATCH] fix(hub): Don't set lastEventID for transactions (#3966) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As lastEventID is often just used for UserFeedback, let's not set it when we capture transactions. This is technically a breaking change in terms of behaviour, but we elect to not put this in a major as the previous behaviour was incorrect. Validated with unit tests. Co-authored-by: Kamil Ogórek --- packages/hub/src/hub.ts | 6 +++++- packages/hub/test/hub.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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', () => {