bitfab 0.52.5 → 0.53.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/dist/autoTrace.cjs +84 -34
- package/dist/autoTrace.cjs.map +1 -1
- package/dist/autoTrace.d.cts +19 -4
- package/dist/autoTrace.d.ts +19 -4
- package/dist/autoTrace.js +9 -3
- package/dist/{chunk-CAE7HE4C.js → chunk-6IMGAODW.js} +2 -2
- package/dist/{chunk-CAE7HE4C.js.map → chunk-6IMGAODW.js.map} +1 -1
- package/dist/{chunk-3D7FNJ5R.js → chunk-CBRO6BP7.js} +2 -2
- package/dist/{chunk-3D7FNJ5R.js.map → chunk-CBRO6BP7.js.map} +1 -1
- package/dist/{chunk-3QXNM62Y.js → chunk-DTC6SIXW.js} +3 -3
- package/dist/{chunk-ZUD7OFYB.js → chunk-E5BLYL5X.js} +81 -34
- package/dist/chunk-E5BLYL5X.js.map +1 -0
- package/dist/{chunk-EMRHO6YW.js → chunk-SCXR43UF.js} +160 -33
- package/dist/chunk-SCXR43UF.js.map +1 -0
- package/dist/{chunk-6DRFQJ75.js → chunk-SJKWUQ3G.js} +2 -2
- package/dist/{http-UQT6QVBC.js → http-KP7DVTOD.js} +2 -2
- package/dist/{http-Q6UEKZRF.js → http-SEN3PUXX.js} +2 -2
- package/dist/index.cjs +206 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/node.cjs +206 -50
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +4 -4
- package/dist/{replay-UVSZFZW7.js → replay-Y5RIJOWE.js} +3 -3
- package/dist/replayCli.js +2 -2
- package/dist/seedCli.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-EMRHO6YW.js.map +0 -1
- package/dist/chunk-ZUD7OFYB.js.map +0 -1
- /package/dist/{chunk-3QXNM62Y.js.map → chunk-DTC6SIXW.js.map} +0 -0
- /package/dist/{chunk-6DRFQJ75.js.map → chunk-SJKWUQ3G.js.map} +0 -0
- /package/dist/{http-Q6UEKZRF.js.map → http-KP7DVTOD.js.map} +0 -0
- /package/dist/{http-UQT6QVBC.js.map → http-SEN3PUXX.js.map} +0 -0
- /package/dist/{replay-UVSZFZW7.js.map → replay-Y5RIJOWE.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BitfabError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CBRO6BP7.js";
|
|
4
4
|
|
|
5
5
|
// src/codeChange.ts
|
|
6
6
|
var NUL = String.fromCharCode(0);
|
|
@@ -207,7 +207,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
|
|
|
207
207
|
sessionId: seedCase.sessionId
|
|
208
208
|
})
|
|
209
209
|
);
|
|
210
|
-
const { flushTraces: flushTraces2 } = await import("./http-
|
|
210
|
+
const { flushTraces: flushTraces2 } = await import("./http-KP7DVTOD.js");
|
|
211
211
|
await flushTraces2(3e4);
|
|
212
212
|
return { pipeline, traceFunctionKey, traceIds };
|
|
213
213
|
}
|
|
@@ -744,4 +744,4 @@ export {
|
|
|
744
744
|
runRegistryMain,
|
|
745
745
|
runIfEntrypoint
|
|
746
746
|
};
|
|
747
|
-
//# sourceMappingURL=chunk-
|
|
747
|
+
//# sourceMappingURL=chunk-DTC6SIXW.js.map
|
|
@@ -4,19 +4,18 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/autoTrace.ts
|
|
6
6
|
var autoTraceGlobal = globalThis;
|
|
7
|
-
var autoTraceState = autoTraceGlobal.
|
|
7
|
+
var autoTraceState = autoTraceGlobal.__bitfabAutoTraceStateV4 ?? {
|
|
8
8
|
storage: null,
|
|
9
9
|
browserScope: void 0,
|
|
10
10
|
capturePolicies: /* @__PURE__ */ new WeakMap(),
|
|
11
11
|
activeRoots: 0
|
|
12
12
|
};
|
|
13
|
-
autoTraceGlobal.
|
|
13
|
+
autoTraceGlobal.__bitfabAutoTraceStateV4 = autoTraceState;
|
|
14
14
|
function initializeAutoTraceStorage() {
|
|
15
15
|
autoTraceState.storage ?? (autoTraceState.storage = createAsyncLocalStorage());
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function runWithAutoTraceScope(scope, fn) {
|
|
18
18
|
initializeAutoTraceStorage();
|
|
19
|
-
const scope = { context, depth };
|
|
20
19
|
if (autoTraceState.storage) {
|
|
21
20
|
return autoTraceState.storage.run(scope, fn);
|
|
22
21
|
}
|
|
@@ -28,41 +27,65 @@ function runWithAutoTraceContext(context, fn, depth = 0) {
|
|
|
28
27
|
autoTraceState.browserScope = previous;
|
|
29
28
|
}
|
|
30
29
|
}
|
|
30
|
+
function currentAutoTraceEntries() {
|
|
31
|
+
return currentAutoTraceScope()?.entries ?? [];
|
|
32
|
+
}
|
|
33
|
+
function replaceEntry(entries, previous, updated) {
|
|
34
|
+
return entries.map((entry) => entry === previous ? updated : entry);
|
|
35
|
+
}
|
|
36
|
+
function runWithAutoTraceEntry(previous, updated, fn) {
|
|
37
|
+
const result = runWithAutoTraceScope(
|
|
38
|
+
{ entries: replaceEntry(currentAutoTraceEntries(), previous, updated) },
|
|
39
|
+
fn
|
|
40
|
+
);
|
|
41
|
+
if (isAutoTraceAsyncGenerator(result)) {
|
|
42
|
+
return wrapAutoTraceEntryAsyncGenerator(previous, updated, result);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
function wrapAutoTraceEntryAsyncGenerator(previous, updated, source) {
|
|
47
|
+
const step = (method, value) => runWithAutoTraceScope(
|
|
48
|
+
{ entries: replaceEntry(currentAutoTraceEntries(), previous, updated) },
|
|
49
|
+
() => source[method](value)
|
|
50
|
+
);
|
|
51
|
+
const wrapped = {
|
|
52
|
+
next: (value) => step("next", value),
|
|
53
|
+
return: (value) => step("return", value),
|
|
54
|
+
throw: (error) => step("throw", error),
|
|
55
|
+
[Symbol.asyncIterator]: () => wrapped
|
|
56
|
+
};
|
|
57
|
+
return wrapped;
|
|
58
|
+
}
|
|
59
|
+
function clearAutoTraceNodeConfiguration(fn) {
|
|
60
|
+
return runWithAutoTraceScope({ entries: currentAutoTraceEntries() }, fn);
|
|
61
|
+
}
|
|
31
62
|
function runWithAutoTraceNodeConfiguration(nodeConfiguration, fn) {
|
|
32
63
|
const scope = currentAutoTraceScope();
|
|
33
|
-
if (!scope) {
|
|
64
|
+
if (!scope || scope.entries.length === 0) {
|
|
34
65
|
return fn();
|
|
35
66
|
}
|
|
36
|
-
const
|
|
37
|
-
let result;
|
|
38
|
-
if (autoTraceState.storage) {
|
|
39
|
-
result = autoTraceState.storage.run(configuredScope, fn);
|
|
40
|
-
} else {
|
|
41
|
-
const previous = autoTraceState.browserScope;
|
|
42
|
-
autoTraceState.browserScope = configuredScope;
|
|
43
|
-
try {
|
|
44
|
-
result = fn();
|
|
45
|
-
} finally {
|
|
46
|
-
autoTraceState.browserScope = previous;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
67
|
+
const result = runWithAutoTraceScope({ ...scope, nodeConfiguration }, fn);
|
|
49
68
|
if (isAutoTraceAsyncGenerator(result)) {
|
|
50
69
|
return wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, result);
|
|
51
70
|
}
|
|
52
71
|
return result;
|
|
53
72
|
}
|
|
54
|
-
function runWithAutoTraceRootContext(context, fn) {
|
|
73
|
+
function runWithAutoTraceRootContext(context, spanStack, fn) {
|
|
55
74
|
autoTraceState.activeRoots += 1;
|
|
75
|
+
const entries = [
|
|
76
|
+
...currentAutoTraceEntries(),
|
|
77
|
+
{ context, depth: 0, spanStack }
|
|
78
|
+
];
|
|
56
79
|
let result;
|
|
57
80
|
try {
|
|
58
|
-
result =
|
|
81
|
+
result = runWithAutoTraceScope({ entries }, fn);
|
|
59
82
|
} catch (error) {
|
|
60
83
|
autoTraceState.activeRoots -= 1;
|
|
61
84
|
throw error;
|
|
62
85
|
}
|
|
63
86
|
if (isAutoTraceAsyncGenerator(result)) {
|
|
64
87
|
autoTraceState.activeRoots -= 1;
|
|
65
|
-
return wrapAutoTraceAsyncGenerator(context, result);
|
|
88
|
+
return wrapAutoTraceAsyncGenerator(context, spanStack, result);
|
|
66
89
|
}
|
|
67
90
|
if (result instanceof Promise) {
|
|
68
91
|
return result.finally(() => {
|
|
@@ -72,6 +95,15 @@ function runWithAutoTraceRootContext(context, fn) {
|
|
|
72
95
|
autoTraceState.activeRoots -= 1;
|
|
73
96
|
return result;
|
|
74
97
|
}
|
|
98
|
+
function invokeThroughAutoTraceEntries(entries, step, fn) {
|
|
99
|
+
let run = fn;
|
|
100
|
+
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
101
|
+
const entry = entries[index];
|
|
102
|
+
const next = run;
|
|
103
|
+
run = () => step(entry, next);
|
|
104
|
+
}
|
|
105
|
+
return run();
|
|
106
|
+
}
|
|
75
107
|
function isAutoTraceAsyncGenerator(value) {
|
|
76
108
|
if (value === null || typeof value !== "object") {
|
|
77
109
|
return false;
|
|
@@ -79,8 +111,8 @@ function isAutoTraceAsyncGenerator(value) {
|
|
|
79
111
|
const candidate = value;
|
|
80
112
|
return typeof candidate.next === "function" && typeof candidate.return === "function" && typeof candidate.throw === "function" && typeof candidate[Symbol.asyncIterator] === "function";
|
|
81
113
|
}
|
|
82
|
-
function wrapAutoTraceAsyncGenerator(context, source) {
|
|
83
|
-
const step = (method, value) => runWithAutoTraceRootContext(context, () => source[method](value));
|
|
114
|
+
function wrapAutoTraceAsyncGenerator(context, spanStack, source) {
|
|
115
|
+
const step = (method, value) => runWithAutoTraceRootContext(context, spanStack, () => source[method](value));
|
|
84
116
|
const wrapped = {
|
|
85
117
|
next: (value) => step("next", value),
|
|
86
118
|
return: (value) => step("return", value),
|
|
@@ -102,20 +134,32 @@ function wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, source) {
|
|
|
102
134
|
};
|
|
103
135
|
return wrapped;
|
|
104
136
|
}
|
|
137
|
+
function shareFinalize(configuration) {
|
|
138
|
+
const finalize = configuration.finalize;
|
|
139
|
+
if (finalize === void 0) {
|
|
140
|
+
return configuration;
|
|
141
|
+
}
|
|
142
|
+
let settled;
|
|
143
|
+
return {
|
|
144
|
+
...configuration,
|
|
145
|
+
finalize: (result) => {
|
|
146
|
+
settled ?? (settled = Promise.resolve().then(() => finalize(result)));
|
|
147
|
+
return settled;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
105
151
|
function __bitfabAutoSpan(definition, inputs, fn) {
|
|
106
152
|
const scope = currentAutoTraceScope();
|
|
107
|
-
if (!scope) {
|
|
153
|
+
if (!scope || scope.entries.length === 0) {
|
|
108
154
|
return fn();
|
|
109
155
|
}
|
|
110
156
|
const nameParts = definition.name.split(".");
|
|
111
157
|
const simpleName = nameParts[nameParts.length - 1];
|
|
112
|
-
const nodeConfiguration = simpleName === scope.nodeConfiguration?.functionName ? scope.nodeConfiguration : void 0;
|
|
113
|
-
return
|
|
114
|
-
|
|
115
|
-
inputs,
|
|
116
|
-
fn
|
|
117
|
-
scope.depth,
|
|
118
|
-
nodeConfiguration
|
|
158
|
+
const nodeConfiguration = simpleName === scope.nodeConfiguration?.functionName ? shareFinalize(scope.nodeConfiguration) : void 0;
|
|
159
|
+
return invokeThroughAutoTraceEntries(
|
|
160
|
+
scope.entries,
|
|
161
|
+
(entry, next) => entry.context.invoke(definition, inputs, next, entry, nodeConfiguration),
|
|
162
|
+
fn
|
|
119
163
|
);
|
|
120
164
|
}
|
|
121
165
|
function __bitfabAutoWrap(definition, fn) {
|
|
@@ -147,7 +191,7 @@ function __bitfabAutoTraceActive() {
|
|
|
147
191
|
if (autoTraceState.activeRoots === 0) {
|
|
148
192
|
return false;
|
|
149
193
|
}
|
|
150
|
-
return
|
|
194
|
+
return currentAutoTraceEntries().length > 0;
|
|
151
195
|
}
|
|
152
196
|
function currentAutoTraceScope() {
|
|
153
197
|
initializeAutoTraceStorage();
|
|
@@ -170,13 +214,16 @@ function getAutoTraceCapturePolicy(client, traceFunctionKey) {
|
|
|
170
214
|
}
|
|
171
215
|
|
|
172
216
|
export {
|
|
173
|
-
|
|
217
|
+
currentAutoTraceEntries,
|
|
218
|
+
runWithAutoTraceEntry,
|
|
219
|
+
clearAutoTraceNodeConfiguration,
|
|
174
220
|
runWithAutoTraceNodeConfiguration,
|
|
175
221
|
runWithAutoTraceRootContext,
|
|
222
|
+
invokeThroughAutoTraceEntries,
|
|
176
223
|
__bitfabAutoSpan,
|
|
177
224
|
__bitfabAutoWrap,
|
|
178
225
|
__bitfabAutoTraceActive,
|
|
179
226
|
__setBitfabAutoTraceCapturePolicy,
|
|
180
227
|
getAutoTraceCapturePolicy
|
|
181
228
|
};
|
|
182
|
-
//# sourceMappingURL=chunk-
|
|
229
|
+
//# sourceMappingURL=chunk-E5BLYL5X.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/autoTrace.ts"],"sourcesContent":["import {\n type AsyncLocalStorageLike,\n createAsyncLocalStorage,\n} from \"./asyncStorage.js\"\n\nexport interface AutoTraceFunctionDefinition {\n id: string\n name: string\n file: string\n line: number\n column: number\n async?: boolean\n wrapper?: boolean\n}\n\nexport interface AutoTraceNodeConfiguration {\n functionName: string\n name?: string\n type?: \"llm\" | \"agent\" | \"function\" | \"guardrail\" | \"handoff\" | \"custom\"\n capture: boolean\n testRunId?: string\n mockOnReplay?: boolean\n // biome-ignore lint/suspicious/noExplicitAny: node finalizers receive the configured function's result, whose type is owned by the caller\n finalize?: (result: any) => unknown | Promise<unknown>\n}\n\nexport interface NestedTraceLink {\n traceFunctionKey: string\n traceId?: string\n rootSpanId?: string\n}\n\nexport interface AutoTraceEntry {\n context: AutoTraceContext\n depth: number\n spanStack: unknown\n}\n\nexport interface AutoTraceContext {\n readonly traceFunctionKey: string\n invoke<T>(\n definition: AutoTraceFunctionDefinition,\n inputs: unknown[],\n fn: () => T,\n entry: AutoTraceEntry,\n nodeConfiguration?: AutoTraceNodeConfiguration,\n ): T\n invokeNestedRoot<T>(\n name: string,\n functionName: string,\n inputs: unknown[],\n fn: () => T,\n entry: AutoTraceEntry,\n link: NestedTraceLink | undefined,\n ): T\n}\n\ninterface AutoTraceScope {\n entries: readonly AutoTraceEntry[]\n nodeConfiguration?: AutoTraceNodeConfiguration\n}\n\ninterface AutoTraceState {\n storage: AsyncLocalStorageLike<AutoTraceScope> | null\n browserScope: AutoTraceScope | undefined\n capturePolicies: WeakMap<object, Map<string, ReadonlySet<string>>>\n activeRoots: number\n}\n\ninterface AutoTraceGlobal {\n __bitfabAutoTraceStateV4?: AutoTraceState\n}\n\ninterface AutoTraceAsyncGenerator {\n next(value?: unknown): Promise<IteratorResult<unknown, unknown>>\n return(value?: unknown): Promise<IteratorResult<unknown, unknown>>\n throw(error?: unknown): Promise<IteratorResult<unknown, unknown>>\n [Symbol.asyncIterator](): AutoTraceAsyncGenerator\n}\n\nconst autoTraceGlobal = globalThis as unknown as AutoTraceGlobal\nconst autoTraceState: AutoTraceState =\n autoTraceGlobal.__bitfabAutoTraceStateV4 ?? {\n storage: null,\n browserScope: undefined,\n capturePolicies: new WeakMap(),\n activeRoots: 0,\n }\nautoTraceGlobal.__bitfabAutoTraceStateV4 = autoTraceState\n\nfunction initializeAutoTraceStorage(): void {\n autoTraceState.storage ??= createAsyncLocalStorage<AutoTraceScope>()\n}\n\nfunction runWithAutoTraceScope<T>(scope: AutoTraceScope, fn: () => T): T {\n initializeAutoTraceStorage()\n if (autoTraceState.storage) {\n return autoTraceState.storage.run(scope, fn)\n }\n\n const previous = autoTraceState.browserScope\n autoTraceState.browserScope = scope\n try {\n return fn()\n } finally {\n autoTraceState.browserScope = previous\n }\n}\n\nexport function currentAutoTraceEntries(): readonly AutoTraceEntry[] {\n return currentAutoTraceScope()?.entries ?? []\n}\n\nfunction replaceEntry(\n entries: readonly AutoTraceEntry[],\n previous: AutoTraceEntry,\n updated: AutoTraceEntry,\n): readonly AutoTraceEntry[] {\n return entries.map((entry) => (entry === previous ? updated : entry))\n}\n\nexport function runWithAutoTraceEntry<T>(\n previous: AutoTraceEntry,\n updated: AutoTraceEntry,\n fn: () => T,\n): T {\n const result = runWithAutoTraceScope(\n { entries: replaceEntry(currentAutoTraceEntries(), previous, updated) },\n fn,\n )\n if (isAutoTraceAsyncGenerator(result)) {\n return wrapAutoTraceEntryAsyncGenerator(previous, updated, result) as T\n }\n return result\n}\n\nfunction wrapAutoTraceEntryAsyncGenerator(\n previous: AutoTraceEntry,\n updated: AutoTraceEntry,\n source: AutoTraceAsyncGenerator,\n): AutoTraceAsyncGenerator {\n const step = (\n method: \"next\" | \"return\" | \"throw\",\n value?: unknown,\n ): Promise<IteratorResult<unknown, unknown>> =>\n runWithAutoTraceScope(\n { entries: replaceEntry(currentAutoTraceEntries(), previous, updated) },\n () => source[method](value),\n )\n const wrapped: AutoTraceAsyncGenerator = {\n next: (value) => step(\"next\", value),\n return: (value) => step(\"return\", value),\n throw: (error) => step(\"throw\", error),\n [Symbol.asyncIterator]: () => wrapped,\n }\n return wrapped\n}\n\nexport function clearAutoTraceNodeConfiguration<T>(fn: () => T): T {\n return runWithAutoTraceScope({ entries: currentAutoTraceEntries() }, fn)\n}\n\nexport function runWithAutoTraceNodeConfiguration<T>(\n nodeConfiguration: AutoTraceNodeConfiguration,\n fn: () => T,\n): T {\n const scope = currentAutoTraceScope()\n if (!scope || scope.entries.length === 0) {\n return fn()\n }\n\n const result = runWithAutoTraceScope({ ...scope, nodeConfiguration }, fn)\n if (isAutoTraceAsyncGenerator(result)) {\n return wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, result) as T\n }\n return result\n}\n\nexport function runWithAutoTraceRootContext<T>(\n context: AutoTraceContext,\n spanStack: unknown,\n fn: () => T,\n): T {\n autoTraceState.activeRoots += 1\n const entries = [\n ...currentAutoTraceEntries(),\n { context, depth: 0, spanStack },\n ]\n let result: T\n try {\n result = runWithAutoTraceScope({ entries }, fn)\n } catch (error) {\n autoTraceState.activeRoots -= 1\n throw error\n }\n\n if (isAutoTraceAsyncGenerator(result)) {\n autoTraceState.activeRoots -= 1\n return wrapAutoTraceAsyncGenerator(context, spanStack, result) as T\n }\n\n if (result instanceof Promise) {\n return result.finally(() => {\n autoTraceState.activeRoots -= 1\n }) as T\n }\n\n autoTraceState.activeRoots -= 1\n return result\n}\n\nexport function invokeThroughAutoTraceEntries<T>(\n entries: readonly AutoTraceEntry[],\n step: (entry: AutoTraceEntry, next: () => T) => T,\n fn: () => T,\n): T {\n let run = fn\n for (let index = entries.length - 1; index >= 0; index -= 1) {\n const entry = entries[index] as AutoTraceEntry\n const next = run\n run = () => step(entry, next)\n }\n return run()\n}\n\nfunction isAutoTraceAsyncGenerator(\n value: unknown,\n): value is AutoTraceAsyncGenerator {\n if (value === null || typeof value !== \"object\") {\n return false\n }\n const candidate = value as Record<PropertyKey, unknown>\n return (\n typeof candidate.next === \"function\" &&\n typeof candidate.return === \"function\" &&\n typeof candidate.throw === \"function\" &&\n typeof candidate[Symbol.asyncIterator] === \"function\"\n )\n}\n\nfunction wrapAutoTraceAsyncGenerator(\n context: AutoTraceContext,\n spanStack: unknown,\n source: AutoTraceAsyncGenerator,\n): AutoTraceAsyncGenerator {\n const step = (\n method: \"next\" | \"return\" | \"throw\",\n value?: unknown,\n ): Promise<IteratorResult<unknown, unknown>> =>\n runWithAutoTraceRootContext(context, spanStack, () => source[method](value))\n const wrapped: AutoTraceAsyncGenerator = {\n next: (value) => step(\"next\", value),\n return: (value) => step(\"return\", value),\n throw: (error) => step(\"throw\", error),\n [Symbol.asyncIterator]: () => wrapped,\n }\n return wrapped\n}\n\nfunction wrapAutoTraceNodeAsyncGenerator(\n nodeConfiguration: AutoTraceNodeConfiguration,\n source: AutoTraceAsyncGenerator,\n): AutoTraceAsyncGenerator {\n const step = (\n method: \"next\" | \"return\" | \"throw\",\n value?: unknown,\n ): Promise<IteratorResult<unknown, unknown>> =>\n runWithAutoTraceNodeConfiguration(nodeConfiguration, () =>\n source[method](value),\n )\n const wrapped: AutoTraceAsyncGenerator = {\n next: (value) => step(\"next\", value),\n return: (value) => step(\"return\", value),\n throw: (error) => step(\"throw\", error),\n [Symbol.asyncIterator]: () => wrapped,\n }\n return wrapped\n}\n\nfunction shareFinalize(\n configuration: AutoTraceNodeConfiguration,\n): AutoTraceNodeConfiguration {\n const finalize = configuration.finalize\n if (finalize === undefined) {\n return configuration\n }\n let settled: Promise<unknown> | undefined\n return {\n ...configuration,\n finalize: (result: unknown) => {\n settled ??= Promise.resolve().then(() => finalize(result))\n return settled\n },\n }\n}\n\nexport function __bitfabAutoSpan<T>(\n definition: AutoTraceFunctionDefinition,\n inputs: unknown[],\n fn: () => T,\n): T {\n const scope = currentAutoTraceScope()\n if (!scope || scope.entries.length === 0) {\n return fn()\n }\n const nameParts = definition.name.split(\".\")\n const simpleName = nameParts[nameParts.length - 1]\n const nodeConfiguration =\n simpleName === scope.nodeConfiguration?.functionName\n ? shareFinalize(scope.nodeConfiguration)\n : undefined\n return invokeThroughAutoTraceEntries(\n scope.entries,\n (entry, next) =>\n entry.context.invoke(definition, inputs, next, entry, nodeConfiguration),\n fn,\n )\n}\n\n/**\n * Preserve a function's original call arguments for transform cases where\n * parameter bindings discard them, such as destructured arrow parameters.\n *\n * This helper is internal transform/runtime protocol. The proxy preserves the\n * target's callability, arity, async identity, and non-constructibility while\n * only allocating a trace closure beneath an active automatic trace root.\n *\n * @experimental The automatic tracing protocol may change.\n */\nexport function __bitfabAutoWrap<T extends (...args: never[]) => unknown>(\n definition: AutoTraceFunctionDefinition,\n fn: T,\n): T {\n if (fn.name === \"\") {\n const nameParts = definition.name.split(\".\")\n const inferredName = nameParts[nameParts.length - 1]\n if (inferredName !== undefined) {\n Object.defineProperty(fn, \"name\", {\n configurable: true,\n value: inferredName,\n })\n }\n }\n\n const target = fn as unknown as (...args: unknown[]) => unknown\n return new Proxy(target, {\n apply(callTarget, thisArg, args) {\n if (!__bitfabAutoTraceActive()) {\n return Reflect.apply(callTarget, thisArg, args)\n }\n return __bitfabAutoSpan(definition, args, () =>\n Reflect.apply(callTarget, thisArg, args),\n )\n },\n }) as unknown as T\n}\n\n/**\n * Return whether the current call is inside an automatic trace root.\n *\n * Build transforms use this before allocating function metadata, captured\n * inputs, or an invocation closure. It is internal transform/runtime protocol,\n * not a supported application API.\n *\n * @experimental The automatic tracing protocol may change.\n */\nexport function __bitfabAutoTraceActive(): boolean {\n if (autoTraceState.activeRoots === 0) {\n return false\n }\n return currentAutoTraceEntries().length > 0\n}\n\nfunction currentAutoTraceScope(): AutoTraceScope | undefined {\n initializeAutoTraceStorage()\n return autoTraceState.storage?.getStore() ?? autoTraceState.browserScope\n}\n\nexport function __setBitfabAutoTraceCapturePolicy(\n client: object,\n traceFunctionKey: string,\n functionIds: Iterable<string> | undefined,\n): void {\n const policies = autoTraceState.capturePolicies.get(client) ?? new Map()\n if (functionIds === undefined) {\n policies.delete(traceFunctionKey)\n if (policies.size === 0) {\n autoTraceState.capturePolicies.delete(client)\n }\n return\n }\n policies.set(traceFunctionKey, new Set(functionIds))\n autoTraceState.capturePolicies.set(client, policies)\n}\n\nexport function getAutoTraceCapturePolicy(\n client: object,\n traceFunctionKey: string,\n): ReadonlySet<string> | undefined {\n return autoTraceState.capturePolicies.get(client)?.get(traceFunctionKey)\n}\n"],"mappings":";;;;;AAgFA,IAAM,kBAAkB;AACxB,IAAM,iBACJ,gBAAgB,4BAA4B;AAAA,EAC1C,SAAS;AAAA,EACT,cAAc;AAAA,EACd,iBAAiB,oBAAI,QAAQ;AAAA,EAC7B,aAAa;AACf;AACF,gBAAgB,2BAA2B;AAE3C,SAAS,6BAAmC;AAC1C,iBAAe,YAAf,eAAe,UAAY,wBAAwC;AACrE;AAEA,SAAS,sBAAyB,OAAuB,IAAgB;AACvE,6BAA2B;AAC3B,MAAI,eAAe,SAAS;AAC1B,WAAO,eAAe,QAAQ,IAAI,OAAO,EAAE;AAAA,EAC7C;AAEA,QAAM,WAAW,eAAe;AAChC,iBAAe,eAAe;AAC9B,MAAI;AACF,WAAO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-1,11 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__bitfabAutoTraceActive,
|
|
3
3
|
__setBitfabAutoTraceCapturePolicy,
|
|
4
|
+
clearAutoTraceNodeConfiguration,
|
|
5
|
+
currentAutoTraceEntries,
|
|
4
6
|
getAutoTraceCapturePolicy,
|
|
5
|
-
|
|
7
|
+
invokeThroughAutoTraceEntries,
|
|
8
|
+
runWithAutoTraceEntry,
|
|
6
9
|
runWithAutoTraceNodeConfiguration,
|
|
7
10
|
runWithAutoTraceRootContext
|
|
8
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-E5BLYL5X.js";
|
|
9
12
|
import {
|
|
10
13
|
NO_MOCK_OVERRIDE,
|
|
11
14
|
deserializeInputs,
|
|
@@ -16,7 +19,7 @@ import {
|
|
|
16
19
|
serializeValue,
|
|
17
20
|
toJsonSafe,
|
|
18
21
|
toJsonSafeReport
|
|
19
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-SJKWUQ3G.js";
|
|
20
23
|
import {
|
|
21
24
|
BitfabError,
|
|
22
25
|
DEFAULT_SERVICE_URL,
|
|
@@ -28,7 +31,7 @@ import {
|
|
|
28
31
|
recordCallerTraceMetadata,
|
|
29
32
|
retireTraceMetadata,
|
|
30
33
|
warnOnce
|
|
31
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-6IMGAODW.js";
|
|
32
35
|
import {
|
|
33
36
|
__privateAdd,
|
|
34
37
|
__privateGet,
|
|
@@ -3174,6 +3177,26 @@ var DEFAULT_AUTO_TRACE_MAX_SPANS = 500;
|
|
|
3174
3177
|
var AUTO_TRACE_PROTOCOL = "ts-auto-v1";
|
|
3175
3178
|
var AUTO_TRACE_POLICY_REFRESH_MS = 6e4;
|
|
3176
3179
|
var AUTO_TRACE_POLICY_RETRY_MS = 1e4;
|
|
3180
|
+
function spanOwnerName(receiver) {
|
|
3181
|
+
if (typeof receiver === "function") {
|
|
3182
|
+
return receiver.name !== "" ? receiver.name : void 0;
|
|
3183
|
+
}
|
|
3184
|
+
if (typeof receiver !== "object" || receiver === null) {
|
|
3185
|
+
return void 0;
|
|
3186
|
+
}
|
|
3187
|
+
const owner = receiver.constructor;
|
|
3188
|
+
if (typeof owner !== "function" || owner === Object || owner.name === "") {
|
|
3189
|
+
return void 0;
|
|
3190
|
+
}
|
|
3191
|
+
return owner.name;
|
|
3192
|
+
}
|
|
3193
|
+
function qualifiedSpanName(receiver, functionName) {
|
|
3194
|
+
if (functionName === void 0) {
|
|
3195
|
+
return void 0;
|
|
3196
|
+
}
|
|
3197
|
+
const owner = spanOwnerName(receiver);
|
|
3198
|
+
return owner === void 0 ? functionName : `${owner}.${functionName}`;
|
|
3199
|
+
}
|
|
3177
3200
|
function autoTraceLimit(value, fallback) {
|
|
3178
3201
|
return value !== void 0 && Number.isFinite(value) && value >= 0 ? Math.floor(value) : fallback;
|
|
3179
3202
|
}
|
|
@@ -3376,16 +3399,21 @@ var Bitfab = class {
|
|
|
3376
3399
|
);
|
|
3377
3400
|
const excluded = new Set(options.exclude ?? []);
|
|
3378
3401
|
const includeWrappers = options.includeWrappers ?? false;
|
|
3402
|
+
const rootNameFor = (receiver) => options.name ?? (fn.name !== "" ? qualifiedSpanName(receiver, name) ?? name : name);
|
|
3379
3403
|
const rootOptions = {
|
|
3380
|
-
name: options.name
|
|
3404
|
+
name: options.name,
|
|
3405
|
+
nameFor: rootNameFor,
|
|
3381
3406
|
type: options.type ?? "custom",
|
|
3382
3407
|
surface: "opt-out"
|
|
3383
3408
|
};
|
|
3384
|
-
const
|
|
3409
|
+
const buildTracedRoot = (spanOptions) => this.withSpan(
|
|
3385
3410
|
traceFunctionKey,
|
|
3386
|
-
|
|
3411
|
+
spanOptions,
|
|
3387
3412
|
function(...args) {
|
|
3388
|
-
const capturePolicy = getAutoTraceCapturePolicy(
|
|
3413
|
+
const capturePolicy = getAutoTraceCapturePolicy(
|
|
3414
|
+
self,
|
|
3415
|
+
traceFunctionKey
|
|
3416
|
+
);
|
|
3389
3417
|
self.refreshAutoTraceCapturePolicy(traceFunctionKey);
|
|
3390
3418
|
let spansUsed = 0;
|
|
3391
3419
|
let truncated = false;
|
|
@@ -3406,19 +3434,54 @@ var Bitfab = class {
|
|
|
3406
3434
|
`"${traceFunctionKey}" hit an automatic subtree capture limit (maxDepth=${maxDepth}, maxSpans=${maxSpans}); its trace is incomplete. Raise the limits or narrow the subtree with exclude.`
|
|
3407
3435
|
);
|
|
3408
3436
|
};
|
|
3437
|
+
const spanStackOf = (entry) => entry.spanStack;
|
|
3438
|
+
const openChild = (entry, childOptions, inputs, isAsync, invokeFn) => {
|
|
3439
|
+
const runInside = () => runWithAutoTraceEntry(
|
|
3440
|
+
entry,
|
|
3441
|
+
{
|
|
3442
|
+
context: autoTraceContext,
|
|
3443
|
+
depth: entry.depth + 1,
|
|
3444
|
+
spanStack: getSpanStack()
|
|
3445
|
+
},
|
|
3446
|
+
invokeFn
|
|
3447
|
+
);
|
|
3448
|
+
return runWithSpanStack(spanStackOf(entry), () => {
|
|
3449
|
+
if (isAsync) {
|
|
3450
|
+
const tracedAsyncChild = self.withSpan(
|
|
3451
|
+
traceFunctionKey,
|
|
3452
|
+
childOptions,
|
|
3453
|
+
async (..._inputs) => await runInside()
|
|
3454
|
+
);
|
|
3455
|
+
return tracedAsyncChild(...inputs);
|
|
3456
|
+
}
|
|
3457
|
+
const tracedChild = self.withSpan(
|
|
3458
|
+
traceFunctionKey,
|
|
3459
|
+
childOptions,
|
|
3460
|
+
(..._inputs) => runInside()
|
|
3461
|
+
);
|
|
3462
|
+
return tracedChild(...inputs);
|
|
3463
|
+
});
|
|
3464
|
+
};
|
|
3465
|
+
const overBudget = (entry) => {
|
|
3466
|
+
if (entry.depth < maxDepth && spansUsed < maxSpans) {
|
|
3467
|
+
return false;
|
|
3468
|
+
}
|
|
3469
|
+
runWithSpanStack(spanStackOf(entry), warnTruncated);
|
|
3470
|
+
return true;
|
|
3471
|
+
};
|
|
3409
3472
|
const autoTraceContext = {
|
|
3410
|
-
|
|
3473
|
+
traceFunctionKey,
|
|
3474
|
+
invoke(definition, inputs, invokeFn, entry, nodeConfiguration) {
|
|
3411
3475
|
const nameParts = definition.name.split(".");
|
|
3412
3476
|
const simpleName = nameParts[nameParts.length - 1];
|
|
3413
|
-
const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() :
|
|
3477
|
+
const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : clearAutoTraceNodeConfiguration(invokeFn);
|
|
3414
3478
|
if (excluded.has(definition.name) || simpleName !== void 0 && excluded.has(simpleName) || nodeConfiguration === void 0 && definition.wrapper === true && !includeWrappers) {
|
|
3415
3479
|
return invokeWithoutNode();
|
|
3416
3480
|
}
|
|
3417
3481
|
if (nodeConfiguration?.capture === false) {
|
|
3418
|
-
return
|
|
3482
|
+
return clearAutoTraceNodeConfiguration(invokeFn);
|
|
3419
3483
|
}
|
|
3420
|
-
if (
|
|
3421
|
-
warnTruncated();
|
|
3484
|
+
if (overBudget(entry)) {
|
|
3422
3485
|
return invokeWithoutNode();
|
|
3423
3486
|
}
|
|
3424
3487
|
spansUsed += 1;
|
|
@@ -3441,34 +3504,82 @@ var Bitfab = class {
|
|
|
3441
3504
|
finalize: nodeConfiguration.finalize
|
|
3442
3505
|
}
|
|
3443
3506
|
};
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
const tracedAsyncChild = self.withSpan(
|
|
3447
|
-
traceFunctionKey,
|
|
3448
|
-
childOptions,
|
|
3449
|
-
async (..._inputs) => await invokeWithAutoTraceContext()
|
|
3450
|
-
);
|
|
3451
|
-
return tracedAsyncChild(...inputs);
|
|
3452
|
-
}
|
|
3453
|
-
const tracedChild = self.withSpan(
|
|
3454
|
-
traceFunctionKey,
|
|
3507
|
+
return openChild(
|
|
3508
|
+
entry,
|
|
3455
3509
|
childOptions,
|
|
3456
|
-
|
|
3510
|
+
inputs,
|
|
3511
|
+
definition.async === true,
|
|
3512
|
+
invokeFn
|
|
3457
3513
|
);
|
|
3458
|
-
|
|
3514
|
+
},
|
|
3515
|
+
invokeNestedRoot(nestedName, nestedFunctionName, inputs, invokeFn, entry, link) {
|
|
3516
|
+
if (excluded.has(nestedName) || excluded.has(nestedFunctionName) || overBudget(entry)) {
|
|
3517
|
+
return invokeFn();
|
|
3518
|
+
}
|
|
3519
|
+
spansUsed += 1;
|
|
3520
|
+
const childOptions = {
|
|
3521
|
+
name: nestedName,
|
|
3522
|
+
type: "function",
|
|
3523
|
+
captureWhen: "nested",
|
|
3524
|
+
surface: "opt-out",
|
|
3525
|
+
captureContent: true,
|
|
3526
|
+
...link !== void 0 && { nestedTrace: link }
|
|
3527
|
+
};
|
|
3528
|
+
return openChild(entry, childOptions, inputs, false, invokeFn);
|
|
3459
3529
|
}
|
|
3460
3530
|
};
|
|
3461
3531
|
return runWithAutoTraceRootContext(
|
|
3462
3532
|
autoTraceContext,
|
|
3533
|
+
getSpanStack(),
|
|
3463
3534
|
() => fn.apply(this, args)
|
|
3464
3535
|
);
|
|
3465
3536
|
}
|
|
3466
3537
|
);
|
|
3538
|
+
const tracedRoot = buildTracedRoot(rootOptions);
|
|
3467
3539
|
const autoTraceRoot = function(...args) {
|
|
3468
3540
|
if (!self.shouldRecord()) {
|
|
3469
3541
|
return fn.apply(this, args);
|
|
3470
3542
|
}
|
|
3471
|
-
|
|
3543
|
+
const enclosing = currentAutoTraceEntries();
|
|
3544
|
+
if (enclosing.length === 0) {
|
|
3545
|
+
return tracedRoot.apply(this, args);
|
|
3546
|
+
}
|
|
3547
|
+
const link = getReplayContext() || inSeedScope() ? void 0 : { traceFunctionKey };
|
|
3548
|
+
const rootName = rootNameFor(this);
|
|
3549
|
+
return invokeThroughAutoTraceEntries(
|
|
3550
|
+
enclosing,
|
|
3551
|
+
(entry, next) => entry.context.invokeNestedRoot(
|
|
3552
|
+
rootName,
|
|
3553
|
+
name,
|
|
3554
|
+
args,
|
|
3555
|
+
next,
|
|
3556
|
+
entry,
|
|
3557
|
+
link
|
|
3558
|
+
),
|
|
3559
|
+
() => {
|
|
3560
|
+
if (link === void 0) {
|
|
3561
|
+
return fn.apply(this, args);
|
|
3562
|
+
}
|
|
3563
|
+
const innermost = enclosing[enclosing.length - 1];
|
|
3564
|
+
const innermostNow = currentAutoTraceEntries().find(
|
|
3565
|
+
(entry) => entry.context === innermost.context
|
|
3566
|
+
) ?? innermost;
|
|
3567
|
+
const innermostStack = innermostNow.spanStack;
|
|
3568
|
+
const copy = innermostStack[innermostStack.length - 1];
|
|
3569
|
+
const detachedRoot = buildTracedRoot({
|
|
3570
|
+
...rootOptions,
|
|
3571
|
+
...copy !== void 0 && {
|
|
3572
|
+
enclosingTrace: {
|
|
3573
|
+
traceId: copy.traceId,
|
|
3574
|
+
spanId: copy.spanId,
|
|
3575
|
+
traceFunctionKey: innermost.context.traceFunctionKey,
|
|
3576
|
+
link
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
});
|
|
3580
|
+
return runWithSpanStack([], () => detachedRoot.apply(this, args));
|
|
3581
|
+
}
|
|
3582
|
+
);
|
|
3472
3583
|
};
|
|
3473
3584
|
Object.defineProperty(autoTraceRoot, "_bitfabTraceFunctionKey", {
|
|
3474
3585
|
value: traceFunctionKey
|
|
@@ -4057,6 +4168,10 @@ var Bitfab = class {
|
|
|
4057
4168
|
const spanId = randomUuid();
|
|
4058
4169
|
const parentSpanId = parentContext?.spanId ?? null;
|
|
4059
4170
|
const isRootSpan = parentSpanId === null;
|
|
4171
|
+
if (options.enclosingTrace !== void 0) {
|
|
4172
|
+
options.enclosingTrace.link.traceId = traceId;
|
|
4173
|
+
options.enclosingTrace.link.rootSpanId = spanId;
|
|
4174
|
+
}
|
|
4060
4175
|
const requestedSurface = options.surface ?? DEFAULT_SURFACE;
|
|
4061
4176
|
const surface = resolveSurface(requestedSurface, parentContext?.surface);
|
|
4062
4177
|
assertSurfacesCompatible(
|
|
@@ -4097,7 +4212,7 @@ var Bitfab = class {
|
|
|
4097
4212
|
const baseSpanParams = {
|
|
4098
4213
|
traceFunctionKey,
|
|
4099
4214
|
functionName,
|
|
4100
|
-
spanName: options.name ?? functionName ?? traceFunctionKey,
|
|
4215
|
+
spanName: options.name ?? options.nameFor?.(this) ?? qualifiedSpanName(this, functionName) ?? traceFunctionKey,
|
|
4101
4216
|
traceId,
|
|
4102
4217
|
spanId,
|
|
4103
4218
|
parentSpanId,
|
|
@@ -4106,7 +4221,9 @@ var Bitfab = class {
|
|
|
4106
4221
|
spanType: options.type ?? "custom",
|
|
4107
4222
|
functionId: options.functionId,
|
|
4108
4223
|
captureContent: options.captureContent ?? true,
|
|
4109
|
-
autoTraceDefinition: options.autoTraceDefinition
|
|
4224
|
+
autoTraceDefinition: options.autoTraceDefinition,
|
|
4225
|
+
nestedTrace: options.nestedTrace,
|
|
4226
|
+
enclosingTrace: options.enclosingTrace
|
|
4110
4227
|
};
|
|
4111
4228
|
const sendSpan = async (params) => {
|
|
4112
4229
|
const replayCtx = getReplayContext();
|
|
@@ -4616,6 +4733,16 @@ var Bitfab = class {
|
|
|
4616
4733
|
function_line: params.autoTraceDefinition.line,
|
|
4617
4734
|
function_column: params.autoTraceDefinition.column
|
|
4618
4735
|
},
|
|
4736
|
+
...params.nestedTrace?.traceId !== void 0 && {
|
|
4737
|
+
nested_trace_id: params.nestedTrace.traceId,
|
|
4738
|
+
nested_trace_function_key: params.nestedTrace.traceFunctionKey,
|
|
4739
|
+
nested_root_span_id: params.nestedTrace.rootSpanId
|
|
4740
|
+
},
|
|
4741
|
+
...params.enclosingTrace !== void 0 && {
|
|
4742
|
+
enclosing_trace_id: params.enclosingTrace.traceId,
|
|
4743
|
+
enclosing_trace_function_key: params.enclosingTrace.traceFunctionKey,
|
|
4744
|
+
enclosing_span_id: params.enclosingTrace.spanId
|
|
4745
|
+
},
|
|
4619
4746
|
...serializedInputs !== void 0 && {
|
|
4620
4747
|
input: serializedInputs.json,
|
|
4621
4748
|
...serializedInputs.meta !== void 0 && {
|
|
@@ -4797,7 +4924,7 @@ var Bitfab = class {
|
|
|
4797
4924
|
await runWithSeedContext({ traceId }, async () => target(...args));
|
|
4798
4925
|
} finally {
|
|
4799
4926
|
try {
|
|
4800
|
-
const { flushTraces: flushTraces2 } = await import("./http-
|
|
4927
|
+
const { flushTraces: flushTraces2 } = await import("./http-SEN3PUXX.js");
|
|
4801
4928
|
await flushTraces2(3e4);
|
|
4802
4929
|
} finally {
|
|
4803
4930
|
unrecorded = activeTraceStates.delete(traceId);
|
|
@@ -4856,7 +4983,7 @@ var Bitfab = class {
|
|
|
4856
4983
|
`Function is wrapped with trace function key '${wrappedKey}' but replay was called with '${traceFunctionKey}'. Pass matching keys, or pass the unwrapped function to replay it under the explicit key.`
|
|
4857
4984
|
);
|
|
4858
4985
|
}
|
|
4859
|
-
const { replay: doReplay } = await import("./replay-
|
|
4986
|
+
const { replay: doReplay } = await import("./replay-Y5RIJOWE.js");
|
|
4860
4987
|
return doReplay(
|
|
4861
4988
|
this.httpClient,
|
|
4862
4989
|
this.serviceUrl,
|
|
@@ -5140,7 +5267,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
|
|
|
5140
5267
|
sessionId: seedCase.sessionId
|
|
5141
5268
|
})
|
|
5142
5269
|
);
|
|
5143
|
-
const { flushTraces: flushTraces2 } = await import("./http-
|
|
5270
|
+
const { flushTraces: flushTraces2 } = await import("./http-SEN3PUXX.js");
|
|
5144
5271
|
await flushTraces2(3e4);
|
|
5145
5272
|
return { pipeline, traceFunctionKey, traceIds };
|
|
5146
5273
|
}
|
|
@@ -5177,4 +5304,4 @@ export {
|
|
|
5177
5304
|
reseedFromRegistry,
|
|
5178
5305
|
seedFromRegistry
|
|
5179
5306
|
};
|
|
5180
|
-
//# sourceMappingURL=chunk-
|
|
5307
|
+
//# sourceMappingURL=chunk-SCXR43UF.js.map
|