@@ -82,39 +82,35 @@ function valueToAttribute(key: string, value: unknown): LogAttribute {
82
82
}
83
83
}
84
84
85
- let hasRegisteredFlushHook = false ;
86
-
87
85
function addToLogBuffer ( client : Client , log : Log , scope : Scope ) : void {
88
86
function sendLogs ( flushedLogs : Log [ ] ) : void {
89
87
const envelope = createLogEnvelope ( flushedLogs , client , scope ) ;
90
88
// eslint-disable-next-line @typescript-eslint/no-floating-promises
91
89
void client . sendEnvelope ( envelope ) ;
92
90
}
93
91
94
- // Only register the hook once
95
- if ( ! hasRegisteredFlushHook ) {
96
- client . on ( 'flush' , ( ) => {
92
+ function sendAndClearLogs ( ) : void {
93
+ if ( GLOBAL_LOG_BUFFER . length > 0 ) {
97
94
sendLogs ( GLOBAL_LOG_BUFFER ) ;
98
95
GLOBAL_LOG_BUFFER = [ ] ;
99
- } ) ;
100
- hasRegisteredFlushHook = true ;
96
+ }
101
97
}
102
98
103
99
if ( GLOBAL_LOG_BUFFER . length >= LOG_BUFFER_MAX_LENGTH ) {
104
- sendLogs ( GLOBAL_LOG_BUFFER ) ;
105
- GLOBAL_LOG_BUFFER = [ ] ;
100
+ sendAndClearLogs ( ) ;
106
101
} else {
107
102
GLOBAL_LOG_BUFFER . push ( log ) ;
108
103
}
109
104
110
105
// this is the first time logs have been enabled, let's kick off an interval to flush them
111
106
// we should only do this once.
112
107
if ( ! isFlushingLogs ) {
108
+ client . on ( 'flush' , ( ) => {
109
+ sendAndClearLogs ( ) ;
110
+ } ) ;
111
+
113
112
const flushTimer = setInterval ( ( ) => {
114
- if ( GLOBAL_LOG_BUFFER . length > 0 ) {
115
- sendLogs ( GLOBAL_LOG_BUFFER ) ;
116
- GLOBAL_LOG_BUFFER = [ ] ;
117
- }
113
+ sendAndClearLogs ( ) ;
118
114
} , 5000 ) ;
119
115
120
116
// We need to unref the timer in node.js, otherwise the node process never exit.
@@ -180,7 +176,7 @@ export function captureLog({
180
176
181
177
const span = getActiveSpan ( ) ;
182
178
if ( span ) {
183
- logAttributes [ 'sentry.trace.parent_span_id' ] = spanToJSON ( span ) . parent_span_id ;
179
+ logAttributes [ 'sentry.trace.parent_span_id' ] = span . spanContext ( ) . spanId ;
184
180
}
185
181
186
182
if ( release ) {
0 commit comments