@watchtowerobservability/node 0.0.0-stage → 0.2.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/LICENSE +202 -0
- package/README.md +121 -2
- package/dist/cjs/buffer.d.ts +49 -0
- package/dist/cjs/buffer.js +134 -0
- package/dist/cjs/errors.d.ts +17 -0
- package/dist/cjs/errors.js +55 -0
- package/dist/cjs/index.d.ts +120 -0
- package/dist/cjs/index.js +302 -0
- package/dist/cjs/integrations/azure-functions.d.ts +18 -0
- package/dist/cjs/integrations/azure-functions.js +97 -0
- package/dist/cjs/integrations/express.d.ts +25 -0
- package/dist/cjs/integrations/express.js +58 -0
- package/dist/cjs/integrations/fastify.d.ts +6 -0
- package/dist/cjs/integrations/fastify.js +44 -0
- package/dist/cjs/integrations/genai-agents.d.ts +36 -0
- package/dist/cjs/integrations/genai-agents.js +124 -0
- package/dist/cjs/integrations/genai-stream.d.ts +19 -0
- package/dist/cjs/integrations/genai-stream.js +135 -0
- package/dist/cjs/integrations/genai.d.ts +18 -0
- package/dist/cjs/integrations/genai.js +150 -0
- package/dist/cjs/integrations/koa.d.ts +19 -0
- package/dist/cjs/integrations/koa.js +34 -0
- package/dist/cjs/integrations/lambda.d.ts +11 -0
- package/dist/cjs/integrations/lambda.js +68 -0
- package/dist/cjs/integrations/logs.d.ts +10 -0
- package/dist/cjs/integrations/logs.js +77 -0
- package/dist/cjs/integrations/nestjs.d.ts +16 -0
- package/dist/cjs/integrations/nestjs.js +30 -0
- package/dist/cjs/integrations/next.d.ts +11 -0
- package/dist/cjs/integrations/next.js +59 -0
- package/dist/cjs/integrations/prisma.d.ts +3 -0
- package/dist/cjs/integrations/prisma.js +33 -0
- package/dist/cjs/integrations/util.d.ts +9 -0
- package/dist/cjs/integrations/util.js +37 -0
- package/dist/cjs/jest.d.ts +21 -0
- package/dist/cjs/jest.js +45 -0
- package/dist/cjs/load.d.ts +1 -0
- package/dist/cjs/load.js +11 -0
- package/dist/cjs/metrics.d.ts +10 -0
- package/dist/cjs/metrics.js +81 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/payload.d.ts +42 -0
- package/dist/cjs/payload.js +145 -0
- package/dist/cjs/probes.d.ts +97 -0
- package/dist/cjs/probes.js +422 -0
- package/dist/cjs/profiling.d.ts +81 -0
- package/dist/cjs/profiling.js +253 -0
- package/dist/cjs/reporter-core.d.ts +32 -0
- package/dist/cjs/reporter-core.js +102 -0
- package/dist/cjs/test-plan.d.ts +93 -0
- package/dist/cjs/test-plan.js +262 -0
- package/dist/cjs/vitest.d.ts +27 -0
- package/dist/cjs/vitest.js +52 -0
- package/dist/esm/buffer.d.ts +49 -0
- package/dist/esm/buffer.js +92 -0
- package/dist/esm/errors.d.ts +17 -0
- package/dist/esm/errors.js +50 -0
- package/dist/esm/index.d.ts +120 -0
- package/dist/esm/index.js +251 -0
- package/dist/esm/integrations/azure-functions.d.ts +18 -0
- package/dist/esm/integrations/azure-functions.js +60 -0
- package/dist/esm/integrations/express.d.ts +25 -0
- package/dist/esm/integrations/express.js +54 -0
- package/dist/esm/integrations/fastify.d.ts +6 -0
- package/dist/esm/integrations/fastify.js +41 -0
- package/dist/esm/integrations/genai-agents.d.ts +36 -0
- package/dist/esm/integrations/genai-agents.js +118 -0
- package/dist/esm/integrations/genai-stream.d.ts +19 -0
- package/dist/esm/integrations/genai-stream.js +130 -0
- package/dist/esm/integrations/genai.d.ts +18 -0
- package/dist/esm/integrations/genai.js +138 -0
- package/dist/esm/integrations/koa.d.ts +19 -0
- package/dist/esm/integrations/koa.js +31 -0
- package/dist/esm/integrations/lambda.d.ts +11 -0
- package/dist/esm/integrations/lambda.js +32 -0
- package/dist/esm/integrations/logs.d.ts +10 -0
- package/dist/esm/integrations/logs.js +40 -0
- package/dist/esm/integrations/nestjs.d.ts +16 -0
- package/dist/esm/integrations/nestjs.js +26 -0
- package/dist/esm/integrations/next.d.ts +11 -0
- package/dist/esm/integrations/next.js +22 -0
- package/dist/esm/integrations/prisma.d.ts +3 -0
- package/dist/esm/integrations/prisma.js +30 -0
- package/dist/esm/integrations/util.d.ts +9 -0
- package/dist/esm/integrations/util.js +32 -0
- package/dist/esm/jest.d.ts +21 -0
- package/dist/esm/jest.js +41 -0
- package/dist/esm/load.d.ts +1 -0
- package/dist/esm/load.js +5 -0
- package/dist/esm/metrics.d.ts +10 -0
- package/dist/esm/metrics.js +44 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/payload.d.ts +42 -0
- package/dist/esm/payload.js +131 -0
- package/dist/esm/probes.d.ts +97 -0
- package/dist/esm/probes.js +412 -0
- package/dist/esm/profiling.d.ts +81 -0
- package/dist/esm/profiling.js +242 -0
- package/dist/esm/reporter-core.d.ts +32 -0
- package/dist/esm/reporter-core.js +63 -0
- package/dist/esm/test-plan.d.ts +93 -0
- package/dist/esm/test-plan.js +248 -0
- package/dist/esm/vitest.d.ts +27 -0
- package/dist/esm/vitest.js +48 -0
- package/package.json +219 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function load(id: string): unknown;
|
package/dist/esm/load.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Resource } from '@opentelemetry/resources';
|
|
2
|
+
import { MeterProvider } from '@opentelemetry/sdk-metrics';
|
|
3
|
+
import type { PushMetricExporter } from '@opentelemetry/sdk-metrics';
|
|
4
|
+
/** Explicit flag, else `WATCHTOWER_LOGS` / `WATCHTOWER_METRICS` (default on); `OTEL_*_EXPORTER=none` turns it off. */
|
|
5
|
+
export declare function switchOn(name: string, otelExporterEnv: string, flag?: boolean): boolean;
|
|
6
|
+
export interface Metrics {
|
|
7
|
+
provider: MeterProvider;
|
|
8
|
+
stop(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare function startMetrics(endpoint: string, headers: Record<string, string>, resource: Resource, bufferDir: string | undefined, fetch: typeof globalThis.fetch, exporter?: PushMetricExporter): Metrics;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Metrics: the OTel metrics SDK with a periodic OTLP/HTTP reader. Counters and histograms use
|
|
2
|
+
// delta temporality unless OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE is set. Node runtime
|
|
3
|
+
// metrics (event loop delay and utilization, GC, heap) come from the optional peer
|
|
4
|
+
// @opentelemetry/instrumentation-runtime-node when it is installed.
|
|
5
|
+
import * as nodePath from 'node:path';
|
|
6
|
+
import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
|
|
7
|
+
import { AggregationTemporalityPreference, OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
|
|
8
|
+
import { MetricSpool } from './buffer.js';
|
|
9
|
+
import { load } from './load.js';
|
|
10
|
+
/** Explicit flag, else `WATCHTOWER_LOGS` / `WATCHTOWER_METRICS` (default on); `OTEL_*_EXPORTER=none` turns it off. */
|
|
11
|
+
export function switchOn(name, otelExporterEnv, flag) {
|
|
12
|
+
if (flag !== undefined)
|
|
13
|
+
return flag;
|
|
14
|
+
const env = process.env;
|
|
15
|
+
if ((env[otelExporterEnv] || '').trim().toLowerCase() === 'none')
|
|
16
|
+
return false;
|
|
17
|
+
return !['off', 'false', '0', 'no'].includes((env[name] || 'on').trim().toLowerCase());
|
|
18
|
+
}
|
|
19
|
+
export function startMetrics(endpoint, headers, resource, bufferDir, fetch, exporter) {
|
|
20
|
+
const url = `${endpoint}/v1/metrics`;
|
|
21
|
+
let exp = exporter;
|
|
22
|
+
if (!exp) {
|
|
23
|
+
const delta = process.env.OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE
|
|
24
|
+
? {} : { temporalityPreference: AggregationTemporalityPreference.DELTA };
|
|
25
|
+
exp = new OTLPMetricExporter({ url, headers, ...delta });
|
|
26
|
+
if (bufferDir)
|
|
27
|
+
exp = new MetricSpool(exp, nodePath.join(bufferDir, 'metrics'), url, headers, fetch);
|
|
28
|
+
}
|
|
29
|
+
const interval = Number(process.env.OTEL_METRIC_EXPORT_INTERVAL) || 60000;
|
|
30
|
+
const reader = new PeriodicExportingMetricReader({
|
|
31
|
+
exporter: exp, exportIntervalMillis: interval, exportTimeoutMillis: Math.min(30000, interval),
|
|
32
|
+
});
|
|
33
|
+
const provider = new MeterProvider({ resource, readers: [reader] });
|
|
34
|
+
let runtime;
|
|
35
|
+
try {
|
|
36
|
+
const mod = load('@opentelemetry/instrumentation-runtime-node');
|
|
37
|
+
runtime = new mod.RuntimeNodeInstrumentation();
|
|
38
|
+
runtime.setMeterProvider(provider);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// optional peer not installed
|
|
42
|
+
}
|
|
43
|
+
return { provider, stop: () => runtime?.disable() };
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Span } from '@opentelemetry/api';
|
|
2
|
+
export interface CaptureRule {
|
|
3
|
+
route?: string | null;
|
|
4
|
+
request_headers?: string[];
|
|
5
|
+
response_headers?: string[];
|
|
6
|
+
body_bytes?: number;
|
|
7
|
+
graphql_query?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const HARD_MAX = 8192;
|
|
10
|
+
export declare const setCaptureRules: (r: CaptureRule[]) => void;
|
|
11
|
+
export declare const captureActive: () => boolean;
|
|
12
|
+
/** Fetch the service's rules; any failure leaves capture off. */
|
|
13
|
+
export declare function loadCaptureRules(o: {
|
|
14
|
+
apiUrl: string;
|
|
15
|
+
key: string;
|
|
16
|
+
service: string;
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
}): Promise<CaptureRule[]>;
|
|
19
|
+
/** `*` matches any run of characters (the edge's glob). */
|
|
20
|
+
export declare function glob(pat: string, s: string): boolean;
|
|
21
|
+
export declare const ruleFor: (route: string) => CaptureRule | undefined;
|
|
22
|
+
/** Default secret and PII detectors: secret-named JSON and form fields, keys, tokens, emails, SSNs, Luhn-valid cards. */
|
|
23
|
+
export declare function redactText(s: string): string;
|
|
24
|
+
export declare const textLike: (type?: string) => boolean;
|
|
25
|
+
/** First `n` UTF-8 bytes without splitting a character. */
|
|
26
|
+
export declare function capBytes(s: string, n: number): string;
|
|
27
|
+
/** Redact a wider window than kept so a secret cut at the edge is still masked, then cap. */
|
|
28
|
+
export declare const excerpt: (s: string, n: number) => string;
|
|
29
|
+
/** Operation type and name of a GraphQL document (`{ ... }` is an anonymous query). */
|
|
30
|
+
export declare function graphqlOp(doc: string): {
|
|
31
|
+
type: string;
|
|
32
|
+
name?: string;
|
|
33
|
+
} | undefined;
|
|
34
|
+
export interface Payload {
|
|
35
|
+
route: string;
|
|
36
|
+
reqType?: string;
|
|
37
|
+
reqBody?: unknown;
|
|
38
|
+
resType?: string;
|
|
39
|
+
resBody?: unknown;
|
|
40
|
+
}
|
|
41
|
+
/** Record the bodies and GraphQL operation on `span` per the rule matching the route; no rule, nothing recorded. */
|
|
42
|
+
export declare function capturePayload(span: Span, p: Payload): void;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
export const HARD_MAX = 8192;
|
|
2
|
+
const R = '[REDACTED]';
|
|
3
|
+
let rules = [];
|
|
4
|
+
export const setCaptureRules = (r) => { rules = Array.isArray(r) ? r : []; };
|
|
5
|
+
export const captureActive = () => rules.length > 0;
|
|
6
|
+
/** Fetch the service's rules; any failure leaves capture off. */
|
|
7
|
+
export async function loadCaptureRules(o) {
|
|
8
|
+
try {
|
|
9
|
+
const f = o.fetch || globalThis.fetch;
|
|
10
|
+
const res = await f(`${o.apiUrl}/v1/capture-rules?service=${encodeURIComponent(o.service)}`, {
|
|
11
|
+
headers: { Authorization: `Bearer ${o.key}` },
|
|
12
|
+
});
|
|
13
|
+
if (!res.ok)
|
|
14
|
+
return [];
|
|
15
|
+
const body = (await res.json());
|
|
16
|
+
setCaptureRules(body.rules || []);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
setCaptureRules([]);
|
|
20
|
+
}
|
|
21
|
+
return rules;
|
|
22
|
+
}
|
|
23
|
+
/** `*` matches any run of characters (the edge's glob). */
|
|
24
|
+
export function glob(pat, s) {
|
|
25
|
+
const body = pat.split('*').map((p) => p.replace(/[.+?^$()|{}[\]\\]/g, '\\$&')).join('.*');
|
|
26
|
+
return new RegExp('^' + body + '$', 's').test(s);
|
|
27
|
+
}
|
|
28
|
+
export const ruleFor = (route) => rules.find((r) => !r.route || glob(r.route, route));
|
|
29
|
+
const luhn = (s) => {
|
|
30
|
+
const d = s.replace(/\D/g, '');
|
|
31
|
+
let sum = 0;
|
|
32
|
+
for (let i = 0; i < d.length; i++) {
|
|
33
|
+
let x = Number(d[d.length - 1 - i]);
|
|
34
|
+
if (i % 2)
|
|
35
|
+
x = x * 2 > 9 ? x * 2 - 9 : x * 2;
|
|
36
|
+
sum += x;
|
|
37
|
+
}
|
|
38
|
+
return d.length >= 13 && sum % 10 === 0;
|
|
39
|
+
};
|
|
40
|
+
const SECRET_KEYS = 'password|passwd|secret|token|access_token|refresh_token|client_secret|api_?key|authorization';
|
|
41
|
+
const PATTERNS = [
|
|
42
|
+
/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g,
|
|
43
|
+
/eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,
|
|
44
|
+
/bearer\s+[A-Za-z0-9._~+/-]+=*/gi,
|
|
45
|
+
/wt[ik]_[a-z0-9]{8}_[A-Za-z0-9_-]{43}/g,
|
|
46
|
+
/(?:AKIA|ASIA)[0-9A-Z]{16}/g,
|
|
47
|
+
/gh[pousr]_[A-Za-z0-9]{36,}/g,
|
|
48
|
+
/[rs]k_(?:live|test)_[A-Za-z0-9]{16,}/g,
|
|
49
|
+
/[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/g,
|
|
50
|
+
/\b\d{3}-\d{2}-\d{4}\b/g,
|
|
51
|
+
];
|
|
52
|
+
/** Default secret and PII detectors: secret-named JSON and form fields, keys, tokens, emails, SSNs, Luhn-valid cards. */
|
|
53
|
+
export function redactText(s) {
|
|
54
|
+
let out = s
|
|
55
|
+
.replace(new RegExp(`("(?:${SECRET_KEYS})"\\s*:\\s*)"(?:[^"\\\\]|\\\\.)*"`, 'gi'), `$1"${R}"`)
|
|
56
|
+
.replace(new RegExp(`\\b((?:${SECRET_KEYS})=)[^&\\s]*`, 'gi'), `$1${R}`);
|
|
57
|
+
for (const re of PATTERNS)
|
|
58
|
+
out = out.replace(re, R);
|
|
59
|
+
return out.replace(/\b\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{1,7}\b/g, (m) => (luhn(m) ? R : m));
|
|
60
|
+
}
|
|
61
|
+
export const textLike = (type) => !type || /json|^text\/|xml|x-www-form-urlencoded|graphql/i.test(type);
|
|
62
|
+
/** First `n` UTF-8 bytes without splitting a character. */
|
|
63
|
+
export function capBytes(s, n) {
|
|
64
|
+
const b = Buffer.from(s, 'utf8');
|
|
65
|
+
if (b.length <= n)
|
|
66
|
+
return s;
|
|
67
|
+
return b.subarray(0, n).toString('utf8').replace(/�$/, '');
|
|
68
|
+
}
|
|
69
|
+
/** Redact a wider window than kept so a secret cut at the edge is still masked, then cap. */
|
|
70
|
+
export const excerpt = (s, n) => capBytes(redactText(capBytes(s, n * 2)), n);
|
|
71
|
+
/** Operation type and name of a GraphQL document (`{ ... }` is an anonymous query). */
|
|
72
|
+
export function graphqlOp(doc) {
|
|
73
|
+
const d = doc.replace(/#[^\n]*/g, '');
|
|
74
|
+
const m = /(?:^|\})\s*(query|mutation|subscription)\b\s*([_A-Za-z][_0-9A-Za-z]*)?/.exec(d);
|
|
75
|
+
if (m)
|
|
76
|
+
return { type: m[1], ...(m[2] ? { name: m[2] } : {}) };
|
|
77
|
+
return /^\s*\{/.test(d) ? { type: 'query' } : undefined;
|
|
78
|
+
}
|
|
79
|
+
const asText = (b) => {
|
|
80
|
+
if (b === undefined || b === null)
|
|
81
|
+
return undefined;
|
|
82
|
+
if (typeof b === 'string')
|
|
83
|
+
return b;
|
|
84
|
+
if (Buffer.isBuffer(b))
|
|
85
|
+
return b.toString('utf8');
|
|
86
|
+
if (typeof b.pipe === 'function')
|
|
87
|
+
return undefined; // a stream: never buffered
|
|
88
|
+
try {
|
|
89
|
+
return JSON.stringify(b);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
/** Record the bodies and GraphQL operation on `span` per the rule matching the route; no rule, nothing recorded. */
|
|
96
|
+
export function capturePayload(span, p) {
|
|
97
|
+
const rule = ruleFor(p.route);
|
|
98
|
+
if (!rule)
|
|
99
|
+
return;
|
|
100
|
+
const n = Math.min(rule.body_bytes || 0, HARD_MAX);
|
|
101
|
+
const req = textLike(p.reqType) ? asText(p.reqBody) : undefined;
|
|
102
|
+
const res = textLike(p.resType) ? asText(p.resBody) : undefined;
|
|
103
|
+
if (n > 0 && req)
|
|
104
|
+
span.setAttribute('http.request.body', excerpt(req, n));
|
|
105
|
+
if (n > 0 && res)
|
|
106
|
+
span.setAttribute('http.response.body', excerpt(res, n));
|
|
107
|
+
let doc;
|
|
108
|
+
let opName;
|
|
109
|
+
if (req && /graphql/i.test(p.reqType || ''))
|
|
110
|
+
doc = req;
|
|
111
|
+
else if (req) {
|
|
112
|
+
try {
|
|
113
|
+
const j = (typeof p.reqBody === 'object' ? p.reqBody : JSON.parse(req));
|
|
114
|
+
if (j && typeof j.query === 'string') {
|
|
115
|
+
doc = j.query;
|
|
116
|
+
if (typeof j.operationName === 'string')
|
|
117
|
+
opName = j.operationName;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch { /* not JSON */ }
|
|
121
|
+
}
|
|
122
|
+
const op = doc ? graphqlOp(doc) : undefined;
|
|
123
|
+
if (!op || !doc)
|
|
124
|
+
return;
|
|
125
|
+
span.setAttribute('graphql.operation.type', op.type);
|
|
126
|
+
const name = opName || op.name;
|
|
127
|
+
if (name)
|
|
128
|
+
span.setAttribute('graphql.operation.name', name);
|
|
129
|
+
if (rule.graphql_query)
|
|
130
|
+
span.setAttribute('graphql.document', excerpt(doc, HARD_MAX));
|
|
131
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export type Vars = Record<string, unknown>;
|
|
2
|
+
export interface ProbeDef {
|
|
3
|
+
id: string;
|
|
4
|
+
kind?: string;
|
|
5
|
+
location: {
|
|
6
|
+
file?: string;
|
|
7
|
+
line?: number;
|
|
8
|
+
function?: string;
|
|
9
|
+
};
|
|
10
|
+
condition?: string;
|
|
11
|
+
message?: string;
|
|
12
|
+
capture?: {
|
|
13
|
+
locals_depth?: number;
|
|
14
|
+
max_bytes?: number;
|
|
15
|
+
tags?: {
|
|
16
|
+
name: string;
|
|
17
|
+
value: string;
|
|
18
|
+
}[];
|
|
19
|
+
};
|
|
20
|
+
max_rate_per_min?: number;
|
|
21
|
+
expires_at?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface ProbesOptions {
|
|
24
|
+
/** API base; default `WT_API_URL` or https://api.watchtower.dev */
|
|
25
|
+
endpoint?: string;
|
|
26
|
+
/** ingestion key with scope `probes:read`; default `WT_INGEST_KEY` */
|
|
27
|
+
key?: string;
|
|
28
|
+
service?: string;
|
|
29
|
+
env?: string;
|
|
30
|
+
version?: string;
|
|
31
|
+
intervalMs?: number;
|
|
32
|
+
/** where snapshots go; default: a log record on `logger` when given */
|
|
33
|
+
emit?: (name: string, attrs: Record<string, string>) => void;
|
|
34
|
+
logger?: {
|
|
35
|
+
emit(rec: {
|
|
36
|
+
body: string;
|
|
37
|
+
attributes: Record<string, string>;
|
|
38
|
+
}): void;
|
|
39
|
+
};
|
|
40
|
+
now?: () => number;
|
|
41
|
+
fetch?: typeof fetch;
|
|
42
|
+
}
|
|
43
|
+
/** Compile a condition; throws on anything outside the subset (calls included). Self-contained: the worker embeds its source. */
|
|
44
|
+
export declare function compile(src?: string): (v: Vars) => boolean;
|
|
45
|
+
/** Flatten to dotted names: nesting past `depth` collapses, values cut to 1 KiB, total to `maxBytes`. */
|
|
46
|
+
export declare function capture(vars: Vars, depth: number, maxBytes: number): Record<string, string>;
|
|
47
|
+
/** Fill `{a.b}` from vars (missing names render empty), cut to 1 KiB. Self-contained: the worker embeds it. */
|
|
48
|
+
export declare function render(template: string, vars: Vars): string;
|
|
49
|
+
/** `capture.tags` rendered over vars; `wt.*` names are never set. */
|
|
50
|
+
export declare function tags(def: ProbeDef, vars: Vars): Record<string, string>;
|
|
51
|
+
/** The expression the worker evaluates on a paused frame: tag the active span (OTel API 1.x global). */
|
|
52
|
+
export declare function decorateExpr(attrs: Record<string, string>): string;
|
|
53
|
+
interface Live {
|
|
54
|
+
def: ProbeDef;
|
|
55
|
+
ok: (v: Vars) => boolean;
|
|
56
|
+
win: number;
|
|
57
|
+
n: number;
|
|
58
|
+
}
|
|
59
|
+
type Bp = {
|
|
60
|
+
id: string;
|
|
61
|
+
line: number;
|
|
62
|
+
urlRegex: string;
|
|
63
|
+
dec?: {
|
|
64
|
+
cond: string;
|
|
65
|
+
tags: {
|
|
66
|
+
name: string;
|
|
67
|
+
value: string;
|
|
68
|
+
}[];
|
|
69
|
+
rate: number;
|
|
70
|
+
exp: number;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
/** Parameter names of a function from its source (`argN` where a parameter is destructured or unknown). */
|
|
74
|
+
export declare function paramNames(fn: Function): string[];
|
|
75
|
+
/** The probe set of one service: `set` replaces it, `poll` refreshes it, `onHit` handles a pause. */
|
|
76
|
+
export declare function createProbes(o: ProbesOptions & {
|
|
77
|
+
post?: (defs: Bp[]) => void;
|
|
78
|
+
modules?: () => Record<string, {
|
|
79
|
+
exports: unknown;
|
|
80
|
+
} | undefined>;
|
|
81
|
+
}): {
|
|
82
|
+
set: (defs: ProbeDef[]) => void;
|
|
83
|
+
poll: () => Promise<void>;
|
|
84
|
+
onHit: (h: {
|
|
85
|
+
ids: string[];
|
|
86
|
+
fn: string;
|
|
87
|
+
url: string;
|
|
88
|
+
line: number;
|
|
89
|
+
vars: Vars;
|
|
90
|
+
}) => void;
|
|
91
|
+
live: () => Map<string, Live>;
|
|
92
|
+
};
|
|
93
|
+
/** Poll active probes and hook them through an inspector worker; `stop()` detaches everything. */
|
|
94
|
+
export declare function startProbes(o?: ProbesOptions): {
|
|
95
|
+
stop(): Promise<void>;
|
|
96
|
+
};
|
|
97
|
+
export {};
|