@watchtowerobservability/node 0.7.3 → 0.7.5
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 +40 -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 +25 -8
- package/dist/cjs/integrations/next-build.js +159 -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/pprof.d.ts +2 -0
- package/dist/cjs/pprof.js +18 -5
- package/dist/cjs/profiling.d.ts +31 -0
- package/dist/cjs/profiling.js +67 -11
- 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 +25 -8
- package/dist/esm/integrations/next-build.js +158 -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/pprof.d.ts +2 -0
- package/dist/esm/pprof.js +17 -5
- package/dist/esm/profiling.d.ts +31 -0
- package/dist/esm/profiling.js +66 -12
- 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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RedactHook } from './redact.js';
|
|
2
|
+
export type RedactPreset = 'strict' | 'pii' | 'off';
|
|
3
|
+
export declare const REDACTED = "[redacted]";
|
|
4
|
+
/** Luhn checksum over the digits of `s` (13 to 19 digits). */
|
|
5
|
+
export declare function luhn(s: string): boolean;
|
|
6
|
+
/** Replace emails, phone numbers, Luhn-valid card numbers and IP addresses in free text with `[redacted:<kind>]`. */
|
|
7
|
+
export declare function scrubPii(s: string): string;
|
|
8
|
+
/** True for attribute keys that carry secrets (`http.request.header.authorization`, `db.password`, `x-api-key`); `gen_ai.*` token counters and types are not. */
|
|
9
|
+
export declare const isSecretKey: (k: string) => boolean;
|
|
10
|
+
/** The hook for a preset, or undefined for `off`. Only strings (and arrays of strings) are touched; numbers and booleans pass. */
|
|
11
|
+
export declare function presetHook(level: RedactPreset | undefined): RedactHook | undefined;
|
|
12
|
+
/** `redact` option -> the combined hook: the preset first (default `strict`), then the user's function. */
|
|
13
|
+
export declare function resolveRedact(opt: RedactHook | RedactPreset | undefined): {
|
|
14
|
+
preset: RedactPreset;
|
|
15
|
+
hook: RedactHook | undefined;
|
|
16
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const REDACTED = '[redacted]';
|
|
2
|
+
/** Attribute keys whose string values are secrets: the server's list plus session, credential, private key. */
|
|
3
|
+
const SECRET_KEY = /(?:^|[._-])(?:authorization|cookie|set-cookie|password|passwd|pwd|secret|token|api[-_]?key|session|sid|credential|private[-_]?key)(?:$|[._-])/i;
|
|
4
|
+
const EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/g;
|
|
5
|
+
const PHONE = /\+\d{1,3}[ .-]?\(?\d{2,4}\)?[ .-]?\d{3,4}[ .-]?\d{3,4}\b/g;
|
|
6
|
+
const CARD = /\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{1,7}\b/g;
|
|
7
|
+
const IPV4 = /\b(?:\d{1,3}\.){3}\d{1,3}\b/g;
|
|
8
|
+
const IPV6 = /\b(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\b|\b(?:[0-9A-Fa-f]{1,4}:){1,6}:(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4}\b/g;
|
|
9
|
+
/** Luhn checksum over the digits of `s` (13 to 19 digits). */
|
|
10
|
+
export function luhn(s) {
|
|
11
|
+
const d = s.replace(/\D/g, '');
|
|
12
|
+
if (d.length < 13 || d.length > 19)
|
|
13
|
+
return false;
|
|
14
|
+
let sum = 0;
|
|
15
|
+
for (let i = 0; i < d.length; i++) {
|
|
16
|
+
let n = d.charCodeAt(d.length - 1 - i) - 48;
|
|
17
|
+
if (i % 2 === 1 && (n *= 2) > 9)
|
|
18
|
+
n -= 9;
|
|
19
|
+
sum += n;
|
|
20
|
+
}
|
|
21
|
+
return sum % 10 === 0;
|
|
22
|
+
}
|
|
23
|
+
/** Replace emails, phone numbers, Luhn-valid card numbers and IP addresses in free text with `[redacted:<kind>]`. */
|
|
24
|
+
export function scrubPii(s) {
|
|
25
|
+
return s
|
|
26
|
+
.replace(EMAIL, '[redacted:email]')
|
|
27
|
+
.replace(CARD, (m) => (luhn(m) ? '[redacted:card]' : m))
|
|
28
|
+
.replace(PHONE, '[redacted:phone]')
|
|
29
|
+
.replace(IPV4, (m) => (m.split('.').every((o) => Number(o) <= 255) ? '[redacted:ipv4]' : m))
|
|
30
|
+
.replace(IPV6, '[redacted:ipv6]');
|
|
31
|
+
}
|
|
32
|
+
/** True for attribute keys that carry secrets (`http.request.header.authorization`, `db.password`, `x-api-key`); `gen_ai.*` token counters and types are not. */
|
|
33
|
+
export const isSecretKey = (k) => !k.startsWith('gen_ai.') && SECRET_KEY.test(k);
|
|
34
|
+
/** The hook for a preset, or undefined for `off`. Only strings (and arrays of strings) are touched; numbers and booleans pass. */
|
|
35
|
+
export function presetHook(level) {
|
|
36
|
+
if (level === 'off')
|
|
37
|
+
return undefined;
|
|
38
|
+
const pii = level === 'pii';
|
|
39
|
+
const hook = (k, v) => {
|
|
40
|
+
if (Array.isArray(v))
|
|
41
|
+
return v.map((x) => hook(k, x));
|
|
42
|
+
if (typeof v !== 'string')
|
|
43
|
+
return v;
|
|
44
|
+
if (isSecretKey(k))
|
|
45
|
+
return REDACTED;
|
|
46
|
+
return pii ? scrubPii(v) : v;
|
|
47
|
+
};
|
|
48
|
+
return hook;
|
|
49
|
+
}
|
|
50
|
+
/** `redact` option -> the combined hook: the preset first (default `strict`), then the user's function. */
|
|
51
|
+
export function resolveRedact(opt) {
|
|
52
|
+
const preset = typeof opt === 'string' ? opt : 'strict';
|
|
53
|
+
const user = typeof opt === 'function' ? opt : undefined;
|
|
54
|
+
const base = presetHook(preset);
|
|
55
|
+
if (!user)
|
|
56
|
+
return { preset, hook: base };
|
|
57
|
+
return { preset, hook: base ? (k, v) => user(k, base(k, v)) : user };
|
|
58
|
+
}
|
package/dist/esm/register.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Preload entry: `node --import @watchtowerobservability/node/register app.mjs` (ESM) or `node -r @watchtowerobservability/node/register app.js` (CommonJS).
|
|
2
2
|
// Starts the SDK from WT_*/OTEL_* env before the app loads, so http, fetch, pg and ioredis are patched in time.
|
|
3
|
-
//
|
|
3
|
+
// Without WT_INGEST_KEY it starts nothing and says so.
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
5
|
import { register as registerHooks } from 'node:module';
|
|
6
|
-
import { init } from './index.js';
|
|
6
|
+
import { init, setOffReason } from './index.js';
|
|
7
|
+
import { searchPaths } from './load.js';
|
|
7
8
|
if (process.env.WT_INGEST_KEY || process.env.OTEL_EXPORTER_OTLP_HEADERS) {
|
|
8
9
|
try {
|
|
9
10
|
// ESM modules (node:http imported from an ES module) are only patched through OpenTelemetry's loader hook
|
|
@@ -21,10 +22,16 @@ if (process.env.WT_INGEST_KEY || process.env.OTEL_EXPORTER_OTLP_HEADERS) {
|
|
|
21
22
|
return emit.call(process, w, ...a);
|
|
22
23
|
});
|
|
23
24
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
// same search order as the peers: SDK location, cwd, entry script directory; the first that resolves wins
|
|
26
|
+
// (none: @opentelemetry/instrumentation not installed, CommonJS apps are still instrumented)
|
|
27
|
+
for (const p of searchPaths()) {
|
|
28
|
+
try {
|
|
29
|
+
// .ts/.tsx (tsx, ts-node): the hook would re-parse their TypeScript source as JS and fail once per file.
|
|
30
|
+
registerHooks('@opentelemetry/instrumentation/hook.mjs', pathToFileURL(p), { data: { exclude: [/\.[cm]?tsx?(?:[?#]|$)/] } });
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
catch { /* try the next location */ }
|
|
34
|
+
}
|
|
28
35
|
}
|
|
29
36
|
finally {
|
|
30
37
|
process.emitWarning = emit;
|
|
@@ -33,6 +40,12 @@ if (process.env.WT_INGEST_KEY || process.env.OTEL_EXPORTER_OTLP_HEADERS) {
|
|
|
33
40
|
init({});
|
|
34
41
|
}
|
|
35
42
|
catch (e) {
|
|
36
|
-
|
|
43
|
+
setOffReason(`the preload could not start the SDK (${e.message})`);
|
|
44
|
+
console.warn(`[watchtower] telemetry is OFF: register failed: ${e.message}`);
|
|
37
45
|
}
|
|
38
46
|
}
|
|
47
|
+
else {
|
|
48
|
+
setOffReason('WT_INGEST_KEY is not set');
|
|
49
|
+
if (process.env.NODE_ENV !== 'test')
|
|
50
|
+
console.warn('[watchtower] telemetry is OFF: WT_INGEST_KEY is not set, so the register preload started nothing');
|
|
51
|
+
}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -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.
|
|
2
|
+
export declare const VERSION = "0.7.5";
|
package/dist/esm/version.js
CHANGED
|
@@ -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.
|
|
2
|
+
export const VERSION = '0.7.5';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@watchtowerobservability/node",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/watchtowerobservability/watchtower-node.git"
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"module": "./dist/esm/index.js",
|
|
15
15
|
"types": "./dist/cjs/index.d.ts",
|
|
16
16
|
"bin": {
|
|
17
|
+
"wt-next-doctor": "./dist/cjs/next-doctor-cli.js",
|
|
17
18
|
"wt-next-sourcemaps": "./dist/cjs/next-sourcemaps-cli.js"
|
|
18
19
|
},
|
|
19
20
|
"files": [
|
|
@@ -141,6 +142,46 @@
|
|
|
141
142
|
"default": "./dist/cjs/integrations/next.js"
|
|
142
143
|
}
|
|
143
144
|
},
|
|
145
|
+
"./next-build": {
|
|
146
|
+
"import": {
|
|
147
|
+
"types": "./dist/esm/integrations/next-build.d.ts",
|
|
148
|
+
"default": "./dist/esm/integrations/next-build.js"
|
|
149
|
+
},
|
|
150
|
+
"require": {
|
|
151
|
+
"types": "./dist/cjs/integrations/next-build.d.ts",
|
|
152
|
+
"default": "./dist/cjs/integrations/next-build.js"
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
"./tunnel": {
|
|
156
|
+
"import": {
|
|
157
|
+
"types": "./dist/esm/integrations/next-tunnel.d.ts",
|
|
158
|
+
"default": "./dist/esm/integrations/next-tunnel.js"
|
|
159
|
+
},
|
|
160
|
+
"require": {
|
|
161
|
+
"types": "./dist/cjs/integrations/next-tunnel.d.ts",
|
|
162
|
+
"default": "./dist/cjs/integrations/next-tunnel.js"
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"./temporal": {
|
|
166
|
+
"import": {
|
|
167
|
+
"types": "./dist/esm/integrations/temporal.d.ts",
|
|
168
|
+
"default": "./dist/esm/integrations/temporal.js"
|
|
169
|
+
},
|
|
170
|
+
"require": {
|
|
171
|
+
"types": "./dist/cjs/integrations/temporal.d.ts",
|
|
172
|
+
"default": "./dist/cjs/integrations/temporal.js"
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
"./next-tunnel": {
|
|
176
|
+
"import": {
|
|
177
|
+
"types": "./dist/esm/integrations/next-tunnel.d.ts",
|
|
178
|
+
"default": "./dist/esm/integrations/next-tunnel.js"
|
|
179
|
+
},
|
|
180
|
+
"require": {
|
|
181
|
+
"types": "./dist/cjs/integrations/next-tunnel.d.ts",
|
|
182
|
+
"default": "./dist/cjs/integrations/next-tunnel.js"
|
|
183
|
+
}
|
|
184
|
+
},
|
|
144
185
|
"./prisma": {
|
|
145
186
|
"import": {
|
|
146
187
|
"types": "./dist/esm/integrations/prisma.d.ts",
|