@saidsef/tracing-node 3.12.0 → 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.
Files changed (2) hide show
  1. package/libs/index.mjs +63 -23
  2. 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,32 +316,12 @@ export function setupTracing(options = {}) {
309
316
  }),
310
317
  new IORedisInstrumentation({
311
318
  requireParentSpan: false,
312
- responseHook: (span, cmdName, cmdArgs, response) => {
313
- // Set peer.service for service graph visualization
314
- span.setAttribute('peer.service', 'redis');
315
- span.setAttribute('db.system', 'redis');
316
-
317
- // Add command details for better observability
318
- if (cmdName) {
319
- span.setAttribute('db.operation', cmdName.toUpperCase());
320
- }
321
-
322
- // Log response size if available
323
- if (response !== undefined && response !== null) {
324
- const responseType = typeof response;
325
- span.setAttribute('db.response.type', responseType);
326
-
327
- if (Array.isArray(response)) {
328
- span.setAttribute('db.response.count', response.length);
329
- }
330
- }
331
- },
332
319
  requestHook: (span, cmdName, cmdArgs) => {
333
320
  // Set peer.service for service graph visualization - CRITICAL for Tempo
334
321
  span.setAttribute('peer.service', 'redis');
335
322
  span.setAttribute('db.system', 'redis');
336
323
 
337
- // Add command details
324
+ // Add command details for better observability
338
325
  if (cmdName) {
339
326
  span.setAttribute('db.operation', cmdName.toUpperCase());
340
327
  span.updateName(`redis.${cmdName.toUpperCase()}`);
@@ -350,6 +337,20 @@ export function setupTracing(options = {}) {
350
337
  }
351
338
  }
352
339
  },
340
+ responseHook: (span, cmdName, cmdArgs, response) => {
341
+ // Ensure peer.service persists through response
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
+ }
353
+ },
353
354
  dbStatementSerializer: (cmdName, cmdArgs) => {
354
355
  // Serialize command for better observability (limit arg length to avoid huge spans)
355
356
  const args = cmdArgs.map(arg => {
@@ -359,7 +360,46 @@ export function setupTracing(options = {}) {
359
360
  return `${cmdName} ${args.join(' ')}`;
360
361
  },
361
362
  }),
362
- new ElasticsearchInstrumentation(),
363
+ new ElasticsearchInstrumentation({
364
+ suppressInternalInstrumentation: true,
365
+ requestHook: (span, request) => {
366
+ // Set peer.service for service graph visualization - CRITICAL for Tempo
367
+ // This ensures Elasticsearch spans are properly identified
368
+ span.setAttribute('peer.service', 'elasticsearch');
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
+ }
375
+ },
376
+ responseHook: (span, response) => {
377
+ // Ensure peer.service persists through response
378
+ span.setAttribute('peer.service', 'elasticsearch');
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
+ }
401
+ },
402
+ }),
363
403
  ];
364
404
 
365
405
  if (enableFsInstrumentation) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saidsef/tracing-node",
3
- "version": "3.12.0",
3
+ "version": "3.12.2",
4
4
  "description": "tracing NodeJS - Wrapper for OpenTelemetry instrumentation packages",
5
5
  "main": "libs/index.mjs",
6
6
  "scripts": {