@nxtedition/lib 23.17.0 → 23.17.2
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/package.json +1 -1
- package/trace.js +7 -18
- package/yield.js +12 -37
package/package.json
CHANGED
package/trace.js
CHANGED
|
@@ -61,40 +61,29 @@ export function makeTrace({
|
|
|
61
61
|
dispatcher: client,
|
|
62
62
|
}).then(({ body }) => body.dump())
|
|
63
63
|
} catch (err) {
|
|
64
|
-
logger.error({ err }, 'trace failed')
|
|
64
|
+
logger.error({ err, data }, 'trace failed')
|
|
65
65
|
} finally {
|
|
66
66
|
pending -= data.length
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
let dropCount = 0
|
|
70
71
|
const warnDrop = fp.throttle(10e3, () => {
|
|
71
|
-
logger.warn('trace dropped')
|
|
72
|
+
logger.warn({ count: dropCount }, 'trace dropped')
|
|
73
|
+
dropCount = 0
|
|
72
74
|
})
|
|
73
75
|
|
|
74
|
-
const prefix = `{
|
|
76
|
+
const prefix = `{"create":{"_index":"trace-${index}"}}\n{`
|
|
75
77
|
|
|
76
78
|
function trace(obj, op) {
|
|
77
|
-
if (typeof obj === 'string') {
|
|
78
|
-
// Do nothing...
|
|
79
|
-
} else {
|
|
80
|
-
if (obj.serviceName) {
|
|
81
|
-
throw new Error('invalid property `serviceName`')
|
|
82
|
-
}
|
|
83
|
-
if (obj.op) {
|
|
84
|
-
throw new Error('invalid property `op`')
|
|
85
|
-
}
|
|
86
|
-
if (obj['@timestamp']) {
|
|
87
|
-
throw new Error('invalid property `@timestamp`')
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
79
|
if (pending > limit) {
|
|
80
|
+
dropCount++
|
|
92
81
|
warnDrop()
|
|
93
82
|
} else {
|
|
94
83
|
const doc = (typeof obj === 'string' ? obj : stringify(obj)).slice(1, -1)
|
|
95
84
|
traceData +=
|
|
96
85
|
prefix +
|
|
97
|
-
`${
|
|
86
|
+
`${doc},"serviceName":"${serviceName}","op":"${op}","pid":${process.pid},"tid":${threadId},"traceId":${genTraceId()},"@timestamp":${Date.now()}}\n`
|
|
98
87
|
if (traceData.length > batch) {
|
|
99
88
|
flushTraces()
|
|
100
89
|
}
|
package/yield.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { FixedQueue } from './fixed-queue.js'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const yieldQueueLength = yieldQueues.length
|
|
5
|
-
|
|
6
|
-
export const PRIORITY_HIGH = 0
|
|
7
|
-
export const PRIORITY_NORMAL = 1
|
|
8
|
-
export const PRIORITY_LOW = 2
|
|
9
|
-
|
|
3
|
+
const yieldQueue = new FixedQueue()
|
|
10
4
|
const yieldSchedule = globalThis.setImmediate ?? ((fn) => setTimeout(fn, 0))
|
|
11
5
|
|
|
12
6
|
let yieldTimeout = 40
|
|
@@ -28,13 +22,13 @@ export function shouldYield() {
|
|
|
28
22
|
return yieldActive
|
|
29
23
|
}
|
|
30
24
|
|
|
31
|
-
export function maybeYield(callback
|
|
25
|
+
export function maybeYield(callback) {
|
|
32
26
|
if (callback != null && typeof callback !== 'function') {
|
|
33
27
|
throw new TypeError('callback must be a function')
|
|
34
28
|
}
|
|
35
29
|
|
|
36
30
|
if (shouldYield()) {
|
|
37
|
-
return doYield(callback
|
|
31
|
+
return doYield(callback)
|
|
38
32
|
}
|
|
39
33
|
|
|
40
34
|
if (callback != null) {
|
|
@@ -44,39 +38,23 @@ export function maybeYield(callback, priority) {
|
|
|
44
38
|
return null
|
|
45
39
|
}
|
|
46
40
|
|
|
47
|
-
export function doYield(
|
|
48
|
-
let callback = callbackOrPriority
|
|
49
|
-
let priority = priorityOrNil
|
|
50
|
-
|
|
51
|
-
if (callbackOrPriority == null) {
|
|
52
|
-
// Do nothing...
|
|
53
|
-
} else if (typeof callbackOrPriority === 'number' && priorityOrNil == null) {
|
|
54
|
-
priority = callbackOrPriority
|
|
55
|
-
callback = null
|
|
56
|
-
} else {
|
|
57
|
-
callback = callbackOrPriority
|
|
58
|
-
}
|
|
59
|
-
|
|
41
|
+
export function doYield(callback) {
|
|
60
42
|
if (callback != null && typeof callback !== 'function') {
|
|
61
43
|
throw new TypeError('callback must be a function')
|
|
62
44
|
}
|
|
63
45
|
|
|
64
|
-
if (priority != null && typeof priority !== 'number') {
|
|
65
|
-
throw new TypeError('priority must be a number')
|
|
66
|
-
}
|
|
67
|
-
|
|
68
46
|
if (!yieldScheduled) {
|
|
69
47
|
yieldScheduled = true
|
|
70
48
|
yieldSchedule(dispatchYield)
|
|
71
49
|
}
|
|
72
50
|
|
|
73
51
|
if (callback != null) {
|
|
74
|
-
|
|
52
|
+
yieldQueue.push(callback)
|
|
75
53
|
return null
|
|
76
54
|
}
|
|
77
55
|
|
|
78
56
|
return new Promise((resolve) => {
|
|
79
|
-
|
|
57
|
+
yieldQueue.push(resolve)
|
|
80
58
|
})
|
|
81
59
|
}
|
|
82
60
|
|
|
@@ -84,17 +62,14 @@ function dispatchYield() {
|
|
|
84
62
|
yieldTime = performance.now()
|
|
85
63
|
yieldActive = false
|
|
86
64
|
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
while (!yieldQueue.isEmpty()) {
|
|
90
|
-
const resolve = yieldQueue.shift()
|
|
65
|
+
while (!yieldQueue.isEmpty()) {
|
|
66
|
+
const resolve = yieldQueue.shift()
|
|
91
67
|
|
|
92
|
-
|
|
68
|
+
resolve(null)
|
|
93
69
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
70
|
+
if (shouldYield()) {
|
|
71
|
+
yieldSchedule(dispatchYield)
|
|
72
|
+
return
|
|
98
73
|
}
|
|
99
74
|
}
|
|
100
75
|
|