@senzops/apm-node 1.2.6 → 1.2.7
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/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/register.js +1 -1
- package/dist/register.js.map +1 -1
- package/dist/register.mjs +1 -1
- package/dist/register.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/transport.ts +22 -9
package/package.json
CHANGED
package/src/core/transport.ts
CHANGED
|
@@ -22,7 +22,8 @@ export class Transport {
|
|
|
22
22
|
private taskErrorQueue: SenzorError[] = [];
|
|
23
23
|
private taskLogQueue: SenzorLog[] = [];
|
|
24
24
|
|
|
25
|
-
private timer:
|
|
25
|
+
private timer: ReturnType<typeof setInterval> | null = null;
|
|
26
|
+
private timerStarted = false;
|
|
26
27
|
private apmEndpoint: string;
|
|
27
28
|
private taskEndpoint: string;
|
|
28
29
|
private isFlushing = false;
|
|
@@ -38,15 +39,26 @@ export class Transport {
|
|
|
38
39
|
? baseEndpoint.replace('/apm', '/task')
|
|
39
40
|
: `${baseEndpoint}/api/ingest/task`;
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
// Timer and shutdown flush are deferred to first enqueue.
|
|
43
|
+
// Cloudflare Workers forbids setInterval / process access in global scope,
|
|
44
|
+
// and init() may be called at module evaluation time (e.g. Nitro plugins).
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private ensureTimer() {
|
|
48
|
+
if (this.timerStarted) return;
|
|
49
|
+
this.timerStarted = true;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
if (typeof setInterval !== 'undefined') {
|
|
53
|
+
this.timer = setInterval(
|
|
54
|
+
() => void this.flush(),
|
|
55
|
+
this.config.flushInterval || 10000
|
|
56
|
+
);
|
|
57
|
+
if (this.timer && typeof (this.timer as any).unref === 'function') {
|
|
58
|
+
(this.timer as any).unref();
|
|
59
|
+
}
|
|
48
60
|
}
|
|
49
|
-
}
|
|
61
|
+
} catch {}
|
|
50
62
|
|
|
51
63
|
this.installShutdownFlush();
|
|
52
64
|
}
|
|
@@ -78,6 +90,7 @@ export class Transport {
|
|
|
78
90
|
}
|
|
79
91
|
|
|
80
92
|
private enqueue<T>(queue: T[], item: T) {
|
|
93
|
+
this.ensureTimer();
|
|
81
94
|
queue.push(item);
|
|
82
95
|
|
|
83
96
|
const maxQueueSize = this.config.maxQueueSize ?? 10000;
|