@watchtowerobservability/node 0.7.4 → 0.7.6
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 +39 -1
- package/README.md +96 -12
- package/dist/cjs/attach.d.ts +7 -0
- package/dist/cjs/attach.js +29 -0
- package/dist/cjs/checkin.js +4 -13
- package/dist/cjs/cron/monitor.d.ts +47 -0
- package/dist/cjs/cron/monitor.js +95 -0
- package/dist/cjs/cron/schedulers.d.ts +36 -0
- package/dist/cjs/cron/schedulers.js +65 -0
- package/dist/cjs/env.d.ts +10 -0
- package/dist/cjs/env.js +98 -1
- package/dist/cjs/index.d.ts +50 -6
- package/dist/cjs/index.js +114 -37
- package/dist/cjs/instrument-for.d.ts +17 -0
- package/dist/cjs/instrument-for.js +44 -0
- package/dist/cjs/instrument.d.ts +4 -0
- package/dist/cjs/instrument.js +32 -1
- package/dist/cjs/integrations/bullmq.d.ts +8 -2
- package/dist/cjs/integrations/bullmq.js +32 -5
- package/dist/cjs/integrations/db.d.ts +7 -2
- package/dist/cjs/integrations/db.js +32 -4
- package/dist/cjs/integrations/fastify.d.ts +1 -1
- package/dist/cjs/integrations/fastify.js +3 -2
- package/dist/cjs/integrations/logs.js +16 -5
- package/dist/cjs/integrations/next-build.d.ts +31 -8
- package/dist/cjs/integrations/next-build.js +183 -34
- package/dist/cjs/integrations/next-tunnel.d.ts +6 -1
- package/dist/cjs/integrations/next-tunnel.js +13 -2
- package/dist/cjs/integrations/postgres.d.ts +2 -0
- package/dist/cjs/integrations/postgres.js +43 -1
- package/dist/cjs/integrations/temporal.d.ts +97 -0
- package/dist/cjs/integrations/temporal.js +144 -0
- package/dist/cjs/integrations/util.d.ts +17 -0
- package/dist/cjs/integrations/util.js +38 -0
- package/dist/cjs/load.d.ts +6 -0
- package/dist/cjs/load.js +28 -4
- package/dist/cjs/next-doctor-cli.d.ts +2 -0
- package/dist/cjs/next-doctor-cli.js +15 -0
- package/dist/cjs/next-doctor.d.ts +2 -0
- package/dist/cjs/next-doctor.js +50 -0
- package/dist/cjs/redact-presets.d.ts +16 -0
- package/dist/cjs/redact-presets.js +66 -0
- package/dist/cjs/register.js +19 -6
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/attach.d.ts +7 -0
- package/dist/esm/attach.js +25 -0
- package/dist/esm/checkin.js +4 -13
- package/dist/esm/cron/monitor.d.ts +47 -0
- package/dist/esm/cron/monitor.js +85 -0
- package/dist/esm/cron/schedulers.d.ts +36 -0
- package/dist/esm/cron/schedulers.js +61 -0
- package/dist/esm/env.d.ts +10 -0
- package/dist/esm/env.js +62 -0
- package/dist/esm/index.d.ts +50 -6
- package/dist/esm/index.js +109 -39
- package/dist/esm/instrument-for.d.ts +17 -0
- package/dist/esm/instrument-for.js +41 -0
- package/dist/esm/instrument.d.ts +4 -0
- package/dist/esm/instrument.js +30 -1
- package/dist/esm/integrations/bullmq.d.ts +8 -2
- package/dist/esm/integrations/bullmq.js +32 -5
- package/dist/esm/integrations/db.d.ts +7 -2
- package/dist/esm/integrations/db.js +29 -4
- package/dist/esm/integrations/fastify.d.ts +1 -1
- package/dist/esm/integrations/fastify.js +4 -3
- package/dist/esm/integrations/logs.js +16 -5
- package/dist/esm/integrations/next-build.d.ts +31 -8
- package/dist/esm/integrations/next-build.js +180 -34
- package/dist/esm/integrations/next-tunnel.d.ts +6 -1
- package/dist/esm/integrations/next-tunnel.js +13 -2
- package/dist/esm/integrations/postgres.d.ts +2 -0
- package/dist/esm/integrations/postgres.js +43 -2
- package/dist/esm/integrations/temporal.d.ts +97 -0
- package/dist/esm/integrations/temporal.js +139 -0
- package/dist/esm/integrations/util.d.ts +17 -0
- package/dist/esm/integrations/util.js +35 -0
- package/dist/esm/load.d.ts +6 -0
- package/dist/esm/load.js +21 -3
- package/dist/esm/next-doctor-cli.d.ts +2 -0
- package/dist/esm/next-doctor-cli.js +13 -0
- package/dist/esm/next-doctor.d.ts +2 -0
- package/dist/esm/next-doctor.js +14 -0
- package/dist/esm/redact-presets.d.ts +16 -0
- package/dist/esm/redact-presets.js +58 -0
- package/dist/esm/register.js +20 -7
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +42 -1
package/dist/cjs/env.js
CHANGED
|
@@ -1,8 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
3
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
36
|
exports.parseKv = parseKv;
|
|
5
37
|
exports.otelEnv = otelEnv;
|
|
38
|
+
exports.gitHeadSha = gitHeadSha;
|
|
39
|
+
exports.resolveRelease = resolveRelease;
|
|
40
|
+
const fs = __importStar(require("node:fs"));
|
|
41
|
+
const nodePath = __importStar(require("node:path"));
|
|
42
|
+
// Standard OTEL_* environment variables, used as fallbacks after the WT_* ones.
|
|
6
43
|
/** Parse `k=v,k2=v2` (OTEL_RESOURCE_ATTRIBUTES / OTEL_EXPORTER_OTLP_HEADERS); values are percent-decoded. */
|
|
7
44
|
function parseKv(s) {
|
|
8
45
|
const out = {};
|
|
@@ -35,3 +72,63 @@ function otelEnv(env = process.env) {
|
|
|
35
72
|
resource,
|
|
36
73
|
};
|
|
37
74
|
}
|
|
75
|
+
const CI_SHA_VARS = ['GITHUB_SHA', 'CI_COMMIT_SHA', 'VERCEL_GIT_COMMIT_SHA', 'SOURCE_VERSION', 'BUILD_SHA', 'RENDER_GIT_COMMIT', 'HEROKU_SLUG_COMMIT'];
|
|
76
|
+
const present = (v) => { const t = (v || '').trim(); return t && t.toLowerCase() !== 'unknown' ? t : undefined; };
|
|
77
|
+
/**
|
|
78
|
+
* The commit `HEAD` points at, found by walking up from `from` to a `.git` directory (a `.git` file of a worktree or submodule is
|
|
79
|
+
* followed through its `gitdir:` line). Reads `HEAD`, then the ref file or `packed-refs`; no child process. undefined when not found.
|
|
80
|
+
*/
|
|
81
|
+
function gitHeadSha(from) {
|
|
82
|
+
const sha = /^[0-9a-f]{40,64}$/i;
|
|
83
|
+
try {
|
|
84
|
+
for (let dir = nodePath.resolve(from);; dir = nodePath.dirname(dir)) {
|
|
85
|
+
let git = nodePath.join(dir, '.git');
|
|
86
|
+
if (fs.existsSync(git)) {
|
|
87
|
+
if (fs.statSync(git).isFile())
|
|
88
|
+
git = nodePath.resolve(dir, /^gitdir:\s*(.+)$/m.exec(fs.readFileSync(git, 'utf8'))?.[1]?.trim() ?? '');
|
|
89
|
+
const head = fs.readFileSync(nodePath.join(git, 'HEAD'), 'utf8').trim();
|
|
90
|
+
if (sha.test(head))
|
|
91
|
+
return head; // detached
|
|
92
|
+
const ref = /^ref:\s*(\S+)/.exec(head)?.[1];
|
|
93
|
+
if (!ref)
|
|
94
|
+
return undefined;
|
|
95
|
+
// a worktree keeps its branch refs in the common dir
|
|
96
|
+
const cd = nodePath.join(git, 'commondir');
|
|
97
|
+
const common = fs.existsSync(cd) ? nodePath.resolve(git, fs.readFileSync(cd, 'utf8').trim()) : git;
|
|
98
|
+
for (const d of [git, common]) {
|
|
99
|
+
try {
|
|
100
|
+
const v = fs.readFileSync(nodePath.join(d, ref), 'utf8').trim();
|
|
101
|
+
if (sha.test(v))
|
|
102
|
+
return v;
|
|
103
|
+
}
|
|
104
|
+
catch { /* not a loose ref */ }
|
|
105
|
+
try {
|
|
106
|
+
const line = fs.readFileSync(nodePath.join(d, 'packed-refs'), 'utf8').split('\n').find((l) => l.endsWith(` ${ref}`));
|
|
107
|
+
const v = line?.split(' ')[0];
|
|
108
|
+
if (v && sha.test(v))
|
|
109
|
+
return v;
|
|
110
|
+
}
|
|
111
|
+
catch { /* no packed-refs */ }
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
if (nodePath.dirname(dir) === dir)
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* service.version: explicit option, WT_RELEASE, OTEL_RESOURCE_ATTRIBUTES, the first CI commit-sha variable, the build stamp
|
|
125
|
+
* (`WT_BUILD_STAMP`, `BUILD_STAMP`), then the `.git` HEAD found upward from `gitFrom` (skipped when not given). Empty and `unknown` count as absent.
|
|
126
|
+
*/
|
|
127
|
+
function resolveRelease(opt, env, otelResource, gitFrom) {
|
|
128
|
+
for (const v of [opt, env.WT_RELEASE, otelResource['service.version'], ...CI_SHA_VARS.map((k) => env[k]), env.WT_BUILD_STAMP, env.BUILD_STAMP]) {
|
|
129
|
+
const r = present(v);
|
|
130
|
+
if (r)
|
|
131
|
+
return r;
|
|
132
|
+
}
|
|
133
|
+
return gitFrom ? gitHeadSha(gitFrom) : undefined;
|
|
134
|
+
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -9,12 +9,20 @@ import type { ReadableSpan, TracerProvider } from '@opentelemetry/sdk-trace';
|
|
|
9
9
|
import type { LoggerProvider } from '@opentelemetry/sdk-logs';
|
|
10
10
|
// @ts-ignore optional peer: absent -> any (keeps skipLibCheck:false consumers compiling)
|
|
11
11
|
import type { MeterProvider } from '@opentelemetry/sdk-metrics';
|
|
12
|
+
import type { RedactHook } from './redact.js';
|
|
13
|
+
import type { RedactPreset } from './redact-presets.js';
|
|
14
|
+
import type { CheckInOptions, CheckInStatus, MonitorOptions } from './cron/monitor.js';
|
|
12
15
|
import { captureException } from './errors.js';
|
|
13
16
|
import type { CaptureContext } from './errors.js';
|
|
14
17
|
import { RemoteSampler } from './sampling.js';
|
|
15
18
|
import type { Profiler } from './profiling.js';
|
|
16
19
|
export { captureException, metrics, trace };
|
|
20
|
+
export { instrument } from './instrument-for.js';
|
|
21
|
+
export type { Framework, InstrumentOptions } from './instrument-for.js';
|
|
22
|
+
export { droppedDbSpans } from './integrations/db.js';
|
|
17
23
|
export { setCaptureRules, capturePayload } from './payload.js';
|
|
24
|
+
export type { MonitorOptions, MonitorConfig, CheckInOptions, CheckInStatus } from './cron/monitor.js';
|
|
25
|
+
export { instrumentNestSchedule, instrumentNodeCron } from './cron/schedulers.js';
|
|
18
26
|
export type { CaptureRule } from './payload.js';
|
|
19
27
|
export type { CaptureContext };
|
|
20
28
|
export declare const DEFAULT_ENDPOINT = "http://localhost:4318";
|
|
@@ -26,7 +34,7 @@ export interface InitOptions {
|
|
|
26
34
|
apiKey?: string;
|
|
27
35
|
/** Defaults to WT_ENVIRONMENT. */
|
|
28
36
|
environment?: string;
|
|
29
|
-
/** Sent as `service.version`; the server links an issue's first release by matching it to an existing release's version. Defaults to WT_RELEASE, then `service.version` in OTEL_RESOURCE_ATTRIBUTES. */
|
|
37
|
+
/** Sent as `service.version`; the server links an issue's first release by matching it to an existing release's version. Defaults to WT_RELEASE, then `service.version` in OTEL_RESOURCE_ATTRIBUTES, then the first set of GITHUB_SHA, CI_COMMIT_SHA, VERCEL_GIT_COMMIT_SHA, SOURCE_VERSION, BUILD_SHA, RENDER_GIT_COMMIT, HEROKU_SLUG_COMMIT, then WT_BUILD_STAMP / BUILD_STAMP, then the commit `.git/HEAD` points at (searched upward from the working directory). */
|
|
30
38
|
release?: string;
|
|
31
39
|
/** Hook uncaughtException / unhandledRejection (default true). */
|
|
32
40
|
captureProcessErrors?: boolean;
|
|
@@ -50,11 +58,15 @@ export interface InitOptions {
|
|
|
50
58
|
/** Resource attributes (on top of OTEL_RESOURCE_ATTRIBUTES); keys starting with `wt.` are dropped. */
|
|
51
59
|
resource?: Record<string, string | number | boolean>;
|
|
52
60
|
/**
|
|
53
|
-
*
|
|
61
|
+
* Built-in redaction: `'strict'` (default) replaces string values of secret-shaped keys (authorization, cookie, set-cookie,
|
|
62
|
+
* password, secret, token, api_key, session, ...) with `[redacted]` on spans, span events, logs and errors, and URLs lose their
|
|
63
|
+
* query string and token-shaped path segments (`urlScrubbing`); `'pii'` also masks emails, phone numbers, Luhn-valid card numbers
|
|
64
|
+
* and IP addresses in every string; `'off'` disables the presets and URL scrubbing. The gateway applies the same rules again as
|
|
65
|
+
* a backstop. A function is a hook run after the `'strict'` preset. The hook is called before export for every span attribute, every span event's and link's attributes (so `exception.message`
|
|
54
66
|
* and `exception.stacktrace`), the span name (key `span.name`), the status message (`status.message`) and each log
|
|
55
67
|
* body (`log.body`) and log attribute; return the value to keep.
|
|
56
68
|
*/
|
|
57
|
-
redact?:
|
|
69
|
+
redact?: RedactHook | RedactPreset;
|
|
58
70
|
/** Directory for the offline buffer. */
|
|
59
71
|
bufferDir?: string;
|
|
60
72
|
/** Apply the project's head sampling rules in the SDK, polled from /v1/sampling; defaults to WT_REMOTE_SAMPLING=1. Spans dropped here never reach the gateway, so its exact request counts see only what is kept. */
|
|
@@ -71,9 +83,17 @@ export interface InitOptions {
|
|
|
71
83
|
* Scrub URLs on every span, including spans other libraries create (Next.js, node:http, fetch): the query string is dropped
|
|
72
84
|
* (`url.query` removed) and path segments that look like secrets (UUIDs, hex runs, JWTs, long digit runs, random tokens of >= 16 chars;
|
|
73
85
|
* hosts, readable words, slugs and short ids stay) become `:redacted`, in `http.target`, `url.full`, `url.path`, `http.url` and URLs in span names.
|
|
74
|
-
* `http.route` is kept. Default true; `false` records URLs as the instrumentation produced them.
|
|
86
|
+
* `http.route` is kept. Default true (false when `redact: 'off'`); `false` records URLs as the instrumentation produced them.
|
|
75
87
|
*/
|
|
76
88
|
urlScrubbing?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* What to do when another library (Sentry, ...) already registered the global TracerProvider. `'auto'` (default): attach the
|
|
91
|
+
* Watchtower exporter to that provider as a span processor and leave its context manager and propagator alone; `'own'`: build and
|
|
92
|
+
* register our own provider (the old behaviour; the other one is kept as the global and a warning says so); `'attach'`: like
|
|
93
|
+
* `'auto'`, with a warning when there is no provider to attach to. Attached spans carry the other provider's resource
|
|
94
|
+
* (set `OTEL_SERVICE_NAME`), and `remoteSampling` is not applied.
|
|
95
|
+
*/
|
|
96
|
+
otel?: 'auto' | 'own' | 'attach';
|
|
77
97
|
/** Return false to drop a finished span before export (the `/next` entry uses it for `nextInternals`). */
|
|
78
98
|
spanFilter?: (span: ReadableSpan) => boolean;
|
|
79
99
|
/**
|
|
@@ -116,7 +136,15 @@ export interface ScoreOptions {
|
|
|
116
136
|
}
|
|
117
137
|
/** Drop caller-supplied wt.* keys: tenant identity comes only from the key. */
|
|
118
138
|
export declare function safeResource(attrs?: Record<string, unknown>): Record<string, unknown>;
|
|
119
|
-
|
|
139
|
+
/** What `init()` reports (also fields of the returned Client): per signal `ok`, `disabled` (switched off) or `blocked` (an OTel global was already registered and kept). */
|
|
140
|
+
export interface InitStatus {
|
|
141
|
+
traces: 'ok' | 'disabled' | 'blocked';
|
|
142
|
+
metrics: 'ok' | 'disabled' | 'blocked';
|
|
143
|
+
logs: 'ok' | 'disabled' | 'blocked';
|
|
144
|
+
blocked: string[];
|
|
145
|
+
warnings: string[];
|
|
146
|
+
}
|
|
147
|
+
export declare class Client implements InitStatus {
|
|
120
148
|
readonly endpoint: string;
|
|
121
149
|
readonly apiUrl: string;
|
|
122
150
|
readonly project: string | undefined;
|
|
@@ -124,7 +152,17 @@ export declare class Client {
|
|
|
124
152
|
Authorization: string;
|
|
125
153
|
} & Record<string, string>;
|
|
126
154
|
readonly fetch: typeof fetch;
|
|
127
|
-
readonly redact:
|
|
155
|
+
readonly redact: RedactHook | undefined;
|
|
156
|
+
private readonly scrubUrls;
|
|
157
|
+
/** What `init` found: `blocked` lists the OTel globals that were already registered and kept. */
|
|
158
|
+
traces: 'ok' | 'disabled' | 'blocked';
|
|
159
|
+
metrics: 'ok' | 'disabled' | 'blocked';
|
|
160
|
+
logs: 'ok' | 'disabled' | 'blocked';
|
|
161
|
+
blocked: string[];
|
|
162
|
+
warnings: string[];
|
|
163
|
+
/** True when the exporter was attached to another provider's pipeline (`otel`). */
|
|
164
|
+
readonly attached: boolean;
|
|
165
|
+
private readonly spanProcessors;
|
|
128
166
|
private readonly logCaller;
|
|
129
167
|
readonly provider: TracerProvider;
|
|
130
168
|
readonly resource: Resource;
|
|
@@ -165,6 +203,12 @@ export declare class Client {
|
|
|
165
203
|
shutdown(): Promise<void>;
|
|
166
204
|
}
|
|
167
205
|
export declare function init(opts: InitOptions): Client;
|
|
206
|
+
/** Why telemetry is off (set by the preload when it cannot start); shown on the first dropped helper call. */
|
|
207
|
+
export declare const setOffReason: (r: string) => void;
|
|
208
|
+
/** One check-in for the monitor `slug`. Fire and forget by default (5 s cap, never throws); `{ wait: true }` awaits it. */
|
|
209
|
+
export declare const checkIn: (slug: string, status: CheckInStatus, o?: CheckInOptions) => Promise<void>;
|
|
210
|
+
/** `withMonitor(slug, fn, { schedule, timezone, checkinMargin, maxRuntime, failureThreshold, wait })`: `fn` as a monitored job; the monitor is created or updated from `schedule`. */
|
|
211
|
+
export declare const withMonitor: <T>(slug: string, fn: () => T | Promise<T>, o?: MonitorOptions) => Promise<T>;
|
|
168
212
|
export declare const checkin: <T>(slug: string, fn: () => T | Promise<T>) => Promise<T>;
|
|
169
213
|
export declare const flush: () => Promise<unknown>;
|
|
170
214
|
export declare const log: (l: LogLevel, b: string, a?: Record<string, unknown>) => void;
|
package/dist/cjs/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.shutdown = exports.observe = exports.evaluateResume = exports.evaluate = exports.score = exports.getPrompt = exports.log = exports.flush = exports.checkin = exports.Client = exports.DEFAULT_ENDPOINT = exports.capturePayload = exports.setCaptureRules = exports.trace = exports.metrics = exports.captureException = void 0;
|
|
36
|
+
exports.shutdown = exports.observe = exports.evaluateResume = exports.evaluate = exports.score = exports.getPrompt = exports.log = exports.flush = exports.checkin = exports.withMonitor = exports.checkIn = exports.setOffReason = exports.Client = exports.DEFAULT_ENDPOINT = exports.instrumentNodeCron = exports.instrumentNestSchedule = exports.capturePayload = exports.setCaptureRules = exports.droppedDbSpans = exports.instrument = exports.trace = exports.metrics = exports.captureException = void 0;
|
|
37
37
|
exports.callerOf = callerOf;
|
|
38
38
|
exports.safeResource = safeResource;
|
|
39
39
|
exports.init = init;
|
|
@@ -45,12 +45,16 @@ Object.defineProperty(exports, "metrics", { enumerable: true, get: function () {
|
|
|
45
45
|
Object.defineProperty(exports, "trace", { enumerable: true, get: function () { return api_1.trace; } });
|
|
46
46
|
const load_js_1 = require("./load.js");
|
|
47
47
|
const env_js_1 = require("./env.js");
|
|
48
|
+
const db_js_1 = require("./integrations/db.js");
|
|
48
49
|
const instrument_js_1 = require("./instrument.js");
|
|
49
50
|
const redact_js_1 = require("./redact.js");
|
|
51
|
+
const redact_presets_js_1 = require("./redact-presets.js");
|
|
52
|
+
const attach_js_1 = require("./attach.js");
|
|
50
53
|
const scrub_js_1 = require("./scrub.js");
|
|
51
54
|
const filter_js_1 = require("./filter.js");
|
|
52
55
|
const next_filter_js_1 = require("./next-filter.js");
|
|
53
56
|
const checkin_js_1 = require("./checkin.js");
|
|
57
|
+
const monitor_js_1 = require("./cron/monitor.js");
|
|
54
58
|
const shutdown_js_1 = require("./shutdown.js");
|
|
55
59
|
const version_js_1 = require("./version.js");
|
|
56
60
|
const buffer_js_1 = require("./buffer.js");
|
|
@@ -62,9 +66,16 @@ const payload_js_1 = require("./payload.js");
|
|
|
62
66
|
const profiling_js_1 = require("./profiling.js");
|
|
63
67
|
const sampling_js_1 = require("./sampling.js");
|
|
64
68
|
const origin_js_1 = require("./origin.js");
|
|
69
|
+
var instrument_for_js_1 = require("./instrument-for.js");
|
|
70
|
+
Object.defineProperty(exports, "instrument", { enumerable: true, get: function () { return instrument_for_js_1.instrument; } });
|
|
71
|
+
var db_js_2 = require("./integrations/db.js");
|
|
72
|
+
Object.defineProperty(exports, "droppedDbSpans", { enumerable: true, get: function () { return db_js_2.droppedDbSpans; } });
|
|
65
73
|
var payload_js_2 = require("./payload.js");
|
|
66
74
|
Object.defineProperty(exports, "setCaptureRules", { enumerable: true, get: function () { return payload_js_2.setCaptureRules; } });
|
|
67
75
|
Object.defineProperty(exports, "capturePayload", { enumerable: true, get: function () { return payload_js_2.capturePayload; } });
|
|
76
|
+
var schedulers_js_1 = require("./cron/schedulers.js");
|
|
77
|
+
Object.defineProperty(exports, "instrumentNestSchedule", { enumerable: true, get: function () { return schedulers_js_1.instrumentNestSchedule; } });
|
|
78
|
+
Object.defineProperty(exports, "instrumentNodeCron", { enumerable: true, get: function () { return schedulers_js_1.instrumentNodeCron; } });
|
|
68
79
|
exports.DEFAULT_ENDPOINT = 'http://localhost:4318';
|
|
69
80
|
/** code.filepath/code.lineno of the frame that called `log()` (stack line 0 is "Error", 1 is `log`, 2 the caller). */
|
|
70
81
|
function callerOf(stack) {
|
|
@@ -84,6 +95,16 @@ class Client {
|
|
|
84
95
|
headers;
|
|
85
96
|
fetch;
|
|
86
97
|
redact;
|
|
98
|
+
scrubUrls;
|
|
99
|
+
/** What `init` found: `blocked` lists the OTel globals that were already registered and kept. */
|
|
100
|
+
traces = 'ok';
|
|
101
|
+
metrics = 'ok';
|
|
102
|
+
logs = 'ok';
|
|
103
|
+
blocked = [];
|
|
104
|
+
warnings = [];
|
|
105
|
+
/** True when the exporter was attached to another provider's pipeline (`otel`). */
|
|
106
|
+
attached = false;
|
|
107
|
+
spanProcessors = [];
|
|
87
108
|
logCaller;
|
|
88
109
|
provider;
|
|
89
110
|
resource;
|
|
@@ -111,7 +132,7 @@ class Client {
|
|
|
111
132
|
this.headers = { ...oe.headers, Authorization: `Bearer ${apiKey}` };
|
|
112
133
|
this.fetch = o.fetch || globalThis.fetch;
|
|
113
134
|
const environment = o.environment || env.WT_ENVIRONMENT || oe.resource['deployment.environment.name'];
|
|
114
|
-
const release = o.release
|
|
135
|
+
const release = (0, env_js_1.resolveRelease)(o.release, env, oe.resource, process.cwd());
|
|
115
136
|
// the OTel SDK packages are optional peers, loaded here (not at import time) with a clear error when missing
|
|
116
137
|
const { resourceFromAttributes, defaultResource } = (0, load_js_1.need)('@opentelemetry/resources');
|
|
117
138
|
// the SDK's own telemetry.sdk.* (name, language, version): a bare resourceFromAttributes does not add them
|
|
@@ -129,7 +150,9 @@ class Client {
|
|
|
129
150
|
...safeResource(o.resource),
|
|
130
151
|
});
|
|
131
152
|
this.resource = resource;
|
|
132
|
-
|
|
153
|
+
const red = (0, redact_presets_js_1.resolveRedact)(o.redact);
|
|
154
|
+
this.redact = red.hook;
|
|
155
|
+
this.scrubUrls = o.urlScrubbing ?? red.preset !== 'off';
|
|
133
156
|
this.logCaller = o.logCaller ?? env.WATCHTOWER_LOG_CALLER === '1';
|
|
134
157
|
let exporter = o.exporter;
|
|
135
158
|
if (!exporter) {
|
|
@@ -153,19 +176,30 @@ class Client {
|
|
|
153
176
|
});
|
|
154
177
|
sampler = new ParentBasedSampler({ root: this.remoteSampler });
|
|
155
178
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
...(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
179
|
+
const procs = [
|
|
180
|
+
...(o.codeOrigin ?? env.WT_CODE_ORIGIN === '1' ? [(0, origin_js_1.codeOrigin)()] : []),
|
|
181
|
+
...(o.urlScrubbing ?? red.preset !== 'off' ? [(0, scrub_js_1.urlScrubber)()] : []),
|
|
182
|
+
...(red.hook ? [(0, redact_js_1.redactor)(red.hook)] : []),
|
|
183
|
+
new BatchSpanProcessor({ exporter }),
|
|
184
|
+
];
|
|
185
|
+
const mode = o.otel ?? 'auto';
|
|
186
|
+
const foreign = mode !== 'own' && !state.ownsGlobals ? (0, attach_js_1.foreignProvider)() : undefined;
|
|
187
|
+
if (foreign && (0, attach_js_1.attachProcessors)(foreign, procs)) {
|
|
188
|
+
this.attached = true;
|
|
189
|
+
this.spanProcessors = procs;
|
|
190
|
+
this.provider = foreign;
|
|
191
|
+
if (sampler)
|
|
192
|
+
this.warnings.push('remoteSampling is not applied when attached to another tracer provider');
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
if (foreign || mode === 'attach')
|
|
196
|
+
this.warnings.push(foreign ? 'otel: the existing tracer provider has no span-processor hook; using our own' : "otel: 'attach' but no tracer provider is registered yet; using our own");
|
|
197
|
+
this.provider = new TP({ resource, ...(sampler ? { sampler: sampler } : {}), spanProcessors: procs });
|
|
198
|
+
}
|
|
166
199
|
this.tracer = this.provider.getTracer('watchtower');
|
|
167
200
|
// an explicit exporter never switches the other signals off: only `logs` / `metrics` / the env switches do
|
|
168
201
|
const logsOn = (0, metrics_js_1.switchOn)('WATCHTOWER_LOGS', 'OTEL_LOGS_EXPORTER', o.logs ?? (o.logExporter ? true : undefined));
|
|
202
|
+
this.logs = logsOn ? 'ok' : 'disabled';
|
|
169
203
|
let logExporter = logsOn ? o.logExporter : undefined;
|
|
170
204
|
if (logsOn && !logExporter) {
|
|
171
205
|
const url = `${this.endpoint}/v1/logs`;
|
|
@@ -185,6 +219,9 @@ class Client {
|
|
|
185
219
|
this.meterProvider = m.provider;
|
|
186
220
|
this.stopRuntime = m.stop;
|
|
187
221
|
}
|
|
222
|
+
else {
|
|
223
|
+
this.metrics = 'disabled';
|
|
224
|
+
}
|
|
188
225
|
if (o.captureRules ?? env.WT_CAPTURE_RULES === '1') {
|
|
189
226
|
void (0, payload_js_1.loadCaptureRules)({ apiUrl: this.apiUrl, key: apiKey, service: String(resource.attributes['service.name']), fetch: this.fetch });
|
|
190
227
|
}
|
|
@@ -194,9 +231,18 @@ class Client {
|
|
|
194
231
|
let attrs = (0, errors_js_1.dropReserved)(attributes);
|
|
195
232
|
const redact = this.redact;
|
|
196
233
|
if (redact) {
|
|
197
|
-
|
|
234
|
+
// dotted keys (flattened nested objects) also go through the hook under their leaf name, so a hook keyed on `url` sees `req.url`
|
|
235
|
+
attrs = Object.fromEntries(Object.entries(attrs).map(([k, v]) => {
|
|
236
|
+
v = redact(k, v);
|
|
237
|
+
const leaf = k.slice(k.lastIndexOf('.') + 1);
|
|
238
|
+
return [k, leaf !== k ? redact(leaf, v) : v];
|
|
239
|
+
}));
|
|
198
240
|
body = String(redact(redact_js_1.LOG_BODY_KEY, body) ?? '');
|
|
199
241
|
}
|
|
242
|
+
if (this.scrubUrls)
|
|
243
|
+
for (const k of Object.keys(attrs))
|
|
244
|
+
if (typeof attrs[k] === 'string' && /(^|\.)(url|uri|target)$/.test(k))
|
|
245
|
+
attrs[k] = (0, scrub_js_1.scrubUrl)(attrs[k]);
|
|
200
246
|
if (this.logCaller)
|
|
201
247
|
attrs = { ...attrs, ...callerOf(new Error().stack) };
|
|
202
248
|
this.logger.emit({
|
|
@@ -211,7 +257,8 @@ class Client {
|
|
|
211
257
|
return (0, checkin_js_1.checkin)(this, monitorSlug, fn);
|
|
212
258
|
}
|
|
213
259
|
forceFlush() {
|
|
214
|
-
|
|
260
|
+
const spans = this.attached ? Promise.all(this.spanProcessors.map((p) => p.forceFlush())) : this.provider.forceFlush();
|
|
261
|
+
return Promise.all([spans, this.loggerProvider.forceFlush(), this.meterProvider?.forceFlush()]);
|
|
215
262
|
}
|
|
216
263
|
// keep the key out of console.log / JSON.stringify
|
|
217
264
|
toJSON() {
|
|
@@ -311,7 +358,7 @@ class Client {
|
|
|
311
358
|
shutdown() {
|
|
312
359
|
this.stopRuntime();
|
|
313
360
|
this.remoteSampler?.stop();
|
|
314
|
-
return Promise.all([this.profiler?.then((p) => p?.stop()), this.provider.shutdown(), this.loggerProvider.shutdown(), this.meterProvider?.shutdown()]).then(() => undefined);
|
|
361
|
+
return Promise.all([this.profiler?.then((p) => p?.stop()), this.attached ? Promise.all(this.spanProcessors.map((p) => p.shutdown())) : this.provider.shutdown(), this.loggerProvider.shutdown(), this.meterProvider?.shutdown()]).then(() => undefined);
|
|
315
362
|
}
|
|
316
363
|
}
|
|
317
364
|
exports.Client = Client;
|
|
@@ -324,25 +371,42 @@ const state = (globalThis[Symbol.for('watchtower.node.state')] ??= {});
|
|
|
324
371
|
* left alone and a warning says so; only globals a previous `init` installed are torn down on a re-init.
|
|
325
372
|
*/
|
|
326
373
|
function registerGlobals(c) {
|
|
374
|
+
const blocked = [];
|
|
327
375
|
if (state.ownsGlobals) { // a re-init replaces what the previous init installed
|
|
328
376
|
api_1.trace.disable();
|
|
329
377
|
api_1.context.disable();
|
|
330
378
|
api_1.propagation.disable();
|
|
331
379
|
api_1.metrics.disable();
|
|
332
380
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
api_1.trace.setGlobalTracerProvider(c.provider)
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
381
|
+
if (!c.attached) { // attached: the other setup owns the provider, context manager and propagator
|
|
382
|
+
const { AsyncLocalStorageContextManager } = (0, load_js_1.need)('@opentelemetry/context-async-hooks');
|
|
383
|
+
const { CompositePropagator, W3CBaggagePropagator, W3CTraceContextPropagator } = (0, load_js_1.need)('@opentelemetry/core');
|
|
384
|
+
const ownTracer = api_1.trace.setGlobalTracerProvider(c.provider);
|
|
385
|
+
state.ownsGlobals = ownTracer === true;
|
|
386
|
+
if (!ownTracer)
|
|
387
|
+
blocked.push('tracer-provider');
|
|
388
|
+
if (!api_1.context.setGlobalContextManager(new AsyncLocalStorageContextManager().enable()))
|
|
389
|
+
blocked.push('context-manager');
|
|
390
|
+
if (!api_1.propagation.setGlobalPropagator(new CompositePropagator({ propagators: [new W3CTraceContextPropagator(), new W3CBaggagePropagator()] })))
|
|
391
|
+
blocked.push('propagator');
|
|
392
|
+
}
|
|
393
|
+
if (c.meterProvider && !api_1.metrics.setGlobalMeterProvider(c.meterProvider))
|
|
394
|
+
blocked.push('meter-provider');
|
|
395
|
+
c.blocked = blocked;
|
|
396
|
+
if (blocked.includes('tracer-provider'))
|
|
397
|
+
c.traces = 'blocked';
|
|
398
|
+
if (blocked.includes('meter-provider'))
|
|
399
|
+
c.metrics = 'blocked';
|
|
400
|
+
if (blocked.length) {
|
|
401
|
+
const w = `watchtower: OpenTelemetry global(s) already registered and kept: ${blocked.join(', ')}; call init() before other OTel setup to own them, or leave \`otel\` on 'auto' to attach to the existing provider`;
|
|
402
|
+
c.warnings.push(w);
|
|
403
|
+
api_1.diag.warn(w);
|
|
404
|
+
}
|
|
344
405
|
}
|
|
345
406
|
function init(opts) {
|
|
407
|
+
const missing = (0, load_js_1.missingPeers)();
|
|
408
|
+
if (missing.length)
|
|
409
|
+
console.warn(`[watchtower] missing OpenTelemetry package(s): ${missing.join(', ')}. Next.js standalone: ${load_js_1.STANDALONE_HINT}. Otherwise: npm install ${missing.join(' ')}`);
|
|
346
410
|
const nextMode = opts?.nextInternals ?? (process.env.NEXT_RUNTIME ? 'sample' : undefined);
|
|
347
411
|
if (nextMode) {
|
|
348
412
|
const own = (0, next_filter_js_1.nextInternalsFilter)(nextMode, opts?.nextInternalsRate);
|
|
@@ -359,11 +423,12 @@ function init(opts) {
|
|
|
359
423
|
const mode = opts?.instrument ?? (env === 'auto' ? 'auto' : !['0', 'off', 'false', 'no'].includes(env));
|
|
360
424
|
if (mode) {
|
|
361
425
|
const names = (0, instrument_js_1.instrumentAll)({ tracerProvider: c.provider, meterProvider: c.meterProvider }, [c.endpoint, c.apiUrl], mode === 'auto');
|
|
426
|
+
(0, db_js_1.setHttpServerActive)(names.includes('@opentelemetry/instrumentation-http'));
|
|
362
427
|
const logOn = opts?.instrumentLog ?? !['0', 'off', 'false', 'no'].includes((process.env.WT_INSTRUMENT_LOG || '').trim().toLowerCase());
|
|
363
428
|
if (mode === 'auto' && logOn) {
|
|
364
429
|
console.info(`[watchtower] instrumented: ${names.map((n) => n.replace('@opentelemetry/instrumentation-', '')).join(', ') || 'nothing (no supported package found)'}`);
|
|
365
430
|
}
|
|
366
|
-
if (logOn &&
|
|
431
|
+
if (logOn && (0, db_js_1.dbRequireParent)(undefined)) {
|
|
367
432
|
console.info('watchtower: requireParent on; queries outside a span are not recorded (WATCHTOWER_DB_REQUIRE_PARENT=0 to keep them)');
|
|
368
433
|
}
|
|
369
434
|
}
|
|
@@ -383,26 +448,38 @@ function init(opts) {
|
|
|
383
448
|
}
|
|
384
449
|
return c;
|
|
385
450
|
}
|
|
451
|
+
/** Every public helper is a no-op before `init()` (like `captureException`), so shared code can call them in any order. */
|
|
386
452
|
function need() {
|
|
387
|
-
if (!state.current)
|
|
388
|
-
|
|
453
|
+
if (!state.current && !state.offWarned && process.env.NODE_ENV !== 'test') {
|
|
454
|
+
state.offWarned = true; // once per process: a dropped call must not go unnoticed, nor flood the log
|
|
455
|
+
console.warn(`[watchtower] telemetry is OFF: ${state.offReason ?? 'init() was not called'}. Calls to log, observe, checkin and the other helpers are dropped.`);
|
|
456
|
+
}
|
|
389
457
|
return state.current;
|
|
390
458
|
}
|
|
391
|
-
|
|
459
|
+
/** Why telemetry is off (set by the preload when it cannot start); shown on the first dropped helper call. */
|
|
460
|
+
const setOffReason = (r) => { state.offReason = r; };
|
|
461
|
+
exports.setOffReason = setOffReason;
|
|
462
|
+
/** One check-in for the monitor `slug`. Fire and forget by default (5 s cap, never throws); `{ wait: true }` awaits it. */
|
|
463
|
+
const checkIn = (slug, status, o) => { const c = need(); return c ? (0, monitor_js_1.checkIn)(c, slug, status, o) : Promise.resolve(); };
|
|
464
|
+
exports.checkIn = checkIn;
|
|
465
|
+
/** `withMonitor(slug, fn, { schedule, timezone, checkinMargin, maxRuntime, failureThreshold, wait })`: `fn` as a monitored job; the monitor is created or updated from `schedule`. */
|
|
466
|
+
const withMonitor = (slug, fn, o) => { const c = need(); return c ? (0, monitor_js_1.withMonitor)(c, slug, fn, o) : Promise.resolve().then(fn); };
|
|
467
|
+
exports.withMonitor = withMonitor;
|
|
468
|
+
const checkin = (slug, fn) => need()?.checkin(slug, fn) ?? Promise.resolve().then(fn);
|
|
392
469
|
exports.checkin = checkin;
|
|
393
470
|
const flush = () => (state.current ? state.current.forceFlush() : Promise.resolve());
|
|
394
471
|
exports.flush = flush;
|
|
395
|
-
const log = (l, b, a) => need()
|
|
472
|
+
const log = (l, b, a) => need()?.log(l, b, a);
|
|
396
473
|
exports.log = log;
|
|
397
|
-
const getPrompt = (id) => need()
|
|
474
|
+
const getPrompt = (id) => need()?.getPrompt(id) ?? Promise.resolve(undefined);
|
|
398
475
|
exports.getPrompt = getPrompt;
|
|
399
|
-
const score = (t, v, o) => need()
|
|
476
|
+
const score = (t, v, o) => need()?.score(t, v, o) ?? Promise.resolve(undefined);
|
|
400
477
|
exports.score = score;
|
|
401
|
-
const evaluate = (d, t, s, o) => need()
|
|
478
|
+
const evaluate = (d, t, s, o) => need()?.evaluate(d, t, s, o) ?? Promise.resolve([]);
|
|
402
479
|
exports.evaluate = evaluate;
|
|
403
|
-
const evaluateResume = (d, t, s, prev, o) => need()
|
|
480
|
+
const evaluateResume = (d, t, s, prev, o) => need()?.evaluateResume(d, t, s, prev, o) ?? Promise.resolve([]);
|
|
404
481
|
exports.evaluateResume = evaluateResume;
|
|
405
|
-
const observe = (n, f) => need()
|
|
482
|
+
const observe = (n, f) => need()?.observe(n, f) ?? f;
|
|
406
483
|
exports.observe = observe;
|
|
407
484
|
const shutdown = () => (state.current ? state.current.shutdown() : Promise.resolve());
|
|
408
485
|
exports.shutdown = shutdown;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Framework = 'nest' | 'express' | 'next' | 'bullmq' | 'pg' | 'postgres' | 'ioredis';
|
|
2
|
+
export interface InstrumentOptions {
|
|
3
|
+
/** URLs never traced as outgoing calls (our own endpoint); `init` passes its own. */
|
|
4
|
+
selfUrls?: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* `instrument('nest' | 'express' | 'next' | 'bullmq' | 'pg' | 'postgres' | 'ioredis')`. Call it after `init()`.
|
|
8
|
+
*
|
|
9
|
+
* - `nest`, `express`: node:http server instrumentation; server spans are renamed `METHOD /route/:param` from the matched route (Nest on Express).
|
|
10
|
+
* - `next`: http and undici (fetch); Next's own span filtering is `init`'s `nextInternals` (applied when `NEXT_RUNTIME` is set).
|
|
11
|
+
* - `bullmq`: producer and worker spans with trace context in the job (`instrumentBullMQ`); order does not matter, it patches the classes.
|
|
12
|
+
* - `postgres`: postgres.js through its diagnostics channel; order does not matter.
|
|
13
|
+
* - `pg`, `ioredis`: the OTel instrumentation, which hooks `require`: call before the first `require('pg')` / `import 'pg'` (best: the `/register` preload).
|
|
14
|
+
*
|
|
15
|
+
* Returns the packages or integrations enabled by this call (empty when already on, or its peer is not installed).
|
|
16
|
+
*/
|
|
17
|
+
export declare function instrument(name: Framework, opts?: InstrumentOptions): string[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.instrument = instrument;
|
|
4
|
+
// One call per framework: `instrument('nest')`. Applies the right instrumentation and returns what it enabled.
|
|
5
|
+
const load_js_1 = require("./load.js");
|
|
6
|
+
const instrument_js_1 = require("./instrument.js");
|
|
7
|
+
const db_js_1 = require("./integrations/db.js");
|
|
8
|
+
const postgres_js_1 = require("./integrations/postgres.js");
|
|
9
|
+
const bullmq_js_1 = require("./integrations/bullmq.js");
|
|
10
|
+
const HTTP = '@opentelemetry/instrumentation-http';
|
|
11
|
+
const UNDICI = '@opentelemetry/instrumentation-undici';
|
|
12
|
+
/**
|
|
13
|
+
* `instrument('nest' | 'express' | 'next' | 'bullmq' | 'pg' | 'postgres' | 'ioredis')`. Call it after `init()`.
|
|
14
|
+
*
|
|
15
|
+
* - `nest`, `express`: node:http server instrumentation; server spans are renamed `METHOD /route/:param` from the matched route (Nest on Express).
|
|
16
|
+
* - `next`: http and undici (fetch); Next's own span filtering is `init`'s `nextInternals` (applied when `NEXT_RUNTIME` is set).
|
|
17
|
+
* - `bullmq`: producer and worker spans with trace context in the job (`instrumentBullMQ`); order does not matter, it patches the classes.
|
|
18
|
+
* - `postgres`: postgres.js through its diagnostics channel; order does not matter.
|
|
19
|
+
* - `pg`, `ioredis`: the OTel instrumentation, which hooks `require`: call before the first `require('pg')` / `import 'pg'` (best: the `/register` preload).
|
|
20
|
+
*
|
|
21
|
+
* Returns the packages or integrations enabled by this call (empty when already on, or its peer is not installed).
|
|
22
|
+
*/
|
|
23
|
+
function instrument(name, opts = {}) {
|
|
24
|
+
const self = opts.selfUrls ?? [];
|
|
25
|
+
const on = (pkgs) => {
|
|
26
|
+
const done = pkgs.filter((p) => (0, instrument_js_1.instrumentOne)(p, self));
|
|
27
|
+
if (pkgs.includes(HTTP) && done.includes(HTTP))
|
|
28
|
+
(0, db_js_1.setHttpServerActive)(true);
|
|
29
|
+
return done;
|
|
30
|
+
};
|
|
31
|
+
switch (name) {
|
|
32
|
+
case 'nest':
|
|
33
|
+
case 'express': return on([HTTP]);
|
|
34
|
+
case 'next': return on([HTTP, UNDICI]);
|
|
35
|
+
case 'pg': return on(['@opentelemetry/instrumentation-pg']);
|
|
36
|
+
case 'ioredis': return on(['@opentelemetry/instrumentation-ioredis']);
|
|
37
|
+
case 'postgres':
|
|
38
|
+
(0, load_js_1.load)('postgres');
|
|
39
|
+
(0, postgres_js_1.instrumentPostgres)();
|
|
40
|
+
return ['postgres.js'];
|
|
41
|
+
case 'bullmq': return (0, bullmq_js_1.instrumentBullMQ)((0, load_js_1.load)('bullmq')) ? ['bullmq'] : [];
|
|
42
|
+
default: throw new Error(`watchtower: instrument(${JSON.stringify(name)}): expected nest, express, next, bullmq, pg, postgres or ioredis`);
|
|
43
|
+
}
|
|
44
|
+
}
|
package/dist/cjs/instrument.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
/** Instrumentation packages already registered in this process (by `init` or `instrument()`), so none is patched twice. */
|
|
2
|
+
export declare const registered: Set<string>;
|
|
1
3
|
interface Providers {
|
|
2
4
|
tracerProvider: unknown;
|
|
3
5
|
meterProvider?: unknown;
|
|
4
6
|
}
|
|
7
|
+
/** Register one entry by package name (for `instrument(name)`); false when already registered or not installed. Uses the global providers. */
|
|
8
|
+
export declare function instrumentOne(pkg: string, selfUrls?: string[]): boolean;
|
|
5
9
|
/**
|
|
6
10
|
* Register whichever of the OTel instrumentations is installed (http, undici, pg, ioredis; with `auto` also mysql2) and,
|
|
7
11
|
* with `auto`, patch postgres.js and better-sqlite3 when installed. Returns the names that were enabled.
|