@omaralex24/zenith-ai 0.0.0-stage → 0.1.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.
@@ -0,0 +1,46 @@
1
+ import type { CaptureMode, ZenithAIClientOptions, ZenithSpanInput } from "./types.js";
2
+ export interface ErrorCauseEntry {
3
+ name?: string;
4
+ message?: string;
5
+ code?: string;
6
+ detail?: string;
7
+ constraint?: string;
8
+ hint?: string;
9
+ table?: string;
10
+ column?: string;
11
+ schema?: string;
12
+ severity?: string;
13
+ }
14
+ export declare function extractErrorCauseChain(value: unknown, redact?: (text: string) => string): ErrorCauseEntry[];
15
+ export declare function formatErrorWithCause(value: unknown, redact?: (text: string) => string): string | null;
16
+ export declare class ZenithAIClient {
17
+ readonly captureMode: CaptureMode;
18
+ readonly maxBatchBytes: number;
19
+ readonly flushIntervalMs: number;
20
+ private readonly host?;
21
+ private readonly apiKey?;
22
+ private readonly redact?;
23
+ private readonly fetchFn?;
24
+ private readonly onError?;
25
+ private queue;
26
+ private queuedByteCount;
27
+ private readonly maxQueueSize;
28
+ private readonly maxQueueBytes;
29
+ private readonly maxSpanBytes;
30
+ private timer?;
31
+ private flushing;
32
+ private stopped;
33
+ constructor(options: ZenithAIClientOptions);
34
+ private notifyError;
35
+ recordSpan(input: ZenithSpanInput): void;
36
+ flush(): Promise<void>;
37
+ shutdown(): Promise<void>;
38
+ private schedule;
39
+ private enforceQueueLimits;
40
+ private requeueBatch;
41
+ private flushInner;
42
+ }
43
+ export declare function newTraceId(): string;
44
+ export declare function newSpanId(): string;
45
+ export declare function newEventId(): string;
46
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAgB,qBAAqB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAYpG,MAAM,WAAW,eAAe;IAC9B,IAA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AAO,CAAC,KAAK,CAAC,CAAiB;IAC/B,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,qBAAqB;IAW1C,OAAO,CAAC,WAAW;IAKnB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAuElC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAM/B,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,YAAY;YAMN,UAAU;CAiDzB;AAmKD,wBAAgB,UAAU,IAAI,MAAM,CAAsB;AAC1D,wBAAgB,SAAS,IAAI,MAAM,CAAqB;AACxD,wBAAgB,UAAU,IAAI,MAAM,CAAyB"}
package/dist/client.js ADDED
@@ -0,0 +1,529 @@
1
+ import { randomBytes, randomUUID } from "node:crypto";
2
+ import { getZenithContext } from "./context.js";
3
+ const encoder = new TextEncoder();
4
+ const secretKey = /(secret|password|passwd|api[-_]?key|authorization|token|private[-_]?key|client[-_]?secret|credential|bearer)/i;
5
+ const tokenCountKey = /^(input|output|cached|cache_write|reasoning|prompt|completion|total)_tokens$|^(input|output|cached|cacheWrite|reasoning|prompt|completion|total)Tokens$|^token_count$|^tokenCount$/;
6
+ const secretText = /(Bearer\s+[A-Za-z0-9._~+/=-]+|sk-[A-Za-z0-9_-]{12,}|zn_[A-Za-z0-9]+_[A-Za-z0-9_-]+)/gi;
7
+ const secretAssignmentText = /\b(password|passwd|pwd|secret|api[-_]?key|authorization|access[-_]?token|refresh[-_]?token|auth[-_]?token|token|private[-_]?key|client[-_]?secret|credential)\b(["']?\s*[:=]\s*)(?:"[^"\r\n]*"|'[^'\r\n]*'|[^\s,;)]+)/gi;
8
+ function byteLen(text) { return encoder.encode(text).byteLength; }
9
+ function spanId() { return randomBytes(8).toString("hex"); }
10
+ function traceId() { return randomBytes(16).toString("hex"); }
11
+ const MAX_ERROR_CHAIN_LENGTH = 5;
12
+ const MAX_ERROR_MESSAGE_CHARS = 4096;
13
+ const MAX_ERROR_CAUSE_FIELD_CHARS = 2048;
14
+ const TRUNCATED_SUFFIX = "…[Truncated]";
15
+ const errorCauseFields = ["name", "message", "code", "detail", "constraint", "hint", "table", "column", "schema", "severity"];
16
+ const errorCauseDetailOrder = ["constraint", "detail", "hint", "table", "column", "schema", "severity"];
17
+ function hasErrorInput(value) {
18
+ return value !== undefined && value !== null && value !== false && value !== "";
19
+ }
20
+ function safeReadProperty(value, key) {
21
+ try {
22
+ return value[key];
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
28
+ function diagnosticText(value, redact) {
29
+ if (typeof value === "string")
30
+ return scrubText(value, redact);
31
+ if (typeof value === "number" && Number.isFinite(value))
32
+ return scrubText(String(value), redact);
33
+ if (typeof value === "boolean" || typeof value === "bigint")
34
+ return scrubText(String(value), redact);
35
+ return undefined;
36
+ }
37
+ function fallbackErrorText(value, redact) {
38
+ const direct = diagnosticText(value, redact);
39
+ if (direct)
40
+ return direct;
41
+ try {
42
+ const text = String(value);
43
+ return text && text !== "[object Object]" ? scrubText(text, redact) : undefined;
44
+ }
45
+ catch {
46
+ return undefined;
47
+ }
48
+ }
49
+ function capChars(text, maxChars) {
50
+ if (text.length <= maxChars)
51
+ return text;
52
+ return `${text.slice(0, Math.max(0, maxChars - TRUNCATED_SUFFIX.length))}${TRUNCATED_SUFFIX}`;
53
+ }
54
+ function compactWhitespace(text) {
55
+ return text.replace(/\s+/g, " ").trim();
56
+ }
57
+ export function extractErrorCauseChain(value, redact) {
58
+ const chain = [];
59
+ if (!hasErrorInput(value))
60
+ return chain;
61
+ const seen = new WeakSet();
62
+ let current = value;
63
+ try {
64
+ for (let depth = 0; depth < MAX_ERROR_CHAIN_LENGTH && hasErrorInput(current); depth += 1) {
65
+ const entry = {};
66
+ if ((typeof current === "object" && current !== null) || typeof current === "function") {
67
+ const objectValue = current;
68
+ if (seen.has(objectValue))
69
+ break;
70
+ seen.add(objectValue);
71
+ for (const field of errorCauseFields) {
72
+ const text = diagnosticText(safeReadProperty(current, field), redact);
73
+ if (text)
74
+ entry[field] = text;
75
+ }
76
+ if (!errorCauseFields.some((field) => entry[field])) {
77
+ const fallback = fallbackErrorText(current, redact);
78
+ if (fallback)
79
+ entry.message = fallback;
80
+ }
81
+ chain.push(entry);
82
+ current = safeReadProperty(current, "cause");
83
+ }
84
+ else {
85
+ const text = diagnosticText(current, redact) ?? fallbackErrorText(current, redact);
86
+ if (text)
87
+ entry.message = text;
88
+ chain.push(entry);
89
+ break;
90
+ }
91
+ }
92
+ }
93
+ catch {
94
+ if (chain.length === 0)
95
+ chain.push({ message: "[unreadable error]" });
96
+ }
97
+ return chain;
98
+ }
99
+ function summarizeErrorCauseEntry(entry) {
100
+ const message = entry.message ? compactWhitespace(entry.message) : "";
101
+ const name = entry.name ? compactWhitespace(entry.name) : "";
102
+ let base = message || name || "Error";
103
+ if (entry.code)
104
+ base = `[${compactWhitespace(entry.code)}] ${base}`;
105
+ const details = [];
106
+ for (const field of errorCauseDetailOrder) {
107
+ const value = entry[field];
108
+ if (value)
109
+ details.push(`${field}: ${compactWhitespace(value)}`);
110
+ }
111
+ if (details.length > 0)
112
+ base = `${base} (${details.join(", ")})`;
113
+ return base;
114
+ }
115
+ function formatExtractedErrorChain(chain, redact) {
116
+ if (chain.length === 0)
117
+ return null;
118
+ const parts = [summarizeErrorCauseEntry(chain[0])];
119
+ for (const cause of chain.slice(1))
120
+ parts.push(`cause: ${summarizeErrorCauseEntry(cause)}`);
121
+ return capChars(scrubText(parts.join(" | "), redact), MAX_ERROR_MESSAGE_CHARS);
122
+ }
123
+ export function formatErrorWithCause(value, redact) {
124
+ if (!hasErrorInput(value))
125
+ return null;
126
+ const chain = extractErrorCauseChain(value, redact);
127
+ const formatted = formatExtractedErrorChain(chain, redact);
128
+ if (formatted)
129
+ return formatted;
130
+ const fallback = fallbackErrorText(value, redact);
131
+ return fallback ? capChars(scrubText(fallback, redact), MAX_ERROR_MESSAGE_CHARS) : null;
132
+ }
133
+ function cappedErrorCauseMetadata(chain) {
134
+ const causes = chain.slice(1).map((entry) => {
135
+ const out = {};
136
+ for (const field of errorCauseFields) {
137
+ const value = entry[field];
138
+ if (value)
139
+ out[field] = capChars(value, MAX_ERROR_CAUSE_FIELD_CHARS);
140
+ }
141
+ return out;
142
+ }).filter((entry) => Object.keys(entry).length > 0);
143
+ return causes.length > 0 ? causes : undefined;
144
+ }
145
+ function withErrorCauseMetadata(attributes, chain) {
146
+ const causes = cappedErrorCauseMetadata(chain);
147
+ if (!causes)
148
+ return attributes;
149
+ return { ...(attributes ?? {}), "error.cause": causes };
150
+ }
151
+ export class ZenithAIClient {
152
+ captureMode;
153
+ maxBatchBytes;
154
+ flushIntervalMs;
155
+ host;
156
+ apiKey;
157
+ redact;
158
+ fetchFn;
159
+ onError;
160
+ queue = [];
161
+ queuedByteCount = 2;
162
+ maxQueueSize = 5_000;
163
+ maxQueueBytes = 8 * 1024 * 1024;
164
+ maxSpanBytes = 512 * 1024;
165
+ timer;
166
+ flushing;
167
+ stopped = false;
168
+ constructor(options) {
169
+ this.host = options.host?.trim().replace(/\/$/, "") || undefined;
170
+ this.apiKey = options.apiKey?.trim() || undefined;
171
+ this.captureMode = options.captureMode ?? "redacted";
172
+ this.maxBatchBytes = Math.max(1, options.maxBatchBytes ?? 1_048_576);
173
+ this.flushIntervalMs = Math.max(10, options.flushIntervalMs ?? 2_000);
174
+ this.redact = options.redact;
175
+ this.fetchFn = options.fetchFn;
176
+ this.onError = options.onError;
177
+ }
178
+ notifyError(error) {
179
+ if (!this.onError)
180
+ return;
181
+ try {
182
+ this.onError(error);
183
+ }
184
+ catch { /* never disrupt host app */ }
185
+ }
186
+ recordSpan(input) {
187
+ try {
188
+ if (this.stopped || !this.host || !this.apiKey || !input || typeof input !== "object")
189
+ return;
190
+ const ctx = getZenithContext() ?? {};
191
+ const now = Date.now();
192
+ const kind = String(input.spanKind ?? "other");
193
+ const metered = kind === "llm" || kind === "embedding";
194
+ const mode = input.captureMode ?? this.captureMode;
195
+ const rawTraceId = String(input.traceId ?? ctx.traceId ?? "").trim();
196
+ const rawSpanId = String(input.spanId ?? "").trim();
197
+ const rawName = String(input.name ?? "").trim();
198
+ const { error: errorValue, errorMessage: rawErrorMessage, ...inputFields } = input;
199
+ const errorInput = hasErrorInput(errorValue) ? errorValue : rawErrorMessage;
200
+ const errorChain = hasErrorInput(errorInput) ? extractErrorCauseChain(errorInput, this.redact) : [];
201
+ const formattedErrorMessage = hasErrorInput(errorInput)
202
+ ? formatExtractedErrorChain(errorChain, this.redact) ?? formatErrorWithCause(errorInput, this.redact)
203
+ : (rawErrorMessage === null ? null : undefined);
204
+ let attributes = mode === "metadata_only" ? undefined : scrubObject(input.attributes, this.redact);
205
+ if (mode !== "metadata_only")
206
+ attributes = withErrorCauseMetadata(attributes, errorChain);
207
+ const span = {
208
+ ...inputFields,
209
+ traceId: (rawTraceId || traceId()).slice(0, 128),
210
+ spanId: (rawSpanId || spanId()).slice(0, 128),
211
+ parentSpanId: input.parentSpanId !== undefined ? input.parentSpanId : (ctx.parentSpanId ?? null),
212
+ startMs: typeof input.startMs === "number" && Number.isFinite(input.startMs) ? input.startMs : now,
213
+ durationMs: typeof input.durationMs === "number" && Number.isFinite(input.durationMs) ? Math.max(0, input.durationMs) : 0,
214
+ sessionId: input.sessionId ?? ctx.sessionId,
215
+ distinctId: input.distinctId ?? ctx.distinctId,
216
+ orgId: input.orgId ?? ctx.orgId,
217
+ orgPlan: input.orgPlan ?? ctx.orgPlan,
218
+ name: rawName || kind || "span",
219
+ rootName: input.rootName ?? ctx.rootName,
220
+ spanKind: kind,
221
+ status: input.status === "error" ? "error" : "ok",
222
+ errorMessage: formattedErrorMessage,
223
+ inputTokens: metered ? input.inputTokens ?? undefined : undefined,
224
+ outputTokens: metered ? input.outputTokens ?? undefined : undefined,
225
+ cachedTokens: metered ? input.cachedTokens ?? undefined : undefined,
226
+ cacheWriteTokens: metered ? input.cacheWriteTokens ?? undefined : undefined,
227
+ reasoningTokens: metered ? input.reasoningTokens ?? undefined : undefined,
228
+ costUsdMicros: metered ? input.costUsdMicros ?? undefined : undefined,
229
+ captureMode: mode,
230
+ input: mode === "metadata_only" ? undefined : scrubValue(input.input, this.redact),
231
+ output: mode === "metadata_only" ? undefined : scrubValue(input.output, this.redact),
232
+ attributes,
233
+ };
234
+ let size = byteLen(JSON.stringify(wireSpan(span))) + 1;
235
+ if (size > this.maxSpanBytes) {
236
+ const truncationNotice = "[Truncated: span exceeded byte budget]";
237
+ if (span.input !== undefined)
238
+ span.input = truncationNotice;
239
+ if (span.output !== undefined)
240
+ span.output = truncationNotice;
241
+ size = byteLen(JSON.stringify(wireSpan(span))) + 1;
242
+ if (size > this.maxSpanBytes && span.attributes !== undefined) {
243
+ span.attributes = { truncated: true };
244
+ size = byteLen(JSON.stringify(wireSpan(span))) + 1;
245
+ }
246
+ if (size > this.maxSpanBytes) {
247
+ return;
248
+ }
249
+ }
250
+ this.queue.push({ span, size });
251
+ this.queuedByteCount += size;
252
+ this.enforceQueueLimits();
253
+ this.schedule();
254
+ if (this.queuedByteCount >= this.maxBatchBytes)
255
+ void this.flush();
256
+ }
257
+ catch (error) {
258
+ // Observability must never break the host application.
259
+ this.notifyError(error);
260
+ }
261
+ }
262
+ async flush() {
263
+ if (this.flushing)
264
+ return this.flushing;
265
+ this.flushing = this.flushInner().finally(() => { this.flushing = undefined; });
266
+ return this.flushing;
267
+ }
268
+ async shutdown() {
269
+ this.stopped = true;
270
+ if (this.timer)
271
+ clearTimeout(this.timer);
272
+ await this.flush().catch(() => undefined);
273
+ }
274
+ schedule() {
275
+ if (this.timer || this.stopped)
276
+ return;
277
+ this.timer = setTimeout(() => {
278
+ this.timer = undefined;
279
+ void this.flush();
280
+ }, this.flushIntervalMs);
281
+ this.timer.unref?.();
282
+ }
283
+ enforceQueueLimits() {
284
+ while (this.queue.length > this.maxQueueSize || (this.queue.length > 0 && this.queuedByteCount > this.maxQueueBytes)) {
285
+ const dropped = this.queue.shift();
286
+ if (dropped)
287
+ this.queuedByteCount -= dropped.size;
288
+ }
289
+ if (this.queue.length === 0) {
290
+ this.queuedByteCount = 2;
291
+ }
292
+ }
293
+ requeueBatch(batch) {
294
+ this.queue.unshift(...batch);
295
+ this.queuedByteCount += batch.reduce((sum, entry) => sum + entry.size, 0);
296
+ this.enforceQueueLimits();
297
+ }
298
+ async flushInner() {
299
+ try {
300
+ if (!this.host || !this.apiKey || this.queue.length === 0)
301
+ return;
302
+ const fetcher = this.fetchFn ?? globalThis.fetch;
303
+ if (!fetcher)
304
+ return;
305
+ while (this.queue.length > 0) {
306
+ const batch = [];
307
+ let bytes = 15;
308
+ while (this.queue.length > 0) {
309
+ if (batch.length >= 500)
310
+ break;
311
+ const next = this.queue[0];
312
+ if (batch.length > 0 && bytes + next.size > this.maxBatchBytes)
313
+ break;
314
+ batch.push(next);
315
+ bytes += next.size;
316
+ this.queue.shift();
317
+ this.queuedByteCount -= next.size;
318
+ if (next.size >= this.maxBatchBytes)
319
+ break;
320
+ }
321
+ let response;
322
+ try {
323
+ response = await fetcher(`${this.host}/ai/spans`, {
324
+ method: "POST",
325
+ headers: {
326
+ "content-type": "application/json",
327
+ authorization: `Bearer ${this.apiKey}`,
328
+ "x-zenith-ai-key": this.apiKey,
329
+ },
330
+ body: JSON.stringify({ spans: batch.map((entry) => wireSpan(entry.span)) }),
331
+ });
332
+ }
333
+ catch {
334
+ this.requeueBatch(batch);
335
+ return;
336
+ }
337
+ if (!response.ok) {
338
+ const retryable = response.status === 429 || response.status >= 500;
339
+ if (retryable) {
340
+ this.requeueBatch(batch);
341
+ }
342
+ this.notifyError(new Error(`Zenith /ai/spans failed with HTTP ${response.status}`));
343
+ // Other 4xx responses are contract/validation failures: retrying them forever would
344
+ // pin the queue, so the batch is deliberately dropped.
345
+ return;
346
+ }
347
+ }
348
+ }
349
+ catch (error) {
350
+ // Fail-safe by contract: network failures are swallowed and data may be retried on a later flush.
351
+ this.notifyError(error);
352
+ }
353
+ }
354
+ }
355
+ const validSpanKinds = new Set(["agent", "workflow", "step", "llm", "tool", "embedding", "retrieval", "other"]);
356
+ const MAX_SCRUB_DEPTH = 24;
357
+ const MAX_SCRUB_ITEMS = 256;
358
+ const MAX_SCRUB_KEYS = 256;
359
+ const MAX_SCRUB_STRING_CHARS = 128 * 1024;
360
+ function integer(value) {
361
+ return typeof value === "number" && Number.isFinite(value) ? Math.round(value) : null;
362
+ }
363
+ function wireSpan(span) {
364
+ return {
365
+ trace_id: span.traceId,
366
+ span_id: span.spanId,
367
+ parent_span_id: span.parentSpanId ?? null,
368
+ start_ms: integer(span.startMs),
369
+ duration_ms: integer(span.durationMs),
370
+ ttft_ms: integer(span.ttftMs),
371
+ session_id: span.sessionId,
372
+ distinct_id: span.distinctId,
373
+ org_id: span.orgId,
374
+ org_plan: span.orgPlan ?? null,
375
+ span_kind: validSpanKinds.has(span.spanKind) ? span.spanKind : "other",
376
+ name: span.name,
377
+ root_name: span.rootName,
378
+ provider: span.provider,
379
+ model: span.model,
380
+ finish_reason: span.finishReason ?? null,
381
+ status: span.status,
382
+ error_message: span.errorMessage ?? null,
383
+ input_tokens: integer(span.inputTokens),
384
+ output_tokens: integer(span.outputTokens),
385
+ cached_tokens: integer(span.cachedTokens),
386
+ cache_write_tokens: integer(span.cacheWriteTokens),
387
+ reasoning_tokens: integer(span.reasoningTokens),
388
+ cost_usd_micros: integer(span.costUsdMicros),
389
+ capture_mode: span.captureMode,
390
+ input: span.input,
391
+ output: span.output,
392
+ attributes: span.attributes,
393
+ };
394
+ }
395
+ function scrubText(text, custom) {
396
+ let out = text
397
+ .replace(secretText, "[REDACTED]")
398
+ .replace(secretAssignmentText, "$1$2[REDACTED]");
399
+ if (custom) {
400
+ try {
401
+ const customized = custom(out);
402
+ if (typeof customized === "string")
403
+ out = customized;
404
+ }
405
+ catch { /* ignore user redactor failures */ }
406
+ }
407
+ return out;
408
+ }
409
+ function scrubObject(input, custom) {
410
+ if (!input || typeof input !== "object")
411
+ return undefined;
412
+ const result = scrubValue(input, custom, new WeakSet(), 0);
413
+ return result && typeof result === "object" && !Array.isArray(result)
414
+ ? result
415
+ : undefined;
416
+ }
417
+ function scrubValue(value, custom, seen = new WeakSet(), depth = 0) {
418
+ if (value === null || value === undefined)
419
+ return value;
420
+ if (typeof value === "string") {
421
+ const capped = value.length > MAX_SCRUB_STRING_CHARS ? `${value.slice(0, MAX_SCRUB_STRING_CHARS)}…[Truncated]` : value;
422
+ return scrubText(capped, custom);
423
+ }
424
+ if (typeof value === "number")
425
+ return Number.isFinite(value) ? value : null;
426
+ if (typeof value === "boolean")
427
+ return value;
428
+ if (typeof value === "bigint")
429
+ return value.toString();
430
+ if (typeof value === "function" || typeof value === "symbol")
431
+ return undefined;
432
+ if (value instanceof Date)
433
+ return Number.isNaN(value.getTime()) ? null : value.toISOString();
434
+ if (value instanceof Error) {
435
+ return {
436
+ name: scrubValue(safeReadProperty(value, "name"), custom, seen, depth + 1),
437
+ message: scrubValue(safeReadProperty(value, "message"), custom, seen, depth + 1),
438
+ };
439
+ }
440
+ if (depth >= MAX_SCRUB_DEPTH)
441
+ return "[MaxDepth]";
442
+ if (typeof value === "object") {
443
+ if (seen.has(value))
444
+ return "[Circular]";
445
+ seen.add(value);
446
+ try {
447
+ if (Array.isArray(value)) {
448
+ const sliced = value.slice(0, MAX_SCRUB_ITEMS).map((item) => scrubValue(item, custom, seen, depth + 1));
449
+ if (value.length > MAX_SCRUB_ITEMS)
450
+ sliced.push("[Truncated]");
451
+ return sliced;
452
+ }
453
+ if (value instanceof Map) {
454
+ const out = {};
455
+ let count = 0;
456
+ for (const [k, v] of value.entries()) {
457
+ if (count >= MAX_SCRUB_KEYS) {
458
+ out.__truncated__ = true;
459
+ break;
460
+ }
461
+ count += 1;
462
+ const key = String(k);
463
+ if (secretKey.test(key) && !(typeof v === "number" && tokenCountKey.test(key)))
464
+ out[key] = "[REDACTED]";
465
+ else {
466
+ const scrubbed = scrubValue(v, custom, seen, depth + 1);
467
+ if (scrubbed !== undefined)
468
+ out[key] = scrubbed;
469
+ }
470
+ }
471
+ return out;
472
+ }
473
+ if (value instanceof Set) {
474
+ const items = [];
475
+ let count = 0;
476
+ for (const item of value) {
477
+ if (count >= MAX_SCRUB_ITEMS) {
478
+ items.push("[Truncated]");
479
+ break;
480
+ }
481
+ count += 1;
482
+ items.push(scrubValue(item, custom, seen, depth + 1));
483
+ }
484
+ return items;
485
+ }
486
+ const out = {};
487
+ let count = 0;
488
+ let keys;
489
+ try {
490
+ keys = Object.keys(value);
491
+ }
492
+ catch {
493
+ return "[Unserializable]";
494
+ }
495
+ for (const key of keys) {
496
+ let child;
497
+ try {
498
+ child = value[key];
499
+ }
500
+ catch {
501
+ child = "[Unreadable]";
502
+ }
503
+ if (typeof child === "function" || typeof child === "symbol")
504
+ continue;
505
+ if (count >= MAX_SCRUB_KEYS) {
506
+ out.__truncated__ = true;
507
+ break;
508
+ }
509
+ count += 1;
510
+ if (secretKey.test(key) && !(typeof child === "number" && tokenCountKey.test(key)))
511
+ out[key] = "[REDACTED]";
512
+ else {
513
+ const scrubbed = scrubValue(child, custom, seen, depth + 1);
514
+ if (scrubbed !== undefined)
515
+ out[key] = scrubbed;
516
+ }
517
+ }
518
+ return out;
519
+ }
520
+ finally {
521
+ seen.delete(value);
522
+ }
523
+ }
524
+ return value;
525
+ }
526
+ export function newTraceId() { return traceId(); }
527
+ export function newSpanId() { return spanId(); }
528
+ export function newEventId() { return randomUUID(); }
529
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,SAAS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OAAO,GAAG,CAAC;QACb,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,UAAU,KAAa,OAAO,OAAO,EAAE,CAAC,CAAC,CAAC;AAC1D,MAAM,UAAU,SAAS,KAAa,OAAO,MAAM,EAAE,CAAC,CAAC,CAAC;AACxD,MAAM,UAAU,UAAU,KAAa,OAAO,UAAU,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { ZenithContext } from "./types.js";
2
+ export declare function withZenith<T>(context: ZenithContext, fn: () => T): T;
3
+ export declare function getZenithContext(): ZenithContext | undefined;
4
+ export declare function fromTraceparent(headers: Headers | Record<string, string | string[] | undefined> | string | undefined): Pick<ZenithContext, "traceId"> & {
5
+ parentSpanId?: string;
6
+ };
7
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIhD,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAGpE;AAED,wBAAgB,gBAAgB,IAAI,aAAa,GAAG,SAAS,CAG5D;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAYjL"}
@@ -0,0 +1,28 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ const storage = new AsyncLocalStorage();
3
+ export function withZenith(context, fn) {
4
+ const parent = storage.getStore() ?? {};
5
+ return storage.run({ ...parent, ...context }, fn);
6
+ }
7
+ export function getZenithContext() {
8
+ const ctx = storage.getStore();
9
+ return ctx ? { ...ctx } : undefined;
10
+ }
11
+ export function fromTraceparent(headers) {
12
+ let value;
13
+ if (typeof headers === "string")
14
+ value = headers;
15
+ else if (headers instanceof Headers)
16
+ value = headers.get("traceparent") ?? undefined;
17
+ else if (headers) {
18
+ const raw = headers.traceparent ?? headers.Traceparent ?? headers["Traceparent"];
19
+ value = Array.isArray(raw) ? raw[0] : raw;
20
+ }
21
+ if (!value)
22
+ return {};
23
+ const parts = value.trim().split("-");
24
+ if (parts.length < 4 || !/^[0-9a-f]{32}$/i.test(parts[1] ?? "") || !/^[0-9a-f]{16}$/i.test(parts[2] ?? ""))
25
+ return {};
26
+ return { traceId: parts[1].toLowerCase(), parentSpanId: parts[2].toLowerCase() };
27
+ }
28
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAiB,CAAC;AAEvD,MAAM,UAAU,UAAU,CAAI,OAAsB,EAAE,EAAW;IAC/D,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;IACxC,OAAO,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC/B,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAqF;IACnH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