Skip to content

Commit

Permalink
fix(replay): Ensure circular references are handled (#7752)
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea authored Apr 5, 2023
1 parent c90a60f commit 1d7f18f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/replay/src/coreHandlers/util/addBreadcrumbEvent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EventType } from '@sentry-internal/rrweb';
import type { Breadcrumb } from '@sentry/types';
import { normalize } from '@sentry/utils';

import type { ReplayContainer } from '../../types';
import { addEvent } from '../../util/addEvent';
Expand All @@ -26,7 +27,7 @@ export function addBreadcrumbEvent(replay: ReplayContainer, breadcrumb: Breadcru
timestamp: (breadcrumb.timestamp || 0) * 1000,
data: {
tag: 'breadcrumb',
payload: breadcrumb,
payload: normalize(breadcrumb),
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { BASE_TIMESTAMP } from '../../..';
import { addBreadcrumbEvent } from '../../../../src/coreHandlers/util/addBreadcrumbEvent';
import type { EventBufferArray } from '../../../../src/eventBuffer/EventBufferArray';
import { setupReplayContainer } from '../../../utils/setupReplayContainer';

jest.useFakeTimers();

describe('Unit | coreHandlers | util | addBreadcrumbEvent', function () {
beforeEach(function () {
jest.setSystemTime(BASE_TIMESTAMP);
});

it('handles circular references', async () => {
const breadcrumb: any = {
category: 'console',
message: 'Test message',
thisIsNull: null,
thisIsUndefined: undefined,
timestamp: BASE_TIMESTAMP / 1000,
};
breadcrumb['circular'] = breadcrumb;

const replay = setupReplayContainer();
addBreadcrumbEvent(replay, breadcrumb);

await undefined;
await undefined;
await undefined;
await undefined;
await undefined;

expect((replay.eventBuffer as EventBufferArray).events).toEqual([
{
type: 5,
timestamp: BASE_TIMESTAMP,
data: {
tag: 'breadcrumb',
payload: {
category: 'console',
message: 'Test message',
thisIsNull: null,
thisIsUndefined: '[undefined]',
circular: '[Circular ~]',
timestamp: BASE_TIMESTAMP / 1000,
},
},
},
]);
});
});

0 comments on commit 1d7f18f

Please sign in to comment.