@sentienguard/apm 1.0.17 → 1.0.19
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 +3 -1
- package/src/traceSpanExporter.js +43 -1
- package/src/tracing.js +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentienguard/apm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"description": "SentienGuard APM SDK - Minimal, production-safe application performance monitoring",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -58,6 +58,8 @@
|
|
|
58
58
|
"@opentelemetry/core": "^2.6.1",
|
|
59
59
|
"@opentelemetry/instrumentation-express": "^0.46.0",
|
|
60
60
|
"@opentelemetry/instrumentation-http": "^0.57.2",
|
|
61
|
+
"@opentelemetry/instrumentation-mongodb": "^0.68.0",
|
|
62
|
+
"@opentelemetry/instrumentation-mongoose": "^0.61.0",
|
|
61
63
|
"@opentelemetry/resources": "^1.30.1",
|
|
62
64
|
"@opentelemetry/sdk-node": "^0.57.2",
|
|
63
65
|
"@opentelemetry/sdk-trace-base": "^1.30.1",
|
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
|
}
|
package/src/tracing.js
CHANGED
|
@@ -10,6 +10,8 @@ import { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_DEPLOYMENT_ENVIRONMENT } from '@o
|
|
|
10
10
|
import { W3CTraceContextPropagator } from '@opentelemetry/core';
|
|
11
11
|
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
|
|
12
12
|
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
|
|
13
|
+
import { MongoDBInstrumentation } from '@opentelemetry/instrumentation-mongodb';
|
|
14
|
+
import { MongooseInstrumentation } from '@opentelemetry/instrumentation-mongoose';
|
|
13
15
|
import { AlwaysOnSampler, BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
14
16
|
import { getConfig, debug } from './config.js';
|
|
15
17
|
import { SentienGuardSpanExporter } from './spanExporter.js';
|
|
@@ -169,6 +171,8 @@ export function startTracing() {
|
|
|
169
171
|
});
|
|
170
172
|
|
|
171
173
|
const expressInstrumentation = new ExpressInstrumentation();
|
|
174
|
+
const mongoInstrumentation = new MongoDBInstrumentation();
|
|
175
|
+
const mongooseInstrumentation = new MongooseInstrumentation();
|
|
172
176
|
|
|
173
177
|
sdk = new NodeSDK({
|
|
174
178
|
resource,
|
|
@@ -176,7 +180,9 @@ export function startTracing() {
|
|
|
176
180
|
// Raw trace export sampling is handled inside SentienGuardTraceSpanExporter instead.
|
|
177
181
|
sampler: new AlwaysOnSampler(),
|
|
178
182
|
textMapPropagator: new W3CTraceContextPropagator(),
|
|
179
|
-
instrumentations
|
|
183
|
+
// Include MongoDB/Mongoose instrumentations for "zero-code" DB spans.
|
|
184
|
+
// These are safe even when the app doesn't use MongoDB; they patch when modules are loaded.
|
|
185
|
+
instrumentations: [httpInstrumentation, expressInstrumentation, mongoInstrumentation, mongooseInstrumentation],
|
|
180
186
|
spanProcessors: [
|
|
181
187
|
new BatchSpanProcessor(metricsExporter),
|
|
182
188
|
new BatchSpanProcessor(traceExporter)
|