@watchtowerobservability/node 0.7.0 → 0.7.1

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 ADDED
@@ -0,0 +1,62 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ## 0.7.1
6
+
7
+ - Fix (bundlers): optional OpenTelemetry peers are no longer named by a literal `require` / `import()`; `load()` uses `createRequire` (from the SDK's location, then the app root), so webpack and Next no longer print "Module not found" for peers you did not install or a "Critical dependency" warning. Install the peers you use as direct dependencies of the app (for a Next standalone build add them to `outputFileTracingIncludes` if the tracer misses one).
8
+ - Fix (types): emitted `.d.ts` files mark every optional-peer import with `// @ts-ignore`, so `tsc` with `skipLibCheck: false` no longer fails with TS2307 when a peer is not installed (the type is `any` then, the real type when installed). `scripts/dts-peers.mjs` does it at build time; `test/dts-peers.test.ts` checks it.
9
+ - Fix: the `register` preload no longer prints Node 26's `DEP0205` (`module.register()`) deprecation warning.
10
+
11
+ ## 0.7.0
12
+
13
+ - URL scrubbing on by default (`urlScrubbing: false` to opt out): a span processor drops the query string, removes `url.query` and replaces secret-looking path segments (>= 24 chars, or >= 10 chars with a letter and a digit; UUIDs too) with `:redacted` in `http.target`, `url.full`, `url.path`, `http.url` and URLs in span names, on every span including Next.js, http and fetch spans. `http.route` is kept. README no longer claims query strings are "never recorded" without saying how. Behaviour change: URLs that carried long ids now show `:redacted`.
14
+ - SQL summaries: `CREATE TABLE IF NOT EXISTS forms` is `CREATE TABLE forms`, `CREATE [UNIQUE] INDEX x ON forms` is `CREATE INDEX forms` (TEMP and VIRTUAL too); `DROP TABLE IF EXISTS` no longer reports `IF`. `db.operation.name` is `CREATE TABLE` / `CREATE INDEX` for these.
15
+ - `DbOptions.requireParent` (default true, `WATCHTOWER_DB_REQUIRE_PARENT=0` to turn off): datastore spans are recorded only under an active span, which keeps startup DDL, migrations and polling loops out. **Behaviour change** for every datastore integration and postgres.js: queries run outside any span used to become root traces and no longer do; pass `requireParent: false` to restore that.
16
+ - Resource attributes `telemetry.sdk.name/language/version` (from the OTel SDK) and `telemetry.distro.name=watchtower`, `telemetry.distro.version`. They were never set before (a bare resource was built; nothing stripped them), so the coverage report showed no SDK.
17
+ - `/next`: `nextInternals: 'drop' | 'sample' | 'keep'` (default `'sample'` at `nextInternalsRate` 0.1) for Next's internal spans (`next.span_type`); request, route-handler, render, server-action, fetch, SERVER/CLIENT and errored spans are kept. New `spanFilter` init option.
18
+ - `/next`: `withWatchtower(nextConfig, { sourcemaps })` (turns on `productionBrowserSourceMaps`), `uploadSourcemaps()` and the `wt-next-sourcemaps` bin (uploads `.next/static` maps with `WT_API_KEY` (scope `ci:write`), `WT_PROJECT`, `WT_RELEASE`, then deletes them), and `tunnelHandler({ endpoint })` for a first-party `app/api/wt/[...path]/route.ts` that forwards only the browser RUM paths.
19
+ - `instrument: 'auto'` (or `WT_INSTRUMENT=auto`): also patches postgres.js, better-sqlite3 and mysql2 (new optional peer `@opentelemetry/instrumentation-mysql2`) when installed and logs one line naming what was patched (`instrumentLog: false` / `WT_INSTRUMENT_LOG=0`).
20
+ - `wt.checkin(monitorSlug, fn)` cron helper over `POST /v1/checkins/{slug}` (key scope `ingest:checkins`).
21
+ - `init` now flushes on SIGTERM and SIGINT (2 s cap) and re-sends the signal when no other handler is registered. Not done before: a SIGTERM exited without flushing. Under `next start` Next's own handler still decides the exit.
22
+
23
+ ## 0.6.0
24
+
25
+ - Fix: the ESM build was unimportable (`dist/esm/load.js` lacked `need`). The ESM loader is now the compiled `load.ts` with a `createRequire`; `npm run smoke` packs, installs and imports both builds.
26
+ - Bundling: OpenTelemetry peers are required by literal name inside try blocks, so webpack, esbuild and Next's file tracer can follow them. README has a Next.js recipe.
27
+ - `redact` now also runs on span names (`span.name`), status messages (`status.message`), every span event's and link's attributes (including `exception.message` / `exception.stacktrace`) and log bodies (`log.body`). `@watchtowerobservability/node/next` exports `makeRegister(options)`; `register` is unchanged.
28
+ - `init` no longer disables the OpenTelemetry globals: it registers only those not yet set (a warning says when one was kept) and tears down only what an earlier `init` installed.
29
+ - Passing `exporter` no longer turns off the default log and metric exporters (use `logs: false` / `metrics: false`); an explicit `logExporter` / `metricExporter` turns its signal on and logs always go through a batch processor.
30
+ - Auto-instrumentation: `instrument` option (default on) for installed `@opentelemetry/instrumentation-{http,undici,pg,ioredis}` optional peers, and a `@watchtowerobservability/node/register` preload entry.
31
+ - `OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_EXPORTER_OTLP_HEADERS`, `OTEL_SERVICE_NAME` and `OTEL_RESOURCE_ATTRIBUTES` are read after the `WT_*` variables; `service.version` from `OTEL_RESOURCE_ATTRIBUTES` is the release.
32
+ - README: npm install instructions (no token, no tarball).
33
+
34
+ ## 0.5.0
35
+
36
+ - `@opentelemetry/api` is now the only hard dependency. The SDK packages (`sdk-trace`, `sdk-logs`, `sdk-metrics`, `resources`, `core`, `context-async-hooks`, `otlp-transformer` and the three OTLP/HTTP exporters) are optional peer dependencies, loaded when `init` runs; if one is missing, `init` throws an error that lists what to `npm install`. Install them next to the SDK (see the README). Same ranges as before (SDK 3.1, exporters 0.301).
37
+
38
+ - OpenTelemetry moves to the current majors: API 1.10, SDK packages 3.1 (`sdk-trace`, `sdk-metrics`, `sdk-logs`, `resources`, `core`) and the 0.301 exporters, replacing the 1.30 / 0.57 stack. Node 22.15 or newer is required (the OTel 3.x packages need it). `NodeTracerProvider` is gone upstream, so `init` registers the async-hooks context manager, the W3C propagators and the tracer provider itself; `Client.provider` is now an SDK `TracerProvider` and `Client.resource` is new. A span's parent is `parentSpanContext?.spanId` (was `parentSpanId`). The optional peer `@opentelemetry/instrumentation-runtime-node` is `>=0.38`.
39
+
40
+ - Datastores and queues: new subpaths `sql` (shared SQL normalizer and `db.query.hash`, same as the server), `sqlite` (node:sqlite, better-sqlite3, sqlite3, libSQL), `duckdb`, `lmdb`, `level` (LevelDB/RocksDB), `cache` (node-cache, lru-cache, Keyv hit/miss), `pools` (MongoDB, mysql2, any pool), `orm` (Drizzle, Kysely, TypeORM, Sequelize, MikroORM), `amqp` (amqplib, rabbitmq-client), `nats`, `mqtt`, `pg-boss`, `graphile-worker`. SQL spans carry an N+1 hint (`db.n_plus_one`, `db.query.repeat_count`); statement text is opt-in (`queryText` / `WATCHTOWER_DB_QUERY_TEXT=1`) and literal-free. postgres.js spans gain `db.query.hash`; `querySummary` also returns `target`.
41
+ - Metrics: the OTel metrics SDK with a periodic OTLP reader (delta temporality by default), set as the global meter provider by `init`; runtime metrics through the optional peer `@opentelemetry/instrumentation-runtime-node`; spooled to `bufferDir/metrics`. `WATCHTOWER_LOGS` / `WATCHTOWER_METRICS` (or `logs` / `metrics` options) switch the two signals, default on.
42
+
43
+ - GenAI: `instrumentMistral`, `instrumentOllama`, `instrumentLlamaIndex(Settings)` and `instrumentOpenAIAgents(addTraceProcessor)`. Streams (`stream: true`, Mistral `chat.stream`) keep the span open until the stream ends and record time to first chunk, usage and finish reasons; tool calls become `gen_ai.tool.call` span events (name and id only) for every wrapper.
44
+ - Offline buffer: log records are spooled too. `bufferDir` now holds `traces/` and `logs/` subdirectories (at most 500 batches each, oldest dropped, replayed oldest first before the next export); batches spooled by older versions in the root of `bufferDir` are not replayed.
45
+ - GenAI: `instrumentBedrock` (Converse/InvokeModel via `send`), `instrumentGoogleGenAI` (`models.generateContent`, Gemini or Vertex AI) and a gateway name for `instrumentOpenAI(client, 'litellm')`.
46
+
47
+ ## 0.2.0
48
+
49
+ - TypeScript source with generated type declarations; dual ESM and CommonJS build (`dist/esm`, `dist/cjs`).
50
+ - No API change: same exports, subpaths, options, environment variables and behavior.
51
+ - New: the `jest` and `vitest` reporter subpaths now ship types.
52
+
53
+ ## 0.1.0
54
+
55
+ - Init over the OpenTelemetry Node SDK: key header, `WT_OTLP_ENDPOINT`, offline buffer, redaction hook.
56
+ - Configuration from `WT_INGEST_KEY`, `WT_SERVICE`, `WT_ENVIRONMENT`, `WT_RELEASE`.
57
+ - Error capture: `captureException`, `uncaughtException` and `unhandledRejection` hooks, trace ids returned.
58
+ - OTLP logs (`log`) with pino and winston bridges.
59
+ - Integrations: express, fastify, koa, nestjs, next.js (instrumentation hook), prisma, AWS Lambda wrapper,
60
+ openai, anthropic and Vercel AI SDK GenAI spans.
61
+ - Jest and Vitest reporters, prompts, scores, evals.
62
+ - The key is masked in `console.log` and `JSON.stringify` output of the client.
package/README.md CHANGED
@@ -99,9 +99,9 @@ registered it re-sends the signal so the exit is unchanged. Under `next start`,
99
99
  the server and calls `process.exit`; our flush starts first (the `register` hook runs before) and gets the time the server takes
100
100
  to close, so a very slow export can still be cut.
101
101
 
102
- Install the OpenTelemetry peers above in the app itself (with pnpm, as direct dependencies, so Next's standalone tracer copies them). The SDK requires each peer by its literal name, so webpack and Next's file tracer can follow them; if the SDK arrives through a transpiled workspace package, add it to `transpilePackages`. Add `outputFileTracingIncludes` for the peers only if the standalone build still reports a missing `@opentelemetry/*` package.
102
+ 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: add the peers you use to `outputFileTracingIncludes` (for example `{ '/*': ['./node_modules/@opentelemetry/**'] }`).
103
103
 
104
- Bundling with esbuild or webpack (ESM or CommonJS output) works: both the CommonJS and ESM builds name every optional peer with a literal `require`/`import()` inside try, so the bundler follows the peers you have installed and skips the rest.
104
+ 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.
105
105
 
106
106
  ## Integrations
107
107
 
@@ -1,5 +1,8 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace';
3
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
4
  import type { LogRecordExporter, ReadableLogRecord } from '@opentelemetry/sdk-logs';
5
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
3
6
  import type { AggregationTemporality, InstrumentType, PushMetricExporter, ResourceMetrics } from '@opentelemetry/sdk-metrics';
4
7
  type Done = Parameters<SpanExporter['export']>[1];
5
8
  /** What the spool wraps: a span, log record or metric exporter; `B` is one export batch. */
@@ -1,2 +1,3 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace';
2
3
  export declare function filterExporter(inner: SpanExporter, keep: (s: ReadableSpan) => boolean): SpanExporter;
@@ -1,9 +1,13 @@
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)
4
5
  import type { Resource } from '@opentelemetry/resources';
6
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
5
7
  import type { ReadableSpan, TracerProvider } from '@opentelemetry/sdk-trace';
8
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
6
9
  import type { LoggerProvider } from '@opentelemetry/sdk-logs';
10
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
7
11
  import type { MeterProvider } from '@opentelemetry/sdk-metrics';
8
12
  import { captureException } from './errors.js';
9
13
  import type { CaptureContext } from './errors.js';
@@ -1,3 +1,4 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { ReadableSpan } from '@opentelemetry/sdk-trace';
2
3
  import * as wt from '../index.js';
3
4
  export { withWatchtower, uploadSourcemaps } from './next-build.js';
package/dist/cjs/load.js CHANGED
@@ -2,45 +2,29 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.load = load;
4
4
  exports.need = need;
5
- // Optional-peer loader. Each peer is required by a LITERAL name inside a try block so bundlers (webpack, esbuild, Next's
6
- // file tracer) can follow it; a computed `require(name)` is invisible to them. This is the CommonJS form;
7
- // scripts/build.mjs prepends `const require = createRequire(import.meta.url)` for dist/esm (webpack follows that too).
8
- // The cwd fallback only matters when `require` does not exist (test runners running the TS source as ESM).
5
+ // Optional-peer loader (same source for the CommonJS and ESM builds).
9
6
  const node_module_1 = require("node:module");
10
- const NONE = Symbol('not a known peer');
11
- function known(id) {
12
- try { // bundlers only tolerate an optional require that is lexically inside try
13
- switch (id) {
14
- case '@opentelemetry/context-async-hooks': return require('@opentelemetry/context-async-hooks');
15
- case '@opentelemetry/core': return require('@opentelemetry/core');
16
- case '@opentelemetry/exporter-logs-otlp-http': return require('@opentelemetry/exporter-logs-otlp-http');
17
- case '@opentelemetry/exporter-metrics-otlp-http': return require('@opentelemetry/exporter-metrics-otlp-http');
18
- case '@opentelemetry/exporter-trace-otlp-http': return require('@opentelemetry/exporter-trace-otlp-http');
19
- case '@opentelemetry/otlp-transformer': return require('@opentelemetry/otlp-transformer');
20
- case '@opentelemetry/resources': return require('@opentelemetry/resources');
21
- case '@opentelemetry/sdk-logs': return require('@opentelemetry/sdk-logs');
22
- case '@opentelemetry/sdk-metrics': return require('@opentelemetry/sdk-metrics');
23
- case '@opentelemetry/sdk-trace': return require('@opentelemetry/sdk-trace');
24
- case '@opentelemetry/instrumentation-runtime-node': return require('@opentelemetry/instrumentation-runtime-node');
25
- case '@opentelemetry/instrumentation': return require('@opentelemetry/instrumentation');
26
- case '@opentelemetry/instrumentation-http': return require('@opentelemetry/instrumentation-http');
27
- case '@opentelemetry/instrumentation-undici': return require('@opentelemetry/instrumentation-undici');
28
- case '@opentelemetry/instrumentation-pg': return require('@opentelemetry/instrumentation-pg');
29
- case '@opentelemetry/instrumentation-ioredis': return require('@opentelemetry/instrumentation-ioredis');
30
- case '@opentelemetry/instrumentation-mysql2': return require('@opentelemetry/instrumentation-mysql2');
31
- case 'winston-transport': return require('winston-transport');
32
- default: return NONE;
33
- }
34
- }
35
- catch (e) {
36
- throw e;
37
- }
7
+ // Bundlers must NOT follow this: an optional peer the app did not install would make webpack warn "Module not found",
8
+ // and a bare require call on a variable id is a "Critical dependency" warning. createRequire() is opaque to webpack/esbuild/Next's tracer,
9
+ // so peers resolve at run time from the SDK's own location, then from the app root (cwd). Install the peers in the app
10
+ // (pnpm: as direct dependencies); for a Next standalone build add them to outputFileTracingIncludes.
11
+ function resolvers() {
12
+ const from = [typeof __filename === 'string' ? __filename : '', `${process.cwd()}/`].filter(Boolean);
13
+ return from.map((f) => (0, node_module_1.createRequire)(f));
38
14
  }
39
15
  function load(id) {
40
- if (typeof require !== 'function')
41
- return (0, node_module_1.createRequire)(`${process.cwd()}/`)(id);
42
- const m = known(id);
43
- return m === NONE ? require(id) : m;
16
+ let err;
17
+ for (const r of resolvers()) {
18
+ try {
19
+ return r(id);
20
+ }
21
+ catch (e) {
22
+ if (e?.code !== 'MODULE_NOT_FOUND')
23
+ throw e;
24
+ err ??= e;
25
+ }
26
+ }
27
+ throw err;
44
28
  }
45
29
  const SDK_PEERS = [
46
30
  '@opentelemetry/context-async-hooks', '@opentelemetry/core', '@opentelemetry/exporter-logs-otlp-http',
@@ -1,4 +1,6 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { Resource } from '@opentelemetry/resources';
3
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
4
  import type { MeterProvider, PushMetricExporter } from '@opentelemetry/sdk-metrics';
3
5
  /** Explicit flag, else `WATCHTOWER_LOGS` / `WATCHTOWER_METRICS` (default on); `OTEL_*_EXPORTER=none` turns it off. */
4
6
  export declare function switchOn(name: string, otelExporterEnv: string, flag?: boolean): boolean;
@@ -1,3 +1,4 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { SpanProcessor } from '@opentelemetry/sdk-trace';
2
3
  export interface Frame {
3
4
  file: string;
@@ -1,3 +1,4 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { SpanProcessor } from '@opentelemetry/sdk-trace';
2
3
  export type RedactHook = (key: string, value: unknown) => unknown;
3
4
  /** Hook keys for the non-attribute fields. Event attributes (incl. exception.message / exception.stacktrace) use their own keys. */
@@ -14,12 +14,23 @@ if (process.env.WT_INGEST_KEY || process.env.OTEL_EXPORTER_OTLP_HEADERS) {
14
14
  const key = Symbol.for('watchtower.node.esm-hook');
15
15
  if (!g[key]) {
16
16
  g[key] = true;
17
+ // Node 26 prints DEP0205 for module.register(); import-in-the-middle's hook has no sync (registerHooks) form yet,
18
+ // so mute only that one warning for this call.
19
+ const emit = process.emitWarning;
20
+ process.emitWarning = ((w, ...a) => {
21
+ if (JSON.stringify(a).includes('DEP0205'))
22
+ return;
23
+ return emit.call(process, w, ...a);
24
+ });
17
25
  try {
18
26
  (0, node_module_1.register)('@opentelemetry/instrumentation/hook.mjs', (0, node_url_1.pathToFileURL)(`${process.cwd()}/`));
19
27
  }
20
28
  catch {
21
29
  // @opentelemetry/instrumentation not installed: CommonJS apps are still instrumented
22
30
  }
31
+ finally {
32
+ process.emitWarning = emit;
33
+ }
23
34
  }
24
35
  (0, index_js_1.init)({});
25
36
  }
@@ -1,4 +1,5 @@
1
1
  import type { Attributes, Context, Link, SpanKind } from '@opentelemetry/api';
2
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
3
  import type { Sampler, SamplingResult } from '@opentelemetry/sdk-trace';
3
4
  export interface SamplingRule {
4
5
  name?: string;
@@ -1,3 +1,4 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { SpanProcessor } from '@opentelemetry/sdk-trace';
2
3
  /** A path segment that reads like a secret or an opaque id: >= 24 chars, or >= 10 chars mixing a letter and a digit (UUIDs included). */
3
4
  export declare function looksSecret(seg: string): boolean;
@@ -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.0";
2
+ export declare const VERSION = "0.7.1";
@@ -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.0';
5
+ exports.VERSION = '0.7.1';
@@ -1,5 +1,8 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace';
3
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
4
  import type { LogRecordExporter, ReadableLogRecord } from '@opentelemetry/sdk-logs';
5
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
3
6
  import type { AggregationTemporality, InstrumentType, PushMetricExporter, ResourceMetrics } from '@opentelemetry/sdk-metrics';
4
7
  type Done = Parameters<SpanExporter['export']>[1];
5
8
  /** What the spool wraps: a span, log record or metric exporter; `B` is one export batch. */
@@ -1,2 +1,3 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace';
2
3
  export declare function filterExporter(inner: SpanExporter, keep: (s: ReadableSpan) => boolean): SpanExporter;
@@ -1,9 +1,13 @@
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)
4
5
  import type { Resource } from '@opentelemetry/resources';
6
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
5
7
  import type { ReadableSpan, TracerProvider } from '@opentelemetry/sdk-trace';
8
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
6
9
  import type { LoggerProvider } from '@opentelemetry/sdk-logs';
10
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
7
11
  import type { MeterProvider } from '@opentelemetry/sdk-metrics';
8
12
  import { captureException } from './errors.js';
9
13
  import type { CaptureContext } from './errors.js';
@@ -1,3 +1,4 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { ReadableSpan } from '@opentelemetry/sdk-trace';
2
3
  import * as wt from '../index.js';
3
4
  export { withWatchtower, uploadSourcemaps } from './next-build.js';
package/dist/esm/load.js CHANGED
@@ -1,68 +1,26 @@
1
- // Optional-peer loader. Each peer is required by a LITERAL name inside a try block so bundlers (webpack, esbuild, Next's
2
- // file tracer) can follow it; a computed `require(name)` is invisible to them. This is the CommonJS form;
3
- // scripts/build.mjs prepends `const require = createRequire(import.meta.url)` for dist/esm (webpack follows that too).
4
- // The cwd fallback only matters when `require` does not exist (test runners running the TS source as ESM).
1
+ // Optional-peer loader (same source for the CommonJS and ESM builds).
5
2
  import { createRequire } from 'node:module';
6
- const pre = {};
7
- try { pre["@opentelemetry/context-async-hooks"] = await import("@opentelemetry/context-async-hooks"); } catch (e) { pre["@opentelemetry/context-async-hooks"] = e; }
8
- try { pre["@opentelemetry/core"] = await import("@opentelemetry/core"); } catch (e) { pre["@opentelemetry/core"] = e; }
9
- try { pre["@opentelemetry/exporter-logs-otlp-http"] = await import("@opentelemetry/exporter-logs-otlp-http"); } catch (e) { pre["@opentelemetry/exporter-logs-otlp-http"] = e; }
10
- try { pre["@opentelemetry/exporter-metrics-otlp-http"] = await import("@opentelemetry/exporter-metrics-otlp-http"); } catch (e) { pre["@opentelemetry/exporter-metrics-otlp-http"] = e; }
11
- try { pre["@opentelemetry/exporter-trace-otlp-http"] = await import("@opentelemetry/exporter-trace-otlp-http"); } catch (e) { pre["@opentelemetry/exporter-trace-otlp-http"] = e; }
12
- try { pre["@opentelemetry/otlp-transformer"] = await import("@opentelemetry/otlp-transformer"); } catch (e) { pre["@opentelemetry/otlp-transformer"] = e; }
13
- try { pre["@opentelemetry/resources"] = await import("@opentelemetry/resources"); } catch (e) { pre["@opentelemetry/resources"] = e; }
14
- try { pre["@opentelemetry/sdk-logs"] = await import("@opentelemetry/sdk-logs"); } catch (e) { pre["@opentelemetry/sdk-logs"] = e; }
15
- try { pre["@opentelemetry/sdk-metrics"] = await import("@opentelemetry/sdk-metrics"); } catch (e) { pre["@opentelemetry/sdk-metrics"] = e; }
16
- try { pre["@opentelemetry/sdk-trace"] = await import("@opentelemetry/sdk-trace"); } catch (e) { pre["@opentelemetry/sdk-trace"] = e; }
17
- try { pre["@opentelemetry/instrumentation-runtime-node"] = await import("@opentelemetry/instrumentation-runtime-node"); } catch (e) { pre["@opentelemetry/instrumentation-runtime-node"] = e; }
18
- try { pre["@opentelemetry/instrumentation"] = await import("@opentelemetry/instrumentation"); } catch (e) { pre["@opentelemetry/instrumentation"] = e; }
19
- try { pre["@opentelemetry/instrumentation-http"] = await import("@opentelemetry/instrumentation-http"); } catch (e) { pre["@opentelemetry/instrumentation-http"] = e; }
20
- try { pre["@opentelemetry/instrumentation-undici"] = await import("@opentelemetry/instrumentation-undici"); } catch (e) { pre["@opentelemetry/instrumentation-undici"] = e; }
21
- try { pre["@opentelemetry/instrumentation-pg"] = await import("@opentelemetry/instrumentation-pg"); } catch (e) { pre["@opentelemetry/instrumentation-pg"] = e; }
22
- try { pre["@opentelemetry/instrumentation-ioredis"] = await import("@opentelemetry/instrumentation-ioredis"); } catch (e) { pre["@opentelemetry/instrumentation-ioredis"] = e; }
23
- try { pre["@opentelemetry/instrumentation-mysql2"] = await import("@opentelemetry/instrumentation-mysql2"); } catch (e) { pre["@opentelemetry/instrumentation-mysql2"] = e; }
24
- try { pre["winston-transport"] = await import("winston-transport"); } catch (e) { pre["winston-transport"] = e; }
25
- const nodeRequire = createRequire(import.meta.url);
26
- const require = (id) => {
27
- const m = pre[id];
28
- if (m === undefined) return nodeRequire(id);
29
- if (m instanceof Error) throw Object.assign(new Error(m.message), { code: m.code === 'ERR_MODULE_NOT_FOUND' ? 'MODULE_NOT_FOUND' : m.code });
30
- return m.default && typeof m.default === 'object' ? { ...m.default, ...m } : m;
31
- };
32
- const NONE = Symbol('not a known peer');
33
- function known(id) {
34
- try { // bundlers only tolerate an optional require that is lexically inside try
35
- switch (id) {
36
- case '@opentelemetry/context-async-hooks': return require('@opentelemetry/context-async-hooks');
37
- case '@opentelemetry/core': return require('@opentelemetry/core');
38
- case '@opentelemetry/exporter-logs-otlp-http': return require('@opentelemetry/exporter-logs-otlp-http');
39
- case '@opentelemetry/exporter-metrics-otlp-http': return require('@opentelemetry/exporter-metrics-otlp-http');
40
- case '@opentelemetry/exporter-trace-otlp-http': return require('@opentelemetry/exporter-trace-otlp-http');
41
- case '@opentelemetry/otlp-transformer': return require('@opentelemetry/otlp-transformer');
42
- case '@opentelemetry/resources': return require('@opentelemetry/resources');
43
- case '@opentelemetry/sdk-logs': return require('@opentelemetry/sdk-logs');
44
- case '@opentelemetry/sdk-metrics': return require('@opentelemetry/sdk-metrics');
45
- case '@opentelemetry/sdk-trace': return require('@opentelemetry/sdk-trace');
46
- case '@opentelemetry/instrumentation-runtime-node': return require('@opentelemetry/instrumentation-runtime-node');
47
- case '@opentelemetry/instrumentation': return require('@opentelemetry/instrumentation');
48
- case '@opentelemetry/instrumentation-http': return require('@opentelemetry/instrumentation-http');
49
- case '@opentelemetry/instrumentation-undici': return require('@opentelemetry/instrumentation-undici');
50
- case '@opentelemetry/instrumentation-pg': return require('@opentelemetry/instrumentation-pg');
51
- case '@opentelemetry/instrumentation-ioredis': return require('@opentelemetry/instrumentation-ioredis');
52
- case '@opentelemetry/instrumentation-mysql2': return require('@opentelemetry/instrumentation-mysql2');
53
- case 'winston-transport': return require('winston-transport');
54
- default: return NONE;
55
- }
56
- }
57
- catch (e) {
58
- throw e;
59
- }
3
+ // Bundlers must NOT follow this: an optional peer the app did not install would make webpack warn "Module not found",
4
+ // and a bare require call on a variable id is a "Critical dependency" warning. createRequire() is opaque to webpack/esbuild/Next's tracer,
5
+ // so peers resolve at run time from the SDK's own location, then from the app root (cwd). Install the peers in the app
6
+ // (pnpm: as direct dependencies); for a Next standalone build add them to outputFileTracingIncludes.
7
+ function resolvers() {
8
+ const from = [typeof __filename === 'string' ? __filename : '', `${process.cwd()}/`].filter(Boolean);
9
+ return from.map((f) => createRequire(f));
60
10
  }
61
11
  export function load(id) {
62
- if (typeof require !== 'function')
63
- return createRequire(`${process.cwd()}/`)(id);
64
- const m = known(id);
65
- return m === NONE ? require(id) : m;
12
+ let err;
13
+ for (const r of resolvers()) {
14
+ try {
15
+ return r(id);
16
+ }
17
+ catch (e) {
18
+ if (e?.code !== 'MODULE_NOT_FOUND')
19
+ throw e;
20
+ err ??= e;
21
+ }
22
+ }
23
+ throw err;
66
24
  }
67
25
  const SDK_PEERS = [
68
26
  '@opentelemetry/context-async-hooks', '@opentelemetry/core', '@opentelemetry/exporter-logs-otlp-http',
@@ -1,4 +1,6 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { Resource } from '@opentelemetry/resources';
3
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
4
  import type { MeterProvider, PushMetricExporter } from '@opentelemetry/sdk-metrics';
3
5
  /** Explicit flag, else `WATCHTOWER_LOGS` / `WATCHTOWER_METRICS` (default on); `OTEL_*_EXPORTER=none` turns it off. */
4
6
  export declare function switchOn(name: string, otelExporterEnv: string, flag?: boolean): boolean;
@@ -1,3 +1,4 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { SpanProcessor } from '@opentelemetry/sdk-trace';
2
3
  export interface Frame {
3
4
  file: string;
@@ -1,3 +1,4 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { SpanProcessor } from '@opentelemetry/sdk-trace';
2
3
  export type RedactHook = (key: string, value: unknown) => unknown;
3
4
  /** Hook keys for the non-attribute fields. Event attributes (incl. exception.message / exception.stacktrace) use their own keys. */
@@ -12,12 +12,23 @@ if (process.env.WT_INGEST_KEY || process.env.OTEL_EXPORTER_OTLP_HEADERS) {
12
12
  const key = Symbol.for('watchtower.node.esm-hook');
13
13
  if (!g[key]) {
14
14
  g[key] = true;
15
+ // Node 26 prints DEP0205 for module.register(); import-in-the-middle's hook has no sync (registerHooks) form yet,
16
+ // so mute only that one warning for this call.
17
+ const emit = process.emitWarning;
18
+ process.emitWarning = ((w, ...a) => {
19
+ if (JSON.stringify(a).includes('DEP0205'))
20
+ return;
21
+ return emit.call(process, w, ...a);
22
+ });
15
23
  try {
16
24
  registerHooks('@opentelemetry/instrumentation/hook.mjs', pathToFileURL(`${process.cwd()}/`));
17
25
  }
18
26
  catch {
19
27
  // @opentelemetry/instrumentation not installed: CommonJS apps are still instrumented
20
28
  }
29
+ finally {
30
+ process.emitWarning = emit;
31
+ }
21
32
  }
22
33
  init({});
23
34
  }
@@ -1,4 +1,5 @@
1
1
  import type { Attributes, Context, Link, SpanKind } from '@opentelemetry/api';
2
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
2
3
  import type { Sampler, SamplingResult } from '@opentelemetry/sdk-trace';
3
4
  export interface SamplingRule {
4
5
  name?: string;
@@ -1,3 +1,4 @@
1
+ // @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
1
2
  import type { SpanProcessor } from '@opentelemetry/sdk-trace';
2
3
  /** A path segment that reads like a secret or an opaque id: >= 24 chars, or >= 10 chars mixing a letter and a digit (UUIDs included). */
3
4
  export declare function looksSecret(seg: string): boolean;
@@ -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.0";
2
+ export declare const VERSION = "0.7.1";
@@ -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.0';
2
+ export const VERSION = '0.7.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@watchtowerobservability/node",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/watchtowerobservability/watchtower-node.git"
@@ -17,7 +17,8 @@
17
17
  "wt-next-sourcemaps": "./dist/cjs/next-sourcemaps-cli.js"
18
18
  },
19
19
  "files": [
20
- "dist"
20
+ "dist",
21
+ "CHANGELOG.md"
21
22
  ],
22
23
  "exports": {
23
24
  ".": {