Skip to content

Commit

Permalink
fix(hub): keep hint event id if it's provided (#4577)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doodidan committed Feb 16, 2022
1 parent b122af8 commit a789ccd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/hub/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
27 changes: 27 additions & 0 deletions packages/hub/test/hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).toBe(id);
});

test('should generate hint if not provided in the call', () => {
const testClient = makeClient();
const hub = new Hub(testClient);
Expand All @@ -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).toBe(id);
});

test('should generate hint if not provided in the call', () => {
const testClient = makeClient();
const hub = new Hub(testClient);
Expand Down Expand Up @@ -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).toBe(id);
});

test('sets lastEventId', () => {
const event: Event = {
extra: { b: 3 },
Expand Down

0 comments on commit a789ccd

Please sign in to comment.