@saidsef/tracing-node 6.1.0 → 7.0.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 CHANGED
@@ -26,6 +26,14 @@ Full documentation: [tracing-node.readthedocs.io](https://tracing-node.readthedo
26
26
  npm install @saidsef/tracing-node --save
27
27
  ```
28
28
 
29
+ Elasticsearch spans carrying the query, the operation and the index name need an optional peer dependency:
30
+
31
+ ```shell
32
+ npm install opentelemetry-instrumentation-elasticsearch --save
33
+ ```
34
+
35
+ That package pins `@opentelemetry/core` to the 1.x line, so installing it brings [GHSA-8988-4f7v-96qf](https://github.com/advisories/GHSA-8988-4f7v-96qf) into the dependency tree. Without it, an Elasticsearch call is still traced as an HTTP client span and still appears on the service graph. See [Instrumentation](https://tracing-node.readthedocs.io/en/latest/instrumentation/) for what each option records.
36
+
29
37
  ## Usage
30
38
 
31
39
  ```javascript
package/libs/index.mjs CHANGED
@@ -23,7 +23,6 @@ import {ConnectInstrumentation} from '@opentelemetry/instrumentation-connect';
23
23
  import {diag, DiagConsoleLogger, DiagLogLevel, metrics} from '@opentelemetry/api';
24
24
  import {HttpInstrumentation} from '@opentelemetry/instrumentation-http';
25
25
  import {DnsInstrumentation} from '@opentelemetry/instrumentation-dns';
26
- import {ElasticsearchInstrumentation} from 'opentelemetry-instrumentation-elasticsearch';
27
26
  import {ExpressInstrumentation, ExpressLayerType} from '@opentelemetry/instrumentation-express';
28
27
  import {logs} from '@opentelemetry/api-logs';
29
28
  import {NodeTracerProvider} from '@opentelemetry/sdk-trace-node';
@@ -50,6 +49,21 @@ if (esmHookFailure) {
50
49
  diag.warn(`ESM loader hook not registered, so ES module imports are not instrumented: ${esmHookFailure.message}`);
51
50
  }
52
51
 
52
+ // An optional peer dependency: it pins @opentelemetry/core 1.x, which carries a
53
+ // published advisory. Absent, an Elasticsearch call still gets a client span from
54
+ // the http or undici instrumentation. See #576.
55
+ let ElasticsearchInstrumentation = null;
56
+ try {
57
+ ({ElasticsearchInstrumentation} = await import('opentelemetry-instrumentation-elasticsearch'));
58
+ } catch (error) {
59
+ // Absence is the expected case. An installed but unloadable package would
60
+ // otherwise vanish silently, and tracing must not take the application down.
61
+ if (error?.code !== 'ERR_MODULE_NOT_FOUND') {
62
+ diag.warn('opentelemetry-instrumentation-elasticsearch failed to load:', error);
63
+ }
64
+ }
65
+
66
+
53
67
  // Set a non-negative integer span attribute from a header value; ignore invalid input.
54
68
  const setIntAttribute = (span, name, value) => {
55
69
  if (!value) return;
@@ -116,9 +130,10 @@ let loggerProvider = null;
116
130
  *
117
131
  * This function configures a NodeTracerProvider with various instrumentations
118
132
  * and span processors to enable tracing for the application. It supports
119
- * tracing for HTTP, Express, AWS, Pino, DNS, Elasticsearch, and IORedis.
120
- * The IORedis instrumentation includes peer.service attributes for proper
121
- * service map visualization in distributed tracing tools like Tempo.
133
+ * tracing for HTTP, Express, AWS, Pino, DNS, and IORedis, and for Elasticsearch
134
+ * when the optional opentelemetry-instrumentation-elasticsearch package is
135
+ * installed. The IORedis instrumentation includes peer.service attributes for
136
+ * proper service map visualization in distributed tracing tools like Tempo.
122
137
  *
123
138
  * A MeterProvider is registered alongside it, which is what makes the
124
139
  * instrumentations record the request duration histograms they already
@@ -356,7 +371,7 @@ export function setupTracing(options = {}) {
356
371
  return `${cmdName} ${args.join(' ')}`;
357
372
  },
358
373
  }),
359
- new ElasticsearchInstrumentation(),
374
+ ...(ElasticsearchInstrumentation ? [new ElasticsearchInstrumentation()] : []),
360
375
  // Event loop delay, GC pauses and heap occupancy are metric-only, and they
361
376
  // are what explains a whole service slowing at once. Constructed only with
362
377
  // metrics on, since the collectors start sampling on construction.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saidsef/tracing-node",
3
- "version": "6.1.0",
3
+ "version": "7.0.0",
4
4
  "description": "tracing NodeJS - Wrapper for OpenTelemetry instrumentation packages",
5
5
  "main": "libs/index.mjs",
6
6
  "scripts": {
@@ -54,15 +54,21 @@
54
54
  "@opentelemetry/sdk-trace-base": "^2.11.0",
55
55
  "@opentelemetry/sdk-trace-node": "^2.11.0",
56
56
  "@opentelemetry/semantic-conventions": "^1.43.0",
57
- "import-in-the-middle": "^3.0.0",
58
- "opentelemetry-instrumentation-elasticsearch": "^0.41.0"
57
+ "import-in-the-middle": "^3.0.0"
59
58
  },
60
59
  "devDependencies": {
61
60
  "eslint": "^10.10.0"
62
61
  },
62
+ "peerDependencies": {
63
+ "opentelemetry-instrumentation-elasticsearch": "^0.41.0"
64
+ },
65
+ "peerDependenciesMeta": {
66
+ "opentelemetry-instrumentation-elasticsearch": {
67
+ "optional": true
68
+ }
69
+ },
63
70
  "overrides": {
64
- "protobufjs": "^7.5.3",
65
- "@opentelemetry/core": "^2.11.0"
71
+ "protobufjs": "^7.5.3"
66
72
  },
67
73
  "allowScripts": {
68
74
  "protobufjs@7.6.6": true