@sentienguard/apm 1.0.17 → 1.0.18
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/src/traceSpanExporter.js +43 -1
package/package.json
CHANGED
package/src/traceSpanExporter.js
CHANGED
|
@@ -10,6 +10,45 @@ import { SpanStatusCode } from '@opentelemetry/api';
|
|
|
10
10
|
import { enqueueSpans } from './traceTransport.js';
|
|
11
11
|
import { getConfig } from './config.js';
|
|
12
12
|
|
|
13
|
+
let debugLogged = 0;
|
|
14
|
+
const DEBUG_LOG_LIMIT = 10;
|
|
15
|
+
|
|
16
|
+
function debugSpanShape(span, serialized, cfg) {
|
|
17
|
+
try {
|
|
18
|
+
if (!cfg?.debug) return;
|
|
19
|
+
if (debugLogged >= DEBUG_LOG_LIMIT) return;
|
|
20
|
+
debugLogged++;
|
|
21
|
+
|
|
22
|
+
const attrObj = serialized?.attributes && typeof serialized.attributes === 'object' ? serialized.attributes : {};
|
|
23
|
+
const keys = Object.keys(attrObj);
|
|
24
|
+
const sample = keys.slice(0, 12).reduce((acc, k) => {
|
|
25
|
+
acc[k] = attrObj[k];
|
|
26
|
+
return acc;
|
|
27
|
+
}, {});
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.log(
|
|
31
|
+
'[SentienGuard APM][trace-debug]',
|
|
32
|
+
JSON.stringify(
|
|
33
|
+
{
|
|
34
|
+
name: serialized?.name,
|
|
35
|
+
kind: serialized?.kind,
|
|
36
|
+
status: serialized?.status?.code,
|
|
37
|
+
trace_id: serialized?.trace_id,
|
|
38
|
+
span_id: serialized?.span_id,
|
|
39
|
+
parent_span_id: serialized?.parent_span_id,
|
|
40
|
+
attributes_count: keys.length,
|
|
41
|
+
attributes_sample: sample
|
|
42
|
+
},
|
|
43
|
+
null,
|
|
44
|
+
0
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
} catch {
|
|
48
|
+
// never break the app
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
13
52
|
function hrTimeToUnixNanoString(hrTime) {
|
|
14
53
|
// hrTime is [seconds, nanoseconds]
|
|
15
54
|
if (!Array.isArray(hrTime) || hrTime.length !== 2) return '';
|
|
@@ -98,7 +137,10 @@ export class SentienGuardTraceSpanExporter {
|
|
|
98
137
|
for (const span of spans) {
|
|
99
138
|
try {
|
|
100
139
|
const s = serializeSpan(span);
|
|
101
|
-
if (s && shouldSampleTraceId(s.trace_id, rate))
|
|
140
|
+
if (s && shouldSampleTraceId(s.trace_id, rate)) {
|
|
141
|
+
debugSpanShape(span, s, cfg);
|
|
142
|
+
serialized.push(s);
|
|
143
|
+
}
|
|
102
144
|
} catch {
|
|
103
145
|
// ignore
|
|
104
146
|
}
|