Skip to content

Commit a789ccd

Browse files
authored
fix(hub): keep hint event id if it's provided (#4577)
1 parent b122af8 commit a789ccd

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

packages/hub/src/hub.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class Hub implements HubInterface {
185185
*/
186186
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
187187
public captureException(exception: any, hint?: EventHint): string {
188-
const eventId = (this._lastEventId = uuid4());
188+
const eventId = (this._lastEventId = hint && hint.event_id ? hint.event_id : uuid4());
189189
let finalHint = hint;
190190

191191
// If there's no explicit hint provided, mimic the same thing that would happen
@@ -216,7 +216,7 @@ export class Hub implements HubInterface {
216216
* @inheritDoc
217217
*/
218218
public captureMessage(message: string, level?: Severity, hint?: EventHint): string {
219-
const eventId = (this._lastEventId = uuid4());
219+
const eventId = (this._lastEventId = hint && hint.event_id ? hint.event_id : uuid4());
220220
let finalHint = hint;
221221

222222
// If there's no explicit hint provided, mimic the same thing that would happen
@@ -247,7 +247,7 @@ export class Hub implements HubInterface {
247247
* @inheritDoc
248248
*/
249249
public captureEvent(event: Event, hint?: EventHint): string {
250-
const eventId = uuid4();
250+
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
251251
if (event.type !== 'transaction') {
252252
this._lastEventId = eventId;
253253
}

packages/hub/test/hub.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ describe('Hub', () => {
222222
expect(testClient.captureException.mock.calls[0][1].event_id).toBeTruthy();
223223
});
224224

225+
test('should keep event_id from hint', () => {
226+
const testClient = makeClient();
227+
const hub = new Hub(testClient);
228+
const id = Math.random().toString();
229+
hub.captureException('a', { event_id: id });
230+
expect(testClient.captureException.mock.calls[0][1].event_id).toBe(id);
231+
});
232+
225233
test('should generate hint if not provided in the call', () => {
226234
const testClient = makeClient();
227235
const hub = new Hub(testClient);
@@ -248,6 +256,14 @@ describe('Hub', () => {
248256
expect(testClient.captureMessage.mock.calls[0][2].event_id).toBeTruthy();
249257
});
250258

259+
test('should keep event_id from hint', () => {
260+
const testClient = makeClient();
261+
const hub = new Hub(testClient);
262+
const id = Math.random().toString();
263+
hub.captureMessage('a', undefined, { event_id: id });
264+
expect(testClient.captureMessage.mock.calls[0][2].event_id).toBe(id);
265+
});
266+
251267
test('should generate hint if not provided in the call', () => {
252268
const testClient = makeClient();
253269
const hub = new Hub(testClient);
@@ -279,6 +295,17 @@ describe('Hub', () => {
279295
expect(testClient.captureEvent.mock.calls[0][1].event_id).toBeTruthy();
280296
});
281297

298+
test('should keep event_id from hint', () => {
299+
const event: Event = {
300+
extra: { b: 3 },
301+
};
302+
const testClient = makeClient();
303+
const hub = new Hub(testClient);
304+
const id = Math.random().toString();
305+
hub.captureEvent(event, { event_id: id });
306+
expect(testClient.captureEvent.mock.calls[0][1].event_id).toBe(id);
307+
});
308+
282309
test('sets lastEventId', () => {
283310
const event: Event = {
284311
extra: { b: 3 },

0 commit comments

Comments
 (0)