Skip to content

Commit

Permalink
fix(hub): Don't set lastEventID for transactions (#3966)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
AbhiPrasad and kamilogorek authored Sep 9, 2021
1 parent 3f74f82 commit 99f9b55
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/hub/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions packages/hub/test/hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 99f9b55

Please sign in to comment.