From 080efff6b86c68e4a1067c86482c4aad023cf971 Mon Sep 17 00:00:00 2001 From: Gosha Egorian Date: Tue, 15 Feb 2022 19:18:43 +0300 Subject: [PATCH 1/3] feat: keep hint id if it's provided --- packages/hub/src/hub.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/hub/src/hub.ts b/packages/hub/src/hub.ts index 60a3fe8a4c76..851a2161d0fe 100644 --- a/packages/hub/src/hub.ts +++ b/packages/hub/src/hub.ts @@ -185,7 +185,7 @@ export class Hub implements HubInterface { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types public captureException(exception: any, hint?: EventHint): string { - const eventId = (this._lastEventId = uuid4()); + const eventId = (this._lastEventId = hint && hint.event_id ? hint.event_id : uuid4()); let finalHint = hint; // If there's no explicit hint provided, mimic the same thing that would happen @@ -216,7 +216,7 @@ export class Hub implements HubInterface { * @inheritDoc */ public captureMessage(message: string, level?: Severity, hint?: EventHint): string { - const eventId = (this._lastEventId = uuid4()); + const eventId = (this._lastEventId = hint && hint.event_id ? hint.event_id : uuid4()); let finalHint = hint; // If there's no explicit hint provided, mimic the same thing that would happen @@ -247,7 +247,7 @@ export class Hub implements HubInterface { * @inheritDoc */ public captureEvent(event: Event, hint?: EventHint): string { - const eventId = uuid4(); + const eventId = hint && hint.event_id ? hint.event_id : uuid4(); if (event.type !== 'transaction') { this._lastEventId = eventId; } From 29ba7604fc14bd57ce3b5477ee5af54b1e7655e3 Mon Sep 17 00:00:00 2001 From: Gosha Egorian Date: Wed, 16 Feb 2022 09:37:25 +0300 Subject: [PATCH 2/3] fix: add tests for hub (keep event id if provided) --- packages/hub/test/hub.test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/hub/test/hub.test.ts b/packages/hub/test/hub.test.ts index 82c6ab22c987..8561161c2712 100644 --- a/packages/hub/test/hub.test.ts +++ b/packages/hub/test/hub.test.ts @@ -222,6 +222,14 @@ describe('Hub', () => { expect(testClient.captureException.mock.calls[0][1].event_id).toBeTruthy(); }); + test('should keep event_id from hint', () => { + const testClient = makeClient(); + const hub = new Hub(testClient); + const id = Math.random().toString(); + hub.captureException('a', {event_id: id}); + expect(testClient.captureException.mock.calls[0][1].event_id === id).toBeTruthy(); + }); + test('should generate hint if not provided in the call', () => { const testClient = makeClient(); const hub = new Hub(testClient); @@ -248,6 +256,14 @@ describe('Hub', () => { expect(testClient.captureMessage.mock.calls[0][2].event_id).toBeTruthy(); }); + test('should keep event_id from hint', () => { + const testClient = makeClient(); + const hub = new Hub(testClient); + const id = Math.random().toString(); + hub.captureMessage('a', undefined, {event_id: id}); + expect(testClient.captureMessage.mock.calls[0][2].event_id === id).toBeTruthy(); + }); + test('should generate hint if not provided in the call', () => { const testClient = makeClient(); const hub = new Hub(testClient); @@ -279,6 +295,17 @@ describe('Hub', () => { expect(testClient.captureEvent.mock.calls[0][1].event_id).toBeTruthy(); }); + test('should keep event_id from hint', () => { + const event: Event = { + extra: { b: 3 }, + }; + const testClient = makeClient(); + const hub = new Hub(testClient); + const id = Math.random().toString(); + hub.captureEvent(event, {event_id: id}); + expect(testClient.captureEvent.mock.calls[0][1].event_id === id).toBeTruthy(); + }); + test('sets lastEventId', () => { const event: Event = { extra: { b: 3 }, From 66456d5454af1f6559513fb8858c090527c8bc4f Mon Sep 17 00:00:00 2001 From: Gosha Egorian Date: Wed, 16 Feb 2022 16:42:34 +0300 Subject: [PATCH 3/3] fix: tests pattern --- packages/hub/test/hub.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/hub/test/hub.test.ts b/packages/hub/test/hub.test.ts index 8561161c2712..98c8dcea0636 100644 --- a/packages/hub/test/hub.test.ts +++ b/packages/hub/test/hub.test.ts @@ -226,8 +226,8 @@ describe('Hub', () => { const testClient = makeClient(); const hub = new Hub(testClient); const id = Math.random().toString(); - hub.captureException('a', {event_id: id}); - expect(testClient.captureException.mock.calls[0][1].event_id === id).toBeTruthy(); + hub.captureException('a', { event_id: id }); + expect(testClient.captureException.mock.calls[0][1].event_id).toBe(id); }); test('should generate hint if not provided in the call', () => { @@ -260,8 +260,8 @@ describe('Hub', () => { const testClient = makeClient(); const hub = new Hub(testClient); const id = Math.random().toString(); - hub.captureMessage('a', undefined, {event_id: id}); - expect(testClient.captureMessage.mock.calls[0][2].event_id === id).toBeTruthy(); + hub.captureMessage('a', undefined, { event_id: id }); + expect(testClient.captureMessage.mock.calls[0][2].event_id).toBe(id); }); test('should generate hint if not provided in the call', () => { @@ -302,8 +302,8 @@ describe('Hub', () => { const testClient = makeClient(); const hub = new Hub(testClient); const id = Math.random().toString(); - hub.captureEvent(event, {event_id: id}); - expect(testClient.captureEvent.mock.calls[0][1].event_id === id).toBeTruthy(); + hub.captureEvent(event, { event_id: id }); + expect(testClient.captureEvent.mock.calls[0][1].event_id).toBe(id); }); test('sets lastEventId', () => {