@saidsef/tracing-node 3.8.4 → 3.9.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.
- package/README.md +13 -1
- package/libs/index.mjs +21 -2
- 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, it
|
|
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,7 @@ 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
|
|
46
|
+
* tracing for HTTP, Express, AWS, Pino, DNS, Elasticsearch, and IORedis.
|
|
46
47
|
*
|
|
47
48
|
* @param {Object} options - Configuration options for tracing.
|
|
48
49
|
* @param {string} [options.hostname=process.env.HOSTNAME] - The hostname of the service.
|
|
@@ -106,14 +107,32 @@ export function setupTracing(options = {}) {
|
|
|
106
107
|
return req.url.startsWith('/metrics') || req.url.startsWith('/healthz');
|
|
107
108
|
};
|
|
108
109
|
|
|
110
|
+
// Hook to set peer service name for outgoing requests
|
|
111
|
+
const applyCustomAttributesOnSpan = (span, request) => {
|
|
112
|
+
const url = request?.url || request?.uri || '';
|
|
113
|
+
const hostname = request?.hostname || request?.host || '';
|
|
114
|
+
|
|
115
|
+
// Detect Elasticsearch endpoints
|
|
116
|
+
if (hostname.includes('elasticsearch') || url.includes('elasticsearch') ||
|
|
117
|
+
hostname.includes(':9200') || url.includes(':9200')) {
|
|
118
|
+
span.setAttribute('peer.service', 'elasticsearch');
|
|
119
|
+
span.setAttribute('db.system', 'elasticsearch');
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
109
123
|
// Register instrumentations
|
|
110
124
|
const instrumentations = [
|
|
111
|
-
new HttpInstrumentation({
|
|
125
|
+
new HttpInstrumentation({
|
|
126
|
+
serverName: serviceName,
|
|
127
|
+
ignoreIncomingRequestHook,
|
|
128
|
+
applyCustomAttributesOnSpan,
|
|
129
|
+
}),
|
|
112
130
|
new ExpressInstrumentation({ ignoreIncomingRequestHook, }),
|
|
113
131
|
new PinoInstrumentation({logHook: (span, record) => {record['trace_id'] = span.spanContext().traceId;record['span_id'] = span.spanContext().spanId;},}),
|
|
114
132
|
new ConnectInstrumentation(),
|
|
115
133
|
new AwsInstrumentation({ sqsExtractContextPropagationFromPayload: true, }),
|
|
116
134
|
new IORedisInstrumentation(),
|
|
135
|
+
new ElasticsearchInstrumentation(),
|
|
117
136
|
];
|
|
118
137
|
|
|
119
138
|
if (enableFsInstrumentation) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saidsef/tracing-node",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.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.
|
|
36
|
-
"@opentelemetry/instrumentation": "^0.
|
|
37
|
-
"@opentelemetry/instrumentation-aws-sdk": "^0.
|
|
38
|
-
"@opentelemetry/instrumentation-connect": "^0.
|
|
39
|
-
"@opentelemetry/instrumentation-dns": "^0.
|
|
40
|
-
"@opentelemetry/instrumentation-express": "^0.
|
|
41
|
-
"@opentelemetry/instrumentation-fs": "^0.
|
|
42
|
-
"@opentelemetry/instrumentation-http": "^0.
|
|
43
|
-
"@opentelemetry/instrumentation-ioredis": "^0.
|
|
44
|
-
"@opentelemetry/instrumentation-pino": "^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",
|