Skip to content

Commit 99f9b55

Browse files
fix(hub): Don't set lastEventID for transactions (#3966)
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]>
1 parent 3f74f82 commit 99f9b55

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/hub/src/hub.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ export class Hub implements HubInterface {
248248
* @inheritDoc
249249
*/
250250
public captureEvent(event: Event, hint?: EventHint): string {
251-
const eventId = (this._lastEventId = uuid4());
251+
const eventId = uuid4();
252+
if (event.type !== 'transaction') {
253+
this._lastEventId = eventId;
254+
}
255+
252256
this._invokeClient('captureEvent', event, {
253257
...hint,
254258
event_id: eventId,

packages/hub/test/hub.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,29 @@ describe('Hub', () => {
279279
// @ts-ignore Says mock object is type unknown
280280
expect(spy.mock.calls[0][2].event_id).toBeTruthy();
281281
});
282+
283+
test('sets lastEventId', () => {
284+
const event: Event = {
285+
extra: { b: 3 },
286+
};
287+
const hub = new Hub();
288+
const spy = jest.spyOn(hub as any, '_invokeClient');
289+
hub.captureEvent(event);
290+
// @ts-ignore Says mock object is type unknown
291+
expect(spy.mock.calls[0][2].event_id).toEqual(hub.lastEventId());
292+
});
293+
294+
test('transactions do not set lastEventId', () => {
295+
const event: Event = {
296+
extra: { b: 3 },
297+
type: 'transaction',
298+
};
299+
const hub = new Hub();
300+
const spy = jest.spyOn(hub as any, '_invokeClient');
301+
hub.captureEvent(event);
302+
// @ts-ignore Says mock object is type unknown
303+
expect(spy.mock.calls[0][2].event_id).not.toEqual(hub.lastEventId());
304+
});
282305
});
283306

284307
test('lastEventId should be the same as last created', () => {

0 commit comments

Comments
 (0)