@watchtowerobservability/node 0.7.7 → 0.7.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.8 (2026-11-16)
4
+
5
+ - Fix: on a non-cloud VM the OpenTelemetry resource detectors probed `169.254.169.254` and the 10 s timeout surfaced as a `UND_ERR_CONNECT_TIMEOUT` issue. When `OTEL_NODE_RESOURCE_DETECTORS` is unset, `init()` now sets it to `env,host,os,process`, adding `aws`, `gcp` or `azure` only when an environment variable shows that cloud (for example `AWS_REGION`, `K_SERVICE`, `WEBSITE_SITE_NAME`). Set `OTEL_NODE_RESOURCE_DETECTORS` yourself to override. Call `init()` (or use the `register` preload) before your own `NodeSDK` starts.
6
+ - The http and undici instrumentations ignore requests to cloud metadata endpoints (`169.254.169.254`, `169.254.170.2`, `metadata.google.internal`, `metadata.azure.internal`), so a failed probe is never reported as an error.
7
+
3
8
  ## 0.7.7 (2026-11-16)
4
9
 
5
10
  - Quieter traces by default: `pg-pool.connect`, bare `BEGIN` / `COMMIT` / `ROLLBACK` statement spans and Express middleware layer spans (`middleware - *`, `expressInit`, `query`) are dropped before export; errored spans are always kept. `noisySpans: true` (or `WT_NOISY_SPANS=1`) keeps them. Your own `spanFilter` still runs on what is left.
package/dist/cjs/env.d.ts CHANGED
@@ -20,3 +20,10 @@ export declare function gitHeadSha(from: string): string | undefined;
20
20
  * (`WT_BUILD_STAMP`, `BUILD_STAMP`), then the `.git` HEAD found upward from `gitFrom` (skipped when not given). Empty and `unknown` count as absent.
21
21
  */
22
22
  export declare function resolveRelease(opt: string | undefined, env: NodeJS.ProcessEnv, otelResource: Record<string, string>, gitFrom?: string): string | undefined;
23
+ /** Cloud metadata endpoints; probing them from a non-cloud host times out, so they never become spans or issues. */
24
+ export declare const METADATA_HOSTS: Set<string>;
25
+ /**
26
+ * When OTEL_NODE_RESOURCE_DETECTORS is unset, limit the OTel Node resource detectors to local ones; a cloud detector is added only
27
+ * when an env var shows that cloud. Otherwise the detectors probe 169.254.169.254 and a non-cloud VM waits out a 10 s connect timeout.
28
+ */
29
+ export declare function defaultResourceDetectors(env?: NodeJS.ProcessEnv): void;
package/dist/cjs/env.js CHANGED
@@ -33,10 +33,12 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.METADATA_HOSTS = void 0;
36
37
  exports.parseKv = parseKv;
37
38
  exports.otelEnv = otelEnv;
38
39
  exports.gitHeadSha = gitHeadSha;
39
40
  exports.resolveRelease = resolveRelease;
41
+ exports.defaultResourceDetectors = defaultResourceDetectors;
40
42
  const fs = __importStar(require("node:fs"));
41
43
  const nodePath = __importStar(require("node:path"));
42
44
  // Standard OTEL_* environment variables, used as fallbacks after the WT_* ones.
@@ -132,3 +134,22 @@ function resolveRelease(opt, env, otelResource, gitFrom) {
132
134
  }
133
135
  return gitFrom ? gitHeadSha(gitFrom) : undefined;
134
136
  }
137
+ /** Cloud metadata endpoints; probing them from a non-cloud host times out, so they never become spans or issues. */
138
+ exports.METADATA_HOSTS = new Set(['169.254.169.254', 'metadata.google.internal', '169.254.170.2', 'metadata.azure.internal']);
139
+ /**
140
+ * When OTEL_NODE_RESOURCE_DETECTORS is unset, limit the OTel Node resource detectors to local ones; a cloud detector is added only
141
+ * when an env var shows that cloud. Otherwise the detectors probe 169.254.169.254 and a non-cloud VM waits out a 10 s connect timeout.
142
+ */
143
+ function defaultResourceDetectors(env = process.env) {
144
+ if (env.OTEL_NODE_RESOURCE_DETECTORS)
145
+ return;
146
+ const on = (...k) => k.some((x) => !!env[x]);
147
+ const d = ['env', 'host', 'os', 'process'];
148
+ if (on('AWS_REGION', 'AWS_DEFAULT_REGION', 'AWS_EXECUTION_ENV', 'ECS_CONTAINER_METADATA_URI'))
149
+ d.push('aws');
150
+ if (on('GOOGLE_CLOUD_PROJECT', 'GCP_PROJECT', 'K_SERVICE', 'GAE_SERVICE'))
151
+ d.push('gcp');
152
+ if (on('WEBSITE_SITE_NAME', 'AZURE_FUNCTIONS_ENVIRONMENT', 'AZURE_CLIENT_ID', 'AZURE_TENANT_ID'))
153
+ d.push('azure');
154
+ env.OTEL_NODE_RESOURCE_DETECTORS = d.join(',');
155
+ }
package/dist/cjs/index.js CHANGED
@@ -405,6 +405,7 @@ function registerGlobals(c) {
405
405
  }
406
406
  }
407
407
  function init(opts) {
408
+ (0, env_js_1.defaultResourceDetectors)(); // before any NodeSDK reads OTEL_NODE_RESOURCE_DETECTORS
408
409
  const missing = (0, load_js_1.missingPeers)();
409
410
  if (missing.length)
410
411
  console.warn(`[watchtower] missing OpenTelemetry package(s): ${missing.join(', ')}. Next.js standalone: ${load_js_1.STANDALONE_HINT}. Otherwise: npm install ${missing.join(' ')}`);
@@ -7,19 +7,26 @@ exports.instrumentAll = instrumentAll;
7
7
  const load_js_1 = require("./load.js");
8
8
  const sqlite_js_1 = require("./integrations/sqlite.js");
9
9
  const postgres_js_1 = require("./integrations/postgres.js");
10
+ const env_js_1 = require("./env.js");
10
11
  const util_js_1 = require("./integrations/util.js");
11
12
  /** Instrumentation packages already registered in this process (by `init` or `instrument()`), so none is patched twice. */
12
13
  exports.registered = new Set();
14
+ const hostOf = (o) => { try {
15
+ return new URL(o ?? '').hostname;
16
+ }
17
+ catch {
18
+ return '';
19
+ } };
13
20
  const ENTRIES = [
14
21
  {
15
22
  pkg: '@opentelemetry/instrumentation-http', ctor: 'HttpInstrumentation',
16
23
  // our own exports and API calls must not become spans
17
24
  // routeNamer: server spans become `GET /users/:id` from the matched Express / Nest route (http alone names them just `GET`)
18
- opts: (self) => ({ applyCustomAttributesOnSpan: util_js_1.routeNamer, ignoreOutgoingRequestHook: (r) => self.some((u) => (r.hostname || r.host) === u.hostname && String(r.port ?? (u.protocol === 'https:' ? 443 : 80)) === String(u.port || (u.protocol === 'https:' ? 443 : 80))) }),
25
+ opts: (self) => ({ applyCustomAttributesOnSpan: util_js_1.routeNamer, ignoreOutgoingRequestHook: (r) => env_js_1.METADATA_HOSTS.has(String(r.hostname || r.host).replace(/:\d+$/, '')) || self.some((u) => (r.hostname || r.host) === u.hostname && String(r.port ?? (u.protocol === 'https:' ? 443 : 80)) === String(u.port || (u.protocol === 'https:' ? 443 : 80))) }),
19
26
  },
20
27
  {
21
28
  pkg: '@opentelemetry/instrumentation-undici', ctor: 'UndiciInstrumentation',
22
- opts: (self) => ({ ignoreRequestHook: (r) => self.some((u) => r.origin === u.origin) }),
29
+ opts: (self) => ({ ignoreRequestHook: (r) => env_js_1.METADATA_HOSTS.has(hostOf(r.origin)) || self.some((u) => r.origin === u.origin) }),
23
30
  },
24
31
  { pkg: '@opentelemetry/instrumentation-pg', ctor: 'PgInstrumentation', opts: () => ({}) },
25
32
  { pkg: '@opentelemetry/instrumentation-ioredis', ctor: 'IORedisInstrumentation', opts: () => ({}) },
@@ -1,2 +1,2 @@
1
1
  /** This package's version (test/distro.test.ts checks it against package.json); sent as `telemetry.distro.version`. */
2
- export declare const VERSION = "0.7.7";
2
+ export declare const VERSION = "0.7.8";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  /** This package's version (test/distro.test.ts checks it against package.json); sent as `telemetry.distro.version`. */
5
- exports.VERSION = '0.7.7';
5
+ exports.VERSION = '0.7.8';
package/dist/esm/env.d.ts CHANGED
@@ -20,3 +20,10 @@ export declare function gitHeadSha(from: string): string | undefined;
20
20
  * (`WT_BUILD_STAMP`, `BUILD_STAMP`), then the `.git` HEAD found upward from `gitFrom` (skipped when not given). Empty and `unknown` count as absent.
21
21
  */
22
22
  export declare function resolveRelease(opt: string | undefined, env: NodeJS.ProcessEnv, otelResource: Record<string, string>, gitFrom?: string): string | undefined;
23
+ /** Cloud metadata endpoints; probing them from a non-cloud host times out, so they never become spans or issues. */
24
+ export declare const METADATA_HOSTS: Set<string>;
25
+ /**
26
+ * When OTEL_NODE_RESOURCE_DETECTORS is unset, limit the OTel Node resource detectors to local ones; a cloud detector is added only
27
+ * when an env var shows that cloud. Otherwise the detectors probe 169.254.169.254 and a non-cloud VM waits out a 10 s connect timeout.
28
+ */
29
+ export declare function defaultResourceDetectors(env?: NodeJS.ProcessEnv): void;
package/dist/esm/env.js CHANGED
@@ -93,3 +93,22 @@ export function resolveRelease(opt, env, otelResource, gitFrom) {
93
93
  }
94
94
  return gitFrom ? gitHeadSha(gitFrom) : undefined;
95
95
  }
96
+ /** Cloud metadata endpoints; probing them from a non-cloud host times out, so they never become spans or issues. */
97
+ export const METADATA_HOSTS = new Set(['169.254.169.254', 'metadata.google.internal', '169.254.170.2', 'metadata.azure.internal']);
98
+ /**
99
+ * When OTEL_NODE_RESOURCE_DETECTORS is unset, limit the OTel Node resource detectors to local ones; a cloud detector is added only
100
+ * when an env var shows that cloud. Otherwise the detectors probe 169.254.169.254 and a non-cloud VM waits out a 10 s connect timeout.
101
+ */
102
+ export function defaultResourceDetectors(env = process.env) {
103
+ if (env.OTEL_NODE_RESOURCE_DETECTORS)
104
+ return;
105
+ const on = (...k) => k.some((x) => !!env[x]);
106
+ const d = ['env', 'host', 'os', 'process'];
107
+ if (on('AWS_REGION', 'AWS_DEFAULT_REGION', 'AWS_EXECUTION_ENV', 'ECS_CONTAINER_METADATA_URI'))
108
+ d.push('aws');
109
+ if (on('GOOGLE_CLOUD_PROJECT', 'GCP_PROJECT', 'K_SERVICE', 'GAE_SERVICE'))
110
+ d.push('gcp');
111
+ if (on('WEBSITE_SITE_NAME', 'AZURE_FUNCTIONS_ENVIRONMENT', 'AZURE_CLIENT_ID', 'AZURE_TENANT_ID'))
112
+ d.push('azure');
113
+ env.OTEL_NODE_RESOURCE_DETECTORS = d.join(',');
114
+ }
package/dist/esm/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import { inspect } from 'node:util';
4
4
  import { context, diag, metrics, propagation, trace } from '@opentelemetry/api';
5
5
  import { missingPeers, need as needPeer, STANDALONE_HINT } from './load.js';
6
- import { otelEnv, resolveRelease } from './env.js';
6
+ import { defaultResourceDetectors, otelEnv, resolveRelease } from './env.js';
7
7
  import { dbRequireParent, setHttpServerActive } from './integrations/db.js';
8
8
  import { instrumentAll } from './instrument.js';
9
9
  import { LOG_BODY_KEY, redactor } from './redact.js';
@@ -357,6 +357,7 @@ function registerGlobals(c) {
357
357
  }
358
358
  }
359
359
  export function init(opts) {
360
+ defaultResourceDetectors(); // before any NodeSDK reads OTEL_NODE_RESOURCE_DETECTORS
360
361
  const missing = missingPeers();
361
362
  if (missing.length)
362
363
  console.warn(`[watchtower] missing OpenTelemetry package(s): ${missing.join(', ')}. Next.js standalone: ${STANDALONE_HINT}. Otherwise: npm install ${missing.join(' ')}`);
@@ -2,19 +2,26 @@
2
2
  import { load } from './load.js';
3
3
  import { instrumentBetterSqlite3 } from './integrations/sqlite.js';
4
4
  import { instrumentPostgres } from './integrations/postgres.js';
5
+ import { METADATA_HOSTS } from './env.js';
5
6
  import { routeNamer } from './integrations/util.js';
6
7
  /** Instrumentation packages already registered in this process (by `init` or `instrument()`), so none is patched twice. */
7
8
  export const registered = new Set();
9
+ const hostOf = (o) => { try {
10
+ return new URL(o ?? '').hostname;
11
+ }
12
+ catch {
13
+ return '';
14
+ } };
8
15
  const ENTRIES = [
9
16
  {
10
17
  pkg: '@opentelemetry/instrumentation-http', ctor: 'HttpInstrumentation',
11
18
  // our own exports and API calls must not become spans
12
19
  // routeNamer: server spans become `GET /users/:id` from the matched Express / Nest route (http alone names them just `GET`)
13
- opts: (self) => ({ applyCustomAttributesOnSpan: routeNamer, ignoreOutgoingRequestHook: (r) => self.some((u) => (r.hostname || r.host) === u.hostname && String(r.port ?? (u.protocol === 'https:' ? 443 : 80)) === String(u.port || (u.protocol === 'https:' ? 443 : 80))) }),
20
+ opts: (self) => ({ applyCustomAttributesOnSpan: routeNamer, ignoreOutgoingRequestHook: (r) => METADATA_HOSTS.has(String(r.hostname || r.host).replace(/:\d+$/, '')) || self.some((u) => (r.hostname || r.host) === u.hostname && String(r.port ?? (u.protocol === 'https:' ? 443 : 80)) === String(u.port || (u.protocol === 'https:' ? 443 : 80))) }),
14
21
  },
15
22
  {
16
23
  pkg: '@opentelemetry/instrumentation-undici', ctor: 'UndiciInstrumentation',
17
- opts: (self) => ({ ignoreRequestHook: (r) => self.some((u) => r.origin === u.origin) }),
24
+ opts: (self) => ({ ignoreRequestHook: (r) => METADATA_HOSTS.has(hostOf(r.origin)) || self.some((u) => r.origin === u.origin) }),
18
25
  },
19
26
  { pkg: '@opentelemetry/instrumentation-pg', ctor: 'PgInstrumentation', opts: () => ({}) },
20
27
  { pkg: '@opentelemetry/instrumentation-ioredis', ctor: 'IORedisInstrumentation', opts: () => ({}) },
@@ -1,2 +1,2 @@
1
1
  /** This package's version (test/distro.test.ts checks it against package.json); sent as `telemetry.distro.version`. */
2
- export declare const VERSION = "0.7.7";
2
+ export declare const VERSION = "0.7.8";
@@ -1,2 +1,2 @@
1
1
  /** This package's version (test/distro.test.ts checks it against package.json); sent as `telemetry.distro.version`. */
2
- export const VERSION = '0.7.7';
2
+ export const VERSION = '0.7.8';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@watchtowerobservability/node",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/watchtowerobservability/watchtower-node.git"