Skip to content

Commit a0290b9

Browse files
authored
ref(replay): Improve internal logging (#8740)
This delays adding the internal replay logging breadcrumbs to the next tick, to avoid race conditions on initial logs where replay may not be initialized yet. With this, you should get proper log breadcrumbs in a replay for itself.
1 parent e0e246d commit a0290b9

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

packages/replay/src/replay.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,7 @@ export class ReplayContainer implements ReplayContainerInterface {
11391139
`[Replay] Session duration (${Math.floor(duration / 1000)}s) is too ${
11401140
tooShort ? 'short' : 'long'
11411141
}, not sending replay.`,
1142+
this._options._experiments.traceInternals,
11421143
);
11431144

11441145
if (tooShort) {

packages/replay/src/util/log.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@ export function logInfo(message: string, shouldAddBreadcrumb?: boolean): void {
1212
logger.info(message);
1313

1414
if (shouldAddBreadcrumb) {
15-
const hub = getCurrentHub();
16-
hub.addBreadcrumb(
17-
{
18-
category: 'console',
19-
data: {
20-
logger: 'replay',
15+
// Wait a tick here to avoid race conditions for some initial logs
16+
// which may be added before replay is initialized
17+
setTimeout(() => {
18+
const hub = getCurrentHub();
19+
hub.addBreadcrumb(
20+
{
21+
category: 'console',
22+
data: {
23+
logger: 'replay',
24+
},
25+
level: 'info',
26+
message,
2127
},
22-
level: 'info',
23-
message,
24-
},
25-
{ level: 'info' },
26-
);
28+
{ level: 'info' },
29+
);
30+
}, 0);
2731
}
2832
}

0 commit comments

Comments
 (0)