@nxtedition/lib 18.0.9 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/trace.js +13 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "18.0.9",
3
+ "version": "18.0.10",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
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
- const doc = (typeof obj === 'string' ? obj : stringify(obj)).slice(1, -1)
92
-
93
- traceData += prefix + `${op}", "@timestamp": ${Date.now()}, ${doc} }\n`
94
- if (traceData.length > batch) {
95
- flushTraces()
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