@watchtowerobservability/node 0.7.9 → 0.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0 (2026-11-16)
4
+
5
+ - `init()` never throws. A missing OpenTelemetry package, a missing key or any startup error logs one `[watchtower] telemetry is OFF` warning (listing every missing package and the install command), leaves every helper a no-op and returns a no-op client, so the app boots. Under pnpm this fixes the crash at the first import of `main.ts`.
6
+ - The OpenTelemetry SDK packages (`context-async-hooks`, `core`, the three OTLP exporters, `otlp-transformer`, `resources`, `sdk-logs`, `sdk-metrics`, `sdk-trace`) are now `dependencies`, not optional peers: `pnpm add @watchtowerobservability/node` is enough. The `instrumentation-*` packages and `winston-transport` stay optional peers.
7
+ - `@watchtowerobservability/node/next` has `edge-light`, `worker` and `browser` conditions pointing at a no-op stub with no `node:*` imports, so `export { register } from '@watchtowerobservability/node/next'` in `instrumentation.ts` builds with no bundler config.
8
+ - Fix (ESM under pnpm): the SDK now looks for its OpenTelemetry packages from its own location in the ESM build too (it only did in CommonJS), which is where pnpm puts its dependencies.
9
+ - Next.js standalone: the SDK names its OpenTelemetry packages literally (`tracedPackages`, never called), so Next's file tracer copies them with their pnpm links. Verified with a pnpm workspace where the app depends only on `@watchtowerobservability/node`, an edge middleware, and `.next/standalone` copied out of the project: `next build` passes and `server.js` starts with no missing-package warning.
10
+
3
11
  ## 0.7.9 (2026-11-16)
4
12
 
5
13
  - Fix (Next.js standalone, pnpm and monorepos; B22, WT-13): `withWatchtower` listed `node_modules/@opentelemetry/**` globs in `outputFileTracingIncludes`. Under pnpm those copied each peer as a plain folder without its own dependencies, or matched nothing when the `.pnpm` store sits at the workspace root, so `init` failed with `missing @opentelemetry/resources`. It now walks the SDK's dependency closure from the app at config time and lists each package's real store folder plus the pnpm links to it, which Next recreates as links. Verified with a pnpm workspace (`apps/web`, `outputFileTracingRoot` at the root, `output: 'standalone'`, peers as direct deps of the app, no peer imports in `instrumentation`): `server.js` starts with no missing-package warning and `wt-next-doctor` exits 0. Your own `outputFileTracingIncludes` are kept. New export: `tracingIncludes(ids, cwd)`.
package/README.md CHANGED
@@ -7,12 +7,10 @@
7
7
  Published on npm:
8
8
 
9
9
  ```sh
10
- npm install @watchtowerobservability/node @opentelemetry/context-async-hooks @opentelemetry/core \
11
- @opentelemetry/exporter-logs-otlp-http @opentelemetry/exporter-metrics-otlp-http @opentelemetry/exporter-trace-otlp-http \
12
- @opentelemetry/otlp-transformer @opentelemetry/resources @opentelemetry/sdk-logs @opentelemetry/sdk-metrics @opentelemetry/sdk-trace
10
+ npm install @watchtowerobservability/node # or: pnpm add @watchtowerobservability/node
13
11
  ```
14
12
 
15
- `@opentelemetry/api` is the only hard dependency; the OpenTelemetry SDK packages above are optional peers (so your app controls their versions) and are loaded by `init`, which throws an error naming the missing ones.
13
+ The OpenTelemetry SDK packages are regular dependencies, so that is enough. `init()` never throws: if a package is missing or startup fails it logs one warning, leaves telemetry off and returns a no-op client. In Next.js, `export { register } from '@watchtowerobservability/node/next'` builds with no bundler config (edge and browser builds get a no-op stub).
16
14
 
17
15
  Optional auto-instrumentation peers (installed ones are used, see below):
18
16
  `npm install @opentelemetry/instrumentation @opentelemetry/instrumentation-http @opentelemetry/instrumentation-undici @opentelemetry/instrumentation-pg @opentelemetry/instrumentation-ioredis`.
@@ -52,7 +50,7 @@ silence it with `instrumentLog: false` or `WT_INSTRUMENT_LOG=0`.
52
50
 
53
51
  Start the preload in the start command: `node --import @watchtowerobservability/node/register app.js` (or `node -r ...` for CommonJS).
54
52
  Do not use `NODE_OPTIONS=--import ...`: it leaks into healthchecks and `pnpm` itself, which cannot resolve the package from the image root.
55
- OpenTelemetry peers are looked up from the SDK's location, then the working directory, then the directory of the entry script, so in a pnpm
53
+ OpenTelemetry packages are looked up from the SDK's location, then the working directory, then the directory of the entry script, so in a pnpm
56
54
  monorepo the app that runs the script is enough.
57
55
 
58
56
  `wt.checkin('nightly-report', async () => { ... })` wraps a cron or scheduler job in check-ins to the monitor with that slug
@@ -116,9 +114,9 @@ registered it re-sends the signal so the exit is unchanged. Under `next start`,
116
114
  the server and calls `process.exit`; our flush starts first (the `register` hook runs before) and gets the time the server takes
117
115
  to close, so a very slow export can still be cut.
118
116
 
119
- Install the OpenTelemetry peers above in the app itself (with pnpm, as direct dependencies). The SDK loads peers at run time through `createRequire`, which webpack does not follow, so a build prints no "Module not found" warning for peers you did not install. Next's standalone file tracer does not follow them either.
117
+ The SDK loads its OpenTelemetry packages at run time through `createRequire`, which webpack does not follow, so a build prints no "Module not found" warning for peers you did not install. Next's standalone file tracer does not follow them either.
120
118
 
121
- Standalone recipe: wrap the config, `module.exports = withWatchtower(nextConfig)` (from `@watchtowerobservability/node/next-build`, or `@watchtowerobservability/next`). It adds the SDK and its OpenTelemetry peers to `serverExternalPackages`, and to `outputFileTracingIncludes` each of them with its dependencies and pnpm links, resolved from the app (npm, pnpm, monorepos with `outputFileTracingRoot` at the workspace root). By hand, add the same packages to `serverExternalPackages` and import each peer literally in `instrumentation.ts`; plain `node_modules/@opentelemetry/**` include globs do not work under pnpm, since they copy each peer without its dependencies. If a peer is missing at run time, `init` logs one warning naming it; after `next build`, `npx wt-next-doctor` checks that `.next/standalone` holds the SDK and its peers and that each one loads from `server.js`, and exits 1 otherwise.
119
+ Standalone recipe: wrap the config, `module.exports = withWatchtower(nextConfig)` (from `@watchtowerobservability/node/next-build`, or `@watchtowerobservability/next`). It adds the SDK and its OpenTelemetry packages to `serverExternalPackages`, and to `outputFileTracingIncludes` each of them with its dependencies and pnpm links, resolved from the app (npm, pnpm, monorepos with `outputFileTracingRoot` at the workspace root). By hand, add the same packages to `serverExternalPackages` and import each peer literally in `instrumentation.ts`; plain `node_modules/@opentelemetry/**` include globs do not work under pnpm, since they copy each peer without its dependencies. If a peer is missing at run time, `init` logs one warning naming it; after `next build`, `npx wt-next-doctor` checks that `.next/standalone` holds the SDK and its peers and that each one loads from `server.js`, and exits 1 otherwise.
122
120
 
123
121
  Bundling with esbuild or webpack (ESM or CommonJS output) works without warnings; mark the peers you use as externals (or ship `node_modules`), because they are resolved at run time. Declarations name optional peers behind `// @ts-ignore`, so `skipLibCheck: false` builds compile without them installed.
124
122
 
@@ -1,8 +1,5 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace';
3
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
4
2
  import type { LogRecordExporter, ReadableLogRecord } from '@opentelemetry/sdk-logs';
5
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
6
3
  import type { AggregationTemporality, InstrumentType, PushMetricExporter, ResourceMetrics } from '@opentelemetry/sdk-metrics';
7
4
  type Done = Parameters<SpanExporter['export']>[1];
8
5
  /** What the spool wraps: a span, log record or metric exporter; `B` is one export batch. */
@@ -1,4 +1,3 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace';
3
2
  export declare function filterExporter(inner: SpanExporter, keep: (s: ReadableSpan) => boolean): SpanExporter;
4
3
  /**
@@ -1,13 +1,9 @@
1
1
  import { inspect } from 'node:util';
2
2
  import { metrics, trace } from '@opentelemetry/api';
3
3
  import type { Tracer } from '@opentelemetry/api';
4
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
5
4
  import type { Resource } from '@opentelemetry/resources';
6
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
7
5
  import type { ReadableSpan, TracerProvider } from '@opentelemetry/sdk-trace';
8
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
9
6
  import type { LoggerProvider } from '@opentelemetry/sdk-logs';
10
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
11
7
  import type { MeterProvider } from '@opentelemetry/sdk-metrics';
12
8
  import type { RedactHook } from './redact.js';
13
9
  import type { RedactPreset } from './redact-presets.js';
@@ -208,6 +204,7 @@ export declare class Client implements InitStatus {
208
204
  observe<A extends unknown[], R>(name: string, fn: (...a: A) => R): (...a: A) => R;
209
205
  shutdown(): Promise<void>;
210
206
  }
207
+ /** Never throws: when a peer is missing, the key is absent or startup fails, it warns once, leaves telemetry off and returns a no-op client. */
211
208
  export declare function init(opts: InitOptions): Client;
212
209
  /** Why telemetry is off (set by the preload when it cannot start); shown on the first dropped helper call. */
213
210
  export declare const setOffReason: (r: string) => void;
package/dist/cjs/index.js CHANGED
@@ -404,11 +404,39 @@ function registerGlobals(c) {
404
404
  api_1.diag.warn(w);
405
405
  }
406
406
  }
407
+ /** A Client-shaped stand-in for when telemetry cannot start: every method does nothing, observe/checkin pass the function through. */
408
+ function offClient() {
409
+ const fns = {
410
+ observe: (_n, f) => f,
411
+ checkin: (_s, f) => Promise.resolve().then(f),
412
+ log: () => undefined,
413
+ toJSON: () => ({}),
414
+ evaluate: () => Promise.resolve([]),
415
+ evaluateResume: () => Promise.resolve([]),
416
+ };
417
+ const plain = { traces: 'disabled', metrics: 'disabled', logs: 'disabled', blocked: [], warnings: [], attached: false };
418
+ return new Proxy({}, { get: (_t, k) => (typeof k === 'symbol' || k === 'then' ? undefined : k in plain ? plain[k] : fns[k] ?? (() => Promise.resolve(undefined))) });
419
+ }
420
+ /** Never throws: when a peer is missing, the key is absent or startup fails, it warns once, leaves telemetry off and returns a no-op client. */
407
421
  function init(opts) {
408
- (0, env_js_1.defaultResourceDetectors)(); // before any NodeSDK reads OTEL_NODE_RESOURCE_DETECTORS
409
422
  const missing = (0, load_js_1.missingPeers)();
410
423
  if (missing.length)
411
- console.warn(`[watchtower] missing OpenTelemetry package(s): ${missing.join(', ')}. Next.js standalone: ${load_js_1.STANDALONE_HINT}. Otherwise: npm install ${missing.join(' ')}`);
424
+ return turnOff(`missing OpenTelemetry package(s): ${missing.join(', ')}. Next.js standalone: ${load_js_1.STANDALONE_HINT}. Otherwise: npm install ${missing.join(' ')}`);
425
+ try {
426
+ return start(opts);
427
+ }
428
+ catch (e) {
429
+ return turnOff(e?.message ?? String(e));
430
+ }
431
+ }
432
+ function turnOff(why) {
433
+ state.current = undefined;
434
+ (0, exports.setOffReason)(why);
435
+ console.warn(`[watchtower] telemetry is OFF: ${why}`);
436
+ return offClient();
437
+ }
438
+ function start(opts) {
439
+ (0, env_js_1.defaultResourceDetectors)(); // before any NodeSDK reads OTEL_NODE_RESOURCE_DETECTORS
412
440
  const nextMode = opts?.nextInternals ?? (process.env.NEXT_RUNTIME ? 'sample' : undefined);
413
441
  if (nextMode) {
414
442
  const own = (0, next_filter_js_1.nextInternalsFilter)(nextMode, opts?.nextInternalsRate);
@@ -0,0 +1,9 @@
1
+ type Opts = Record<string, unknown>;
2
+ export type NextOptions = Opts;
3
+ export type SourcemapOptions = Opts;
4
+ export type TunnelOptions = Opts;
5
+ export declare const makeRegister: (_options?: NextOptions) => (() => Promise<void>);
6
+ export declare const register: () => Promise<void>;
7
+ export declare function onRequestError(_err?: unknown, _request?: unknown, _context?: unknown): Promise<void>;
8
+ export declare const withWatchtower: <T>(config: T, _opts?: Opts) => T;
9
+ export {};
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withWatchtower = exports.register = exports.makeRegister = void 0;
4
+ exports.onRequestError = onRequestError;
5
+ const makeRegister = (_options = {}) => async () => { };
6
+ exports.makeRegister = makeRegister;
7
+ exports.register = (0, exports.makeRegister)();
8
+ async function onRequestError(_err, _request, _context) { }
9
+ const withWatchtower = (config, _opts) => config;
10
+ exports.withWatchtower = withWatchtower;
@@ -2,8 +2,13 @@
2
2
  export declare function searchPaths(): string[];
3
3
  export declare function load(id: string): unknown;
4
4
  export declare const SDK_PEERS: string[];
5
- /** Load an OpenTelemetry SDK package (an optional peer); a missing one throws an error naming what to install. */
5
+ /** Load an OpenTelemetry SDK package (a dependency, loaded lazily); a missing one throws an error naming what to install. */
6
6
  export declare function need<T>(id: string): T;
7
7
  export declare const STANDALONE_HINT = "use withWatchtower() from @watchtowerobservability/next (node SDK 0.7.9 or later) in next.config";
8
8
  /** Required OpenTelemetry peers that cannot be loaded from the SDK's location or the app root. */
9
9
  export declare function missingPeers(): string[];
10
+ /**
11
+ * Never called. Literal names so file tracers (Next's standalone nft) copy the SDK packages together with their pnpm
12
+ * links, which outputFileTracingIncludes cannot do. Safe for bundlers: these are dependencies, so always installed.
13
+ */
14
+ export declare const tracedPackages: () => Promise<unknown>[];
package/dist/cjs/load.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.STANDALONE_HINT = exports.SDK_PEERS = void 0;
6
+ exports.tracedPackages = exports.STANDALONE_HINT = exports.SDK_PEERS = void 0;
7
7
  exports.searchPaths = searchPaths;
8
8
  exports.load = load;
9
9
  exports.need = need;
@@ -42,7 +42,7 @@ exports.SDK_PEERS = [
42
42
  '@opentelemetry/exporter-metrics-otlp-http', '@opentelemetry/exporter-trace-otlp-http', '@opentelemetry/otlp-transformer',
43
43
  '@opentelemetry/resources', '@opentelemetry/sdk-logs', '@opentelemetry/sdk-metrics', '@opentelemetry/sdk-trace',
44
44
  ];
45
- /** Load an OpenTelemetry SDK package (an optional peer); a missing one throws an error naming what to install. */
45
+ /** Load an OpenTelemetry SDK package (a dependency, loaded lazily); a missing one throws an error naming what to install. */
46
46
  function need(id) {
47
47
  try {
48
48
  return load(id);
@@ -67,3 +67,13 @@ function missingPeers() {
67
67
  }
68
68
  });
69
69
  }
70
+ /**
71
+ * Never called. Literal names so file tracers (Next's standalone nft) copy the SDK packages together with their pnpm
72
+ * links, which outputFileTracingIncludes cannot do. Safe for bundlers: these are dependencies, so always installed.
73
+ */
74
+ const tracedPackages = () => [
75
+ import('@opentelemetry/context-async-hooks'), import('@opentelemetry/core'), import('@opentelemetry/exporter-logs-otlp-http'),
76
+ import('@opentelemetry/exporter-metrics-otlp-http'), import('@opentelemetry/exporter-trace-otlp-http'), import('@opentelemetry/otlp-transformer'),
77
+ import('@opentelemetry/resources'), import('@opentelemetry/sdk-logs'), import('@opentelemetry/sdk-metrics'), import('@opentelemetry/sdk-trace'),
78
+ ];
79
+ exports.tracedPackages = tracedPackages;
@@ -1,6 +1,4 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { Resource } from '@opentelemetry/resources';
3
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
4
2
  import type { MeterProvider, PushMetricExporter } from '@opentelemetry/sdk-metrics';
5
3
  /** Explicit flag, else `WATCHTOWER_LOGS` / `WATCHTOWER_METRICS` (default on); `OTEL_*_EXPORTER=none` turns it off. */
6
4
  export declare function switchOn(name: string, otelExporterEnv: string, flag?: boolean): boolean;
@@ -1,4 +1,3 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { ReadableSpan } from '@opentelemetry/sdk-trace';
3
2
  /** Whether `span` is one of Next's internal spans (not a request, route handler, render, server action or fetch). */
4
3
  export declare function isNextInternal(span: ReadableSpan): boolean;
@@ -1,4 +1,3 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { SpanProcessor } from '@opentelemetry/sdk-trace';
3
2
  export interface Frame {
4
3
  file: string;
@@ -1,4 +1,3 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { SpanProcessor } from '@opentelemetry/sdk-trace';
3
2
  export type RedactHook = (key: string, value: unknown) => unknown;
4
3
  /** Hook keys for the non-attribute fields. Event attributes (incl. exception.message / exception.stacktrace) use their own keys. */
@@ -1,5 +1,4 @@
1
1
  import type { Attributes, Context, Link, SpanKind } from '@opentelemetry/api';
2
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
3
2
  import type { Sampler, SamplingResult } from '@opentelemetry/sdk-trace';
4
3
  export interface SamplingRule {
5
4
  name?: string;
@@ -1,4 +1,3 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { SpanProcessor } from '@opentelemetry/sdk-trace';
3
2
  /**
4
3
  * A path segment that looks like a secret: UUID, hex run >= 16, JWT, digit run >= 16, or an opaque token (>= 16 chars of
@@ -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.9";
2
+ export declare const VERSION = "0.8.0";
@@ -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.9';
5
+ exports.VERSION = '0.8.0';
@@ -1,8 +1,5 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace';
3
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
4
2
  import type { LogRecordExporter, ReadableLogRecord } from '@opentelemetry/sdk-logs';
5
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
6
3
  import type { AggregationTemporality, InstrumentType, PushMetricExporter, ResourceMetrics } from '@opentelemetry/sdk-metrics';
7
4
  type Done = Parameters<SpanExporter['export']>[1];
8
5
  /** What the spool wraps: a span, log record or metric exporter; `B` is one export batch. */
@@ -1,4 +1,3 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace';
3
2
  export declare function filterExporter(inner: SpanExporter, keep: (s: ReadableSpan) => boolean): SpanExporter;
4
3
  /**
@@ -1,13 +1,9 @@
1
1
  import { inspect } from 'node:util';
2
2
  import { metrics, trace } from '@opentelemetry/api';
3
3
  import type { Tracer } from '@opentelemetry/api';
4
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
5
4
  import type { Resource } from '@opentelemetry/resources';
6
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
7
5
  import type { ReadableSpan, TracerProvider } from '@opentelemetry/sdk-trace';
8
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
9
6
  import type { LoggerProvider } from '@opentelemetry/sdk-logs';
10
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
11
7
  import type { MeterProvider } from '@opentelemetry/sdk-metrics';
12
8
  import type { RedactHook } from './redact.js';
13
9
  import type { RedactPreset } from './redact-presets.js';
@@ -208,6 +204,7 @@ export declare class Client implements InitStatus {
208
204
  observe<A extends unknown[], R>(name: string, fn: (...a: A) => R): (...a: A) => R;
209
205
  shutdown(): Promise<void>;
210
206
  }
207
+ /** Never throws: when a peer is missing, the key is absent or startup fails, it warns once, leaves telemetry off and returns a no-op client. */
211
208
  export declare function init(opts: InitOptions): Client;
212
209
  /** Why telemetry is off (set by the preload when it cannot start); shown on the first dropped helper call. */
213
210
  export declare const setOffReason: (r: string) => void;
package/dist/esm/index.js CHANGED
@@ -356,11 +356,39 @@ function registerGlobals(c) {
356
356
  diag.warn(w);
357
357
  }
358
358
  }
359
+ /** A Client-shaped stand-in for when telemetry cannot start: every method does nothing, observe/checkin pass the function through. */
360
+ function offClient() {
361
+ const fns = {
362
+ observe: (_n, f) => f,
363
+ checkin: (_s, f) => Promise.resolve().then(f),
364
+ log: () => undefined,
365
+ toJSON: () => ({}),
366
+ evaluate: () => Promise.resolve([]),
367
+ evaluateResume: () => Promise.resolve([]),
368
+ };
369
+ const plain = { traces: 'disabled', metrics: 'disabled', logs: 'disabled', blocked: [], warnings: [], attached: false };
370
+ return new Proxy({}, { get: (_t, k) => (typeof k === 'symbol' || k === 'then' ? undefined : k in plain ? plain[k] : fns[k] ?? (() => Promise.resolve(undefined))) });
371
+ }
372
+ /** Never throws: when a peer is missing, the key is absent or startup fails, it warns once, leaves telemetry off and returns a no-op client. */
359
373
  export function init(opts) {
360
- defaultResourceDetectors(); // before any NodeSDK reads OTEL_NODE_RESOURCE_DETECTORS
361
374
  const missing = missingPeers();
362
375
  if (missing.length)
363
- console.warn(`[watchtower] missing OpenTelemetry package(s): ${missing.join(', ')}. Next.js standalone: ${STANDALONE_HINT}. Otherwise: npm install ${missing.join(' ')}`);
376
+ return turnOff(`missing OpenTelemetry package(s): ${missing.join(', ')}. Next.js standalone: ${STANDALONE_HINT}. Otherwise: npm install ${missing.join(' ')}`);
377
+ try {
378
+ return start(opts);
379
+ }
380
+ catch (e) {
381
+ return turnOff(e?.message ?? String(e));
382
+ }
383
+ }
384
+ function turnOff(why) {
385
+ state.current = undefined;
386
+ setOffReason(why);
387
+ console.warn(`[watchtower] telemetry is OFF: ${why}`);
388
+ return offClient();
389
+ }
390
+ function start(opts) {
391
+ defaultResourceDetectors(); // before any NodeSDK reads OTEL_NODE_RESOURCE_DETECTORS
364
392
  const nextMode = opts?.nextInternals ?? (process.env.NEXT_RUNTIME ? 'sample' : undefined);
365
393
  if (nextMode) {
366
394
  const own = nextInternalsFilter(nextMode, opts?.nextInternalsRate);
@@ -0,0 +1,9 @@
1
+ type Opts = Record<string, unknown>;
2
+ export type NextOptions = Opts;
3
+ export type SourcemapOptions = Opts;
4
+ export type TunnelOptions = Opts;
5
+ export declare const makeRegister: (_options?: NextOptions) => (() => Promise<void>);
6
+ export declare const register: () => Promise<void>;
7
+ export declare function onRequestError(_err?: unknown, _request?: unknown, _context?: unknown): Promise<void>;
8
+ export declare const withWatchtower: <T>(config: T, _opts?: Opts) => T;
9
+ export {};
@@ -0,0 +1,4 @@
1
+ export const makeRegister = (_options = {}) => async () => { };
2
+ export const register = makeRegister();
3
+ export async function onRequestError(_err, _request, _context) { }
4
+ export const withWatchtower = (config, _opts) => config;
@@ -2,8 +2,13 @@
2
2
  export declare function searchPaths(): string[];
3
3
  export declare function load(id: string): unknown;
4
4
  export declare const SDK_PEERS: string[];
5
- /** Load an OpenTelemetry SDK package (an optional peer); a missing one throws an error naming what to install. */
5
+ /** Load an OpenTelemetry SDK package (a dependency, loaded lazily); a missing one throws an error naming what to install. */
6
6
  export declare function need<T>(id: string): T;
7
7
  export declare const STANDALONE_HINT = "use withWatchtower() from @watchtowerobservability/next (node SDK 0.7.9 or later) in next.config";
8
8
  /** Required OpenTelemetry peers that cannot be loaded from the SDK's location or the app root. */
9
9
  export declare function missingPeers(): string[];
10
+ /**
11
+ * Never called. Literal names so file tracers (Next's standalone nft) copy the SDK packages together with their pnpm
12
+ * links, which outputFileTracingIncludes cannot do. Safe for bundlers: these are dependencies, so always installed.
13
+ */
14
+ export declare const tracedPackages: () => Promise<unknown>[];
package/dist/esm/load.js CHANGED
@@ -8,7 +8,7 @@ import nodePath from 'node:path';
8
8
  /** Where peers are searched, in order: the SDK's own location, the cwd, the entry script's directory (pnpm monorepo apps run from the repo root). */
9
9
  export function searchPaths() {
10
10
  const entry = process.argv[1] ? `${nodePath.dirname(nodePath.resolve(process.argv[1]))}/` : '';
11
- return [typeof __filename === 'string' ? __filename : '', `${process.cwd()}/`, entry].filter(Boolean);
11
+ return [String(new URL(import.meta.url)), `${process.cwd()}/`, entry].filter(Boolean);
12
12
  }
13
13
  function resolvers() {
14
14
  return searchPaths().map((f) => createRequire(f));
@@ -32,7 +32,7 @@ export const SDK_PEERS = [
32
32
  '@opentelemetry/exporter-metrics-otlp-http', '@opentelemetry/exporter-trace-otlp-http', '@opentelemetry/otlp-transformer',
33
33
  '@opentelemetry/resources', '@opentelemetry/sdk-logs', '@opentelemetry/sdk-metrics', '@opentelemetry/sdk-trace',
34
34
  ];
35
- /** Load an OpenTelemetry SDK package (an optional peer); a missing one throws an error naming what to install. */
35
+ /** Load an OpenTelemetry SDK package (a dependency, loaded lazily); a missing one throws an error naming what to install. */
36
36
  export function need(id) {
37
37
  try {
38
38
  return load(id);
@@ -57,3 +57,12 @@ export function missingPeers() {
57
57
  }
58
58
  });
59
59
  }
60
+ /**
61
+ * Never called. Literal names so file tracers (Next's standalone nft) copy the SDK packages together with their pnpm
62
+ * links, which outputFileTracingIncludes cannot do. Safe for bundlers: these are dependencies, so always installed.
63
+ */
64
+ export const tracedPackages = () => [
65
+ import('@opentelemetry/context-async-hooks'), import('@opentelemetry/core'), import('@opentelemetry/exporter-logs-otlp-http'),
66
+ import('@opentelemetry/exporter-metrics-otlp-http'), import('@opentelemetry/exporter-trace-otlp-http'), import('@opentelemetry/otlp-transformer'),
67
+ import('@opentelemetry/resources'), import('@opentelemetry/sdk-logs'), import('@opentelemetry/sdk-metrics'), import('@opentelemetry/sdk-trace'),
68
+ ];
@@ -1,6 +1,4 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { Resource } from '@opentelemetry/resources';
3
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
4
2
  import type { MeterProvider, PushMetricExporter } from '@opentelemetry/sdk-metrics';
5
3
  /** Explicit flag, else `WATCHTOWER_LOGS` / `WATCHTOWER_METRICS` (default on); `OTEL_*_EXPORTER=none` turns it off. */
6
4
  export declare function switchOn(name: string, otelExporterEnv: string, flag?: boolean): boolean;
@@ -1,4 +1,3 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { ReadableSpan } from '@opentelemetry/sdk-trace';
3
2
  /** Whether `span` is one of Next's internal spans (not a request, route handler, render, server action or fetch). */
4
3
  export declare function isNextInternal(span: ReadableSpan): boolean;
@@ -1,4 +1,3 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { SpanProcessor } from '@opentelemetry/sdk-trace';
3
2
  export interface Frame {
4
3
  file: string;
@@ -1,4 +1,3 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { SpanProcessor } from '@opentelemetry/sdk-trace';
3
2
  export type RedactHook = (key: string, value: unknown) => unknown;
4
3
  /** Hook keys for the non-attribute fields. Event attributes (incl. exception.message / exception.stacktrace) use their own keys. */
@@ -1,5 +1,4 @@
1
1
  import type { Attributes, Context, Link, SpanKind } from '@opentelemetry/api';
2
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
3
2
  import type { Sampler, SamplingResult } from '@opentelemetry/sdk-trace';
4
3
  export interface SamplingRule {
5
4
  name?: string;
@@ -1,4 +1,3 @@
1
- // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
1
  import type { SpanProcessor } from '@opentelemetry/sdk-trace';
3
2
  /**
4
3
  * A path segment that looks like a secret: UUID, hex run >= 16, JWT, digit run >= 16, or an opaque token (>= 16 chars of
@@ -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.9";
2
+ export declare const VERSION = "0.8.0";
@@ -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.9';
2
+ export const VERSION = '0.8.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@watchtowerobservability/node",
3
- "version": "0.7.9",
3
+ "version": "0.8.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/watchtowerobservability/watchtower-node.git"
@@ -133,6 +133,18 @@
133
133
  }
134
134
  },
135
135
  "./next": {
136
+ "edge-light": {
137
+ "types": "./dist/esm/integrations/next-edge.d.ts",
138
+ "default": "./dist/esm/integrations/next-edge.js"
139
+ },
140
+ "worker": {
141
+ "types": "./dist/esm/integrations/next-edge.d.ts",
142
+ "default": "./dist/esm/integrations/next-edge.js"
143
+ },
144
+ "browser": {
145
+ "types": "./dist/esm/integrations/next-edge.d.ts",
146
+ "default": "./dist/esm/integrations/next-edge.js"
147
+ },
136
148
  "import": {
137
149
  "types": "./dist/esm/integrations/next.d.ts",
138
150
  "default": "./dist/esm/integrations/next.js"
@@ -425,14 +437,19 @@
425
437
  "smoke": "node scripts/smoke-pack.mjs"
426
438
  },
427
439
  "dependencies": {
428
- "@opentelemetry/api": "^1.10.0"
429
- },
430
- "peerDependencies": {
440
+ "@opentelemetry/api": "^1.10.0",
431
441
  "@opentelemetry/context-async-hooks": "^3.1.0",
432
442
  "@opentelemetry/core": "^3.1.0",
433
443
  "@opentelemetry/exporter-logs-otlp-http": "^0.301.0",
434
444
  "@opentelemetry/exporter-metrics-otlp-http": "^0.301.0",
435
445
  "@opentelemetry/exporter-trace-otlp-http": "^0.301.0",
446
+ "@opentelemetry/otlp-transformer": "^0.301.0",
447
+ "@opentelemetry/resources": "^3.1.0",
448
+ "@opentelemetry/sdk-logs": "^3.1.0",
449
+ "@opentelemetry/sdk-metrics": "^3.1.0",
450
+ "@opentelemetry/sdk-trace": "^3.1.0"
451
+ },
452
+ "peerDependencies": {
436
453
  "@opentelemetry/instrumentation": ">=0.200.0",
437
454
  "@opentelemetry/instrumentation-http": ">=0.200.0",
438
455
  "@opentelemetry/instrumentation-ioredis": ">=0.50.0",
@@ -440,29 +457,9 @@
440
457
  "@opentelemetry/instrumentation-pg": ">=0.50.0",
441
458
  "@opentelemetry/instrumentation-runtime-node": ">=0.38.0",
442
459
  "@opentelemetry/instrumentation-undici": ">=0.10.0",
443
- "@opentelemetry/otlp-transformer": "^0.301.0",
444
- "@opentelemetry/resources": "^3.1.0",
445
- "@opentelemetry/sdk-logs": "^3.1.0",
446
- "@opentelemetry/sdk-metrics": "^3.1.0",
447
- "@opentelemetry/sdk-trace": "^3.1.0",
448
460
  "winston-transport": "^4.0.0"
449
461
  },
450
462
  "peerDependenciesMeta": {
451
- "@opentelemetry/context-async-hooks": {
452
- "optional": true
453
- },
454
- "@opentelemetry/core": {
455
- "optional": true
456
- },
457
- "@opentelemetry/exporter-logs-otlp-http": {
458
- "optional": true
459
- },
460
- "@opentelemetry/exporter-metrics-otlp-http": {
461
- "optional": true
462
- },
463
- "@opentelemetry/exporter-trace-otlp-http": {
464
- "optional": true
465
- },
466
463
  "@opentelemetry/instrumentation": {
467
464
  "optional": true
468
465
  },
@@ -484,36 +481,11 @@
484
481
  "@opentelemetry/instrumentation-undici": {
485
482
  "optional": true
486
483
  },
487
- "@opentelemetry/otlp-transformer": {
488
- "optional": true
489
- },
490
- "@opentelemetry/resources": {
491
- "optional": true
492
- },
493
- "@opentelemetry/sdk-logs": {
494
- "optional": true
495
- },
496
- "@opentelemetry/sdk-metrics": {
497
- "optional": true
498
- },
499
- "@opentelemetry/sdk-trace": {
500
- "optional": true
501
- },
502
484
  "winston-transport": {
503
485
  "optional": true
504
486
  }
505
487
  },
506
488
  "devDependencies": {
507
- "@opentelemetry/context-async-hooks": "^3.1.0",
508
- "@opentelemetry/core": "^3.1.0",
509
- "@opentelemetry/exporter-logs-otlp-http": "^0.301.0",
510
- "@opentelemetry/exporter-metrics-otlp-http": "^0.301.0",
511
- "@opentelemetry/exporter-trace-otlp-http": "^0.301.0",
512
- "@opentelemetry/otlp-transformer": "^0.301.0",
513
- "@opentelemetry/resources": "^3.1.0",
514
- "@opentelemetry/sdk-logs": "^3.1.0",
515
- "@opentelemetry/sdk-metrics": "^3.1.0",
516
- "@opentelemetry/sdk-trace": "^3.1.0",
517
489
  "@types/node": "22.15.0",
518
490
  "typescript": "5.7.2",
519
491
  "vitest": "5.0.5",