Skip to content

Commit 6994781

Browse files
committed
fix: Set parent_span_id properly
1 parent 7b83155 commit 6994781

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

packages/core/src/log.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,39 +82,35 @@ function valueToAttribute(key: string, value: unknown): LogAttribute {
8282
}
8383
}
8484

85-
let hasRegisteredFlushHook = false;
86-
8785
function addToLogBuffer(client: Client, log: Log, scope: Scope): void {
8886
function sendLogs(flushedLogs: Log[]): void {
8987
const envelope = createLogEnvelope(flushedLogs, client, scope);
9088
// eslint-disable-next-line @typescript-eslint/no-floating-promises
9189
void client.sendEnvelope(envelope);
9290
}
9391

94-
// Only register the hook once
95-
if (!hasRegisteredFlushHook) {
96-
client.on('flush', () => {
92+
function sendAndClearLogs(): void {
93+
if (GLOBAL_LOG_BUFFER.length > 0) {
9794
sendLogs(GLOBAL_LOG_BUFFER);
9895
GLOBAL_LOG_BUFFER = [];
99-
});
100-
hasRegisteredFlushHook = true;
96+
}
10197
}
10298

10399
if (GLOBAL_LOG_BUFFER.length >= LOG_BUFFER_MAX_LENGTH) {
104-
sendLogs(GLOBAL_LOG_BUFFER);
105-
GLOBAL_LOG_BUFFER = [];
100+
sendAndClearLogs();
106101
} else {
107102
GLOBAL_LOG_BUFFER.push(log);
108103
}
109104

110105
// this is the first time logs have been enabled, let's kick off an interval to flush them
111106
// we should only do this once.
112107
if (!isFlushingLogs) {
108+
client.on('flush', () => {
109+
sendAndClearLogs();
110+
});
111+
113112
const flushTimer = setInterval(() => {
114-
if (GLOBAL_LOG_BUFFER.length > 0) {
115-
sendLogs(GLOBAL_LOG_BUFFER);
116-
GLOBAL_LOG_BUFFER = [];
117-
}
113+
sendAndClearLogs();
118114
}, 5000);
119115

120116
// We need to unref the timer in node.js, otherwise the node process never exit.
@@ -180,7 +176,7 @@ export function captureLog({
180176

181177
const span = getActiveSpan();
182178
if (span) {
183-
logAttributes['sentry.trace.parent_span_id'] = spanToJSON(span).parent_span_id;
179+
logAttributes['sentry.trace.parent_span_id'] = span.spanContext().spanId;
184180
}
185181

186182
if (release) {

0 commit comments

Comments
 (0)