@nxtedition/lib 18.0.8 → 18.0.10
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/errors.js +1 -1
- package/package.json +1 -1
- package/trace.js +13 -20
package/errors.js
CHANGED
|
@@ -83,7 +83,7 @@ export function serializeError(error) {
|
|
|
83
83
|
message = msg,
|
|
84
84
|
errors,
|
|
85
85
|
code,
|
|
86
|
-
exitCode = /^([A-Z]+|[a-z]+|[0-9]+)$/.test(code) ? code :
|
|
86
|
+
exitCode = /^([A-Z]+|[a-z]+|[0-9]+)$/.test(code) ? code : undefined,
|
|
87
87
|
signal,
|
|
88
88
|
signalCode = signal,
|
|
89
89
|
cause,
|
package/package.json
CHANGED
package/trace.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { Pool } from 'undici'
|
|
2
|
-
|
|
3
|
-
function sleep(n) {
|
|
4
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n)
|
|
5
|
-
}
|
|
2
|
+
import fp from 'lodash/fp.js'
|
|
6
3
|
|
|
7
4
|
export function makeTrace({
|
|
8
5
|
url,
|
|
@@ -43,17 +40,6 @@ export function makeTrace({
|
|
|
43
40
|
const data = traceData
|
|
44
41
|
traceData = ''
|
|
45
42
|
|
|
46
|
-
if (pending > limit / 4) {
|
|
47
|
-
logger.warn('throttling tracing')
|
|
48
|
-
if (pending > limit) {
|
|
49
|
-
sleep(1000)
|
|
50
|
-
} else if (pending > limit / 2) {
|
|
51
|
-
sleep(100)
|
|
52
|
-
} else {
|
|
53
|
-
sleep(10)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
43
|
try {
|
|
58
44
|
pending += data.length
|
|
59
45
|
await client
|
|
@@ -74,6 +60,10 @@ export function makeTrace({
|
|
|
74
60
|
}
|
|
75
61
|
}
|
|
76
62
|
|
|
63
|
+
const warnDrop = fp.throttle(10e3, () => {
|
|
64
|
+
logger.warn('trace dropped')
|
|
65
|
+
})
|
|
66
|
+
|
|
77
67
|
const prefix = `{ "create": { "_index": "trace-${index}" } }\n{ "serviceName": "${serviceName}", "op": "`
|
|
78
68
|
|
|
79
69
|
function trace(obj, op) {
|
|
@@ -88,11 +78,14 @@ export function makeTrace({
|
|
|
88
78
|
throw new Error('invalid property `@timestamp`')
|
|
89
79
|
}
|
|
90
80
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
81
|
+
if (pending > limit) {
|
|
82
|
+
warnDrop()
|
|
83
|
+
} else {
|
|
84
|
+
const doc = (typeof obj === 'string' ? obj : stringify(obj)).slice(1, -1)
|
|
85
|
+
traceData += prefix + `${op}", "@timestamp": ${Date.now()}, ${doc} }\n`
|
|
86
|
+
if (traceData.length > batch) {
|
|
87
|
+
flushTraces()
|
|
88
|
+
}
|
|
96
89
|
}
|
|
97
90
|
}
|
|
98
91
|
|