taist 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/trace-reporter.js +10 -3
- package/package.json +1 -1
package/lib/trace-reporter.js
CHANGED
|
@@ -21,6 +21,10 @@ export class TraceReporter extends EventEmitter {
|
|
|
21
21
|
this.flushInterval = options.flushInterval || 1000;
|
|
22
22
|
this.maxRetries = options.maxRetries || 3;
|
|
23
23
|
this.retryDelay = options.retryDelay || 100;
|
|
24
|
+
// Immediate flush mode - sends each trace immediately instead of buffering
|
|
25
|
+
// This is the default to prevent trace loss on process exit
|
|
26
|
+
// Set TAIST_BUFFER_TRACES=true to enable batching for high-throughput scenarios
|
|
27
|
+
this.flushImmediate = options.flushImmediate ?? (process.env.TAIST_BUFFER_TRACES !== 'true');
|
|
24
28
|
|
|
25
29
|
this.buffer = [];
|
|
26
30
|
this.socket = null;
|
|
@@ -32,7 +36,7 @@ export class TraceReporter extends EventEmitter {
|
|
|
32
36
|
this.closed = false;
|
|
33
37
|
this.shuttingDown = false; // Prevents race between shutdown signal and SIGTERM
|
|
34
38
|
|
|
35
|
-
logger.debug("[reporter] Created with socketPath:", this.socketPath);
|
|
39
|
+
logger.debug("[reporter] Created with socketPath:", this.socketPath, "flushImmediate:", this.flushImmediate);
|
|
36
40
|
|
|
37
41
|
// Auto-setup if socket path is available
|
|
38
42
|
if (this.socketPath) {
|
|
@@ -254,8 +258,11 @@ export class TraceReporter extends EventEmitter {
|
|
|
254
258
|
});
|
|
255
259
|
}
|
|
256
260
|
|
|
257
|
-
//
|
|
258
|
-
|
|
261
|
+
// Flush immediately if configured (for spawned processes with unpredictable exit)
|
|
262
|
+
// Otherwise auto-flush when batch size reached
|
|
263
|
+
if (this.flushImmediate) {
|
|
264
|
+
this.flush().catch(() => {});
|
|
265
|
+
} else if (this.buffer.length >= this.batchSize) {
|
|
259
266
|
this.flush().catch(() => {});
|
|
260
267
|
}
|
|
261
268
|
}
|