@saidsef/tracing-node 3.8.4 → 3.10.0

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 (3) hide show
  1. package/README.md +13 -1
  2. package/libs/index.mjs +38 -3
  3. package/package.json +13 -12
package/README.md CHANGED
@@ -9,7 +9,19 @@
9
9
 
10
10
  Get telemetry for your app in less than 3 minutes!
11
11
 
12
- Effortlessly supercharge your applications with world-class distributed tracing! This OpenTelemetry wrapper delivers seamless, lightning-fast observability, empowering developers to monitor, debug, and optimise microservices with ease. Designed for modern cloud-native environments, its the smart choice for engineers who demand reliability, scalability, and actionable insights. Get started in minutes and unlock the full potential of your service architecture—no fuss, just results. This is to make instrumentation (more) idempotent.
12
+ Effortlessly supercharge your applications with world-class distributed tracing! This OpenTelemetry wrapper delivers seamless, lightning-fast observability, empowering developers to monitor, debug, and optimise microservices with ease. Designed for modern cloud-native environments, it's the smart choice for engineers who demand reliability, scalability, and actionable insights. Get started in minutes and unlock the full potential of your service architecture—no fuss, just results. This is to make instrumentation (more) idempotent.
13
+
14
+ ## Features
15
+
16
+ - ✅ HTTP/HTTPS instrumentation with automatic service detection
17
+ - ✅ Express.js framework support
18
+ - ✅ Elasticsearch client instrumentation
19
+ - ✅ IORedis client instrumentation
20
+ - ✅ AWS SDK instrumentation
21
+ - ✅ Pino logger integration with trace/span IDs
22
+ - ✅ Optional DNS and File System instrumentation
23
+ - ✅ Automatic resource detection (host, OS, process, container)
24
+ - ✅ W3C Trace Context propagation
13
25
 
14
26
  ## Prerequisites
15
27
  - NodeJS
package/libs/index.mjs CHANGED
@@ -24,6 +24,7 @@ import {ConnectInstrumentation} from '@opentelemetry/instrumentation-connect';
24
24
  import {diag, DiagConsoleLogger, DiagLogLevel} from '@opentelemetry/api';
25
25
  import {HttpInstrumentation} from '@opentelemetry/instrumentation-http';
26
26
  import {DnsInstrumentation} from '@opentelemetry/instrumentation-dns';
27
+ import {ElasticsearchInstrumentation} from 'opentelemetry-instrumentation-elasticsearch';
27
28
  import {ExpressInstrumentation} from '@opentelemetry/instrumentation-express';
28
29
  import {NodeTracerProvider} from '@opentelemetry/sdk-trace-node';
29
30
  import {OTLPTraceExporter} from '@opentelemetry/exporter-trace-otlp-grpc';
@@ -42,7 +43,9 @@ diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
42
43
  *
43
44
  * This function configures a NodeTracerProvider with various instrumentations
44
45
  * and span processors to enable tracing for the application. It supports
45
- * tracing for HTTP, Express, AWS, Pino, and DNS.
46
+ * tracing for HTTP, Express, AWS, Pino, DNS, Elasticsearch, and IORedis.
47
+ * The IORedis instrumentation includes peer.service attributes for proper
48
+ * service map visualization in distributed tracing tools like Tempo.
46
49
  *
47
50
  * @param {Object} options - Configuration options for tracing.
48
51
  * @param {string} [options.hostname=process.env.HOSTNAME] - The hostname of the service.
@@ -106,14 +109,46 @@ export function setupTracing(options = {}) {
106
109
  return req.url.startsWith('/metrics') || req.url.startsWith('/healthz');
107
110
  };
108
111
 
112
+ // Hook to set peer service name for outgoing requests
113
+ const applyCustomAttributesOnSpan = (span, request) => {
114
+ const url = request?.url || request?.uri || '';
115
+ const hostname = request?.hostname || request?.host || '';
116
+
117
+ // Detect Elasticsearch endpoints
118
+ if (hostname.includes('elasticsearch') || url.includes('elasticsearch') ||
119
+ hostname.includes(':9200') || url.includes(':9200')) {
120
+ span.setAttribute('peer.service', 'elasticsearch');
121
+ span.setAttribute('db.system', 'elasticsearch');
122
+ }
123
+
124
+ // Detect Redis endpoints
125
+ if (hostname.includes('redis') || url.includes('redis') ||
126
+ hostname.includes(':6379') || url.includes(':6379')) {
127
+ span.setAttribute('peer.service', 'redis');
128
+ span.setAttribute('db.system', 'redis');
129
+ }
130
+ };
131
+
109
132
  // Register instrumentations
110
133
  const instrumentations = [
111
- new HttpInstrumentation({serverName: serviceName, ignoreIncomingRequestHook,}),
134
+ new HttpInstrumentation({
135
+ serverName: serviceName,
136
+ ignoreIncomingRequestHook,
137
+ applyCustomAttributesOnSpan,
138
+ }),
112
139
  new ExpressInstrumentation({ ignoreIncomingRequestHook, }),
113
140
  new PinoInstrumentation({logHook: (span, record) => {record['trace_id'] = span.spanContext().traceId;record['span_id'] = span.spanContext().spanId;},}),
114
141
  new ConnectInstrumentation(),
115
142
  new AwsInstrumentation({ sqsExtractContextPropagationFromPayload: true, }),
116
- new IORedisInstrumentation(),
143
+ new IORedisInstrumentation({
144
+ responseHook: (span) => {
145
+ span.setAttribute('peer.service', 'redis');
146
+ },
147
+ requestHook: (span) => {
148
+ span.setAttribute('peer.service', 'redis');
149
+ },
150
+ }),
151
+ new ElasticsearchInstrumentation(),
117
152
  ];
118
153
 
119
154
  if (enableFsInstrumentation) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saidsef/tracing-node",
3
- "version": "3.8.4",
3
+ "version": "3.10.0",
4
4
  "description": "tracing NodeJS - Wrapper for OpenTelemetry instrumentation packages",
5
5
  "main": "libs/index.mjs",
6
6
  "scripts": {
@@ -32,20 +32,21 @@
32
32
  "dependencies": {
33
33
  "@opentelemetry/api": "^1.9.0",
34
34
  "@opentelemetry/context-async-hooks": "^2.0.1",
35
- "@opentelemetry/exporter-trace-otlp-grpc": "^0.206.0",
36
- "@opentelemetry/instrumentation": "^0.206.0",
37
- "@opentelemetry/instrumentation-aws-sdk": "^0.62.0",
38
- "@opentelemetry/instrumentation-connect": "^0.50.0",
39
- "@opentelemetry/instrumentation-dns": "^0.50.0",
40
- "@opentelemetry/instrumentation-express": "^0.55.0",
41
- "@opentelemetry/instrumentation-fs": "^0.26.0",
42
- "@opentelemetry/instrumentation-http": "^0.206.0",
43
- "@opentelemetry/instrumentation-ioredis": "^0.54.0",
44
- "@opentelemetry/instrumentation-pino": "^0.53.0",
35
+ "@opentelemetry/exporter-trace-otlp-grpc": "^0.207.0",
36
+ "@opentelemetry/instrumentation": "^0.207.0",
37
+ "@opentelemetry/instrumentation-aws-sdk": "^0.63.0",
38
+ "@opentelemetry/instrumentation-connect": "^0.51.0",
39
+ "@opentelemetry/instrumentation-dns": "^0.51.0",
40
+ "@opentelemetry/instrumentation-express": "^0.56.0",
41
+ "@opentelemetry/instrumentation-fs": "^0.27.0",
42
+ "@opentelemetry/instrumentation-http": "^0.207.0",
43
+ "@opentelemetry/instrumentation-ioredis": "^0.55.0",
44
+ "@opentelemetry/instrumentation-pino": "^0.54.0",
45
45
  "@opentelemetry/resources": "^2.0.1",
46
46
  "@opentelemetry/sdk-trace-base": "^2.0.0",
47
47
  "@opentelemetry/sdk-trace-node": "^2.0.0",
48
- "@opentelemetry/semantic-conventions": "^1.28.0"
48
+ "@opentelemetry/semantic-conventions": "^1.28.0",
49
+ "opentelemetry-instrumentation-elasticsearch": "^0.41.0"
49
50
  },
50
51
  "devDependencies": {
51
52
  "eslint": "^9.30.0",