@saidsef/tracing-node 3.12.1 → 3.12.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/libs/index.mjs +65 -13
- package/package.json +1 -1
package/libs/index.mjs
CHANGED
|
@@ -185,10 +185,17 @@ export function setupTracing(options = {}) {
|
|
|
185
185
|
if (hostname) {
|
|
186
186
|
const peerService = getPeerServiceName(hostname, url);
|
|
187
187
|
|
|
188
|
-
// Set attributes for service graph
|
|
188
|
+
// Set attributes for service graph - CRITICAL for Tempo
|
|
189
189
|
span.setAttribute('peer.service', peerService);
|
|
190
190
|
span.setAttribute('net.peer.name', hostname);
|
|
191
191
|
|
|
192
|
+
// Add db.system for database clients (elasticsearch, redis, etc.)
|
|
193
|
+
if (peerService === 'elasticsearch') {
|
|
194
|
+
span.setAttribute('db.system', 'elasticsearch');
|
|
195
|
+
} else if (peerService === 'redis') {
|
|
196
|
+
span.setAttribute('db.system', 'redis');
|
|
197
|
+
}
|
|
198
|
+
|
|
192
199
|
// Add port if available
|
|
193
200
|
const port = request?.port || request?.options?.port;
|
|
194
201
|
if (port) {
|
|
@@ -309,22 +316,40 @@ export function setupTracing(options = {}) {
|
|
|
309
316
|
}),
|
|
310
317
|
new IORedisInstrumentation({
|
|
311
318
|
requireParentSpan: false,
|
|
312
|
-
requestHook: (span) => {
|
|
319
|
+
requestHook: (span, cmdName, cmdArgs) => {
|
|
313
320
|
// Set peer.service for service graph visualization - CRITICAL for Tempo
|
|
314
|
-
// This must be set in requestHook to ensure it's available for service graph
|
|
315
321
|
span.setAttribute('peer.service', 'redis');
|
|
316
322
|
span.setAttribute('db.system', 'redis');
|
|
317
|
-
|
|
318
|
-
//
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
323
|
+
|
|
324
|
+
// Add command details for better observability
|
|
325
|
+
if (cmdName) {
|
|
326
|
+
span.setAttribute('db.operation', cmdName.toUpperCase());
|
|
327
|
+
span.updateName(`redis.${cmdName.toUpperCase()}`);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Add key information (first argument is usually the key)
|
|
331
|
+
if (cmdArgs && cmdArgs.length > 0) {
|
|
332
|
+
span.setAttribute('db.redis.key', String(cmdArgs[0]));
|
|
333
|
+
|
|
334
|
+
// For operations with multiple keys or complex args
|
|
335
|
+
if (cmdArgs.length > 1) {
|
|
336
|
+
span.setAttribute('db.redis.args_count', cmdArgs.length);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
324
339
|
},
|
|
325
|
-
responseHook: (span) => {
|
|
340
|
+
responseHook: (span, cmdName, cmdArgs, response) => {
|
|
326
341
|
// Ensure peer.service persists through response
|
|
327
342
|
span.setAttribute('peer.service', 'redis');
|
|
343
|
+
|
|
344
|
+
// Log response size if available
|
|
345
|
+
if (response !== undefined && response !== null) {
|
|
346
|
+
const responseType = typeof response;
|
|
347
|
+
span.setAttribute('db.response.type', responseType);
|
|
348
|
+
|
|
349
|
+
if (Array.isArray(response)) {
|
|
350
|
+
span.setAttribute('db.response.count', response.length);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
328
353
|
},
|
|
329
354
|
dbStatementSerializer: (cmdName, cmdArgs) => {
|
|
330
355
|
// Serialize command for better observability (limit arg length to avoid huge spans)
|
|
@@ -337,15 +362,42 @@ export function setupTracing(options = {}) {
|
|
|
337
362
|
}),
|
|
338
363
|
new ElasticsearchInstrumentation({
|
|
339
364
|
suppressInternalInstrumentation: true,
|
|
340
|
-
requestHook: (span) => {
|
|
365
|
+
requestHook: (span, request) => {
|
|
341
366
|
// Set peer.service for service graph visualization - CRITICAL for Tempo
|
|
367
|
+
// This ensures Elasticsearch spans are properly identified
|
|
342
368
|
span.setAttribute('peer.service', 'elasticsearch');
|
|
343
369
|
span.setAttribute('db.system', 'elasticsearch');
|
|
370
|
+
|
|
371
|
+
// Add operation details if available
|
|
372
|
+
if (request?.method) {
|
|
373
|
+
span.setAttribute('db.operation', request.method.toUpperCase());
|
|
374
|
+
}
|
|
344
375
|
},
|
|
345
|
-
responseHook: (span) => {
|
|
376
|
+
responseHook: (span, response) => {
|
|
346
377
|
// Ensure peer.service persists through response
|
|
347
378
|
span.setAttribute('peer.service', 'elasticsearch');
|
|
348
379
|
span.setAttribute('db.system', 'elasticsearch');
|
|
380
|
+
|
|
381
|
+
// Add response details for better observability
|
|
382
|
+
if (response) {
|
|
383
|
+
// Add status code if available
|
|
384
|
+
if (response.statusCode) {
|
|
385
|
+
span.setAttribute('db.response.status_code', response.statusCode);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Add response body size if available
|
|
389
|
+
if (response.body) {
|
|
390
|
+
const bodySize = typeof response.body === 'string'
|
|
391
|
+
? response.body.length
|
|
392
|
+
: JSON.stringify(response.body).length;
|
|
393
|
+
span.setAttribute('db.response.body_size', bodySize);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Add took time if available (Elasticsearch response timing)
|
|
397
|
+
if (response.body?.took) {
|
|
398
|
+
span.setAttribute('db.elasticsearch.took_ms', response.body.took);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
349
401
|
},
|
|
350
402
|
}),
|
|
351
403
|
];
|