bitfab 0.53.0 → 0.53.2
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/{chunk-DTC6SIXW.js → chunk-3LSPOHL7.js} +3 -3
- package/dist/{chunk-SCXR43UF.js → chunk-6SPWEVFD.js} +210 -76
- package/dist/chunk-6SPWEVFD.js.map +1 -0
- package/dist/{chunk-6IMGAODW.js → chunk-JZAKQDGR.js} +542 -32
- package/dist/chunk-JZAKQDGR.js.map +1 -0
- package/dist/{chunk-CBRO6BP7.js → chunk-S4UK5HNW.js} +141 -29
- package/dist/chunk-S4UK5HNW.js.map +1 -0
- package/dist/{chunk-SJKWUQ3G.js → chunk-V3KD7B3B.js} +2 -2
- package/dist/{http-KP7DVTOD.js → http-LOZSAC23.js} +2 -2
- package/dist/{http-SEN3PUXX.js → http-PUEEHMKU.js} +2 -2
- package/dist/index.cjs +792 -122
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -11
- package/dist/index.d.ts +29 -11
- package/dist/index.js +3 -3
- package/dist/node.cjs +792 -122
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +3 -3
- package/dist/{replay-Y5RIJOWE.js → replay-SSJ72WEI.js} +3 -3
- package/dist/replayCli.js +2 -2
- package/dist/seedCli.js +2 -2
- package/package.json +2 -1
- package/dist/chunk-6IMGAODW.js.map +0 -1
- package/dist/chunk-CBRO6BP7.js.map +0 -1
- package/dist/chunk-SCXR43UF.js.map +0 -1
- /package/dist/{chunk-DTC6SIXW.js.map → chunk-3LSPOHL7.js.map} +0 -0
- /package/dist/{chunk-SJKWUQ3G.js.map → chunk-V3KD7B3B.js.map} +0 -0
- /package/dist/{http-KP7DVTOD.js.map → http-LOZSAC23.js.map} +0 -0
- /package/dist/{http-SEN3PUXX.js.map → http-PUEEHMKU.js.map} +0 -0
- /package/dist/{replay-Y5RIJOWE.js.map → replay-SSJ72WEI.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BitfabError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-S4UK5HNW.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-LOZSAC23.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-3LSPOHL7.js.map
|
|
@@ -19,19 +19,23 @@ import {
|
|
|
19
19
|
serializeValue,
|
|
20
20
|
toJsonSafe,
|
|
21
21
|
toJsonSafeReport
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-V3KD7B3B.js";
|
|
23
23
|
import {
|
|
24
24
|
BitfabError,
|
|
25
25
|
DEFAULT_SERVICE_URL,
|
|
26
26
|
HttpClient,
|
|
27
27
|
MixedTracingError,
|
|
28
|
+
PolicyRefresh,
|
|
29
|
+
ROOT_TRACE_FUNCTION_KEY_FIELD,
|
|
30
|
+
SimulationPlan,
|
|
28
31
|
callerTraceMetadata,
|
|
29
32
|
getReplayContext,
|
|
33
|
+
makeSpanOrigin,
|
|
30
34
|
readEnv,
|
|
31
35
|
recordCallerTraceMetadata,
|
|
32
36
|
retireTraceMetadata,
|
|
33
37
|
warnOnce
|
|
34
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-JZAKQDGR.js";
|
|
35
39
|
import {
|
|
36
40
|
__privateAdd,
|
|
37
41
|
__privateGet,
|
|
@@ -340,6 +344,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
340
344
|
trace_id: spanInfo.traceId,
|
|
341
345
|
started_at: spanInfo.startedAt,
|
|
342
346
|
ended_at: spanInfo.endedAt ?? nowIso(),
|
|
347
|
+
span_origin: makeSpanOrigin("claude-agent-sdk"),
|
|
343
348
|
span_data: spanData
|
|
344
349
|
};
|
|
345
350
|
if (spanInfo.parentId !== null) {
|
|
@@ -1825,6 +1830,7 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
1825
1830
|
trace_id: spanInfo.traceId,
|
|
1826
1831
|
started_at: spanInfo.startedAt,
|
|
1827
1832
|
ended_at: spanInfo.endedAt ?? nowIso2(),
|
|
1833
|
+
span_origin: makeSpanOrigin("langgraph"),
|
|
1828
1834
|
span_data: spanData
|
|
1829
1835
|
};
|
|
1830
1836
|
if (spanInfo.parentId !== null) {
|
|
@@ -2284,7 +2290,8 @@ var BitfabLangGraphIntegration = class {
|
|
|
2284
2290
|
captureWhen: "nested",
|
|
2285
2291
|
mockOnReplay: shouldMock,
|
|
2286
2292
|
finalize: finalizeToolResult,
|
|
2287
|
-
surface: "inherit"
|
|
2293
|
+
surface: "inherit",
|
|
2294
|
+
instrumentation: "langgraph"
|
|
2288
2295
|
},
|
|
2289
2296
|
async (_args) => await originalInvoke(input, ...rest)
|
|
2290
2297
|
);
|
|
@@ -2327,7 +2334,12 @@ var BitfabLangGraphIntegration = class {
|
|
|
2327
2334
|
wrapInvoke(fn) {
|
|
2328
2335
|
return this.client.withSpan(
|
|
2329
2336
|
this.traceFunctionKey,
|
|
2330
|
-
{
|
|
2337
|
+
{
|
|
2338
|
+
name: this.traceFunctionKey,
|
|
2339
|
+
type: "agent",
|
|
2340
|
+
surface: "inherit",
|
|
2341
|
+
instrumentation: "langgraph"
|
|
2342
|
+
},
|
|
2331
2343
|
fn
|
|
2332
2344
|
);
|
|
2333
2345
|
}
|
|
@@ -2380,7 +2392,8 @@ var BitfabOpenAIAgentHandler = class {
|
|
|
2380
2392
|
const options_ = {
|
|
2381
2393
|
type: "agent",
|
|
2382
2394
|
finalize,
|
|
2383
|
-
surface: "inherit"
|
|
2395
|
+
surface: "inherit",
|
|
2396
|
+
instrumentation: "openai-agents"
|
|
2384
2397
|
};
|
|
2385
2398
|
const traced = this.withSpanFn(
|
|
2386
2399
|
this.traceFunctionKey,
|
|
@@ -2469,6 +2482,15 @@ function runWithSeedContext(ctx, fn) {
|
|
|
2469
2482
|
return fn();
|
|
2470
2483
|
}
|
|
2471
2484
|
|
|
2485
|
+
// src/streamFinalizationError.ts
|
|
2486
|
+
var StreamFinalizationError = class extends Error {
|
|
2487
|
+
constructor(message, output) {
|
|
2488
|
+
super(message);
|
|
2489
|
+
this.output = output;
|
|
2490
|
+
this.name = "StreamFinalizationError";
|
|
2491
|
+
}
|
|
2492
|
+
};
|
|
2493
|
+
|
|
2472
2494
|
// src/tracing.ts
|
|
2473
2495
|
var BitfabOpenAITracingProcessor = class {
|
|
2474
2496
|
/**
|
|
@@ -2671,6 +2693,7 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
2671
2693
|
* Build span payload for the external spans API.
|
|
2672
2694
|
*/
|
|
2673
2695
|
buildSpanPayload(serializedSpan, errors) {
|
|
2696
|
+
serializedSpan.span_origin = makeSpanOrigin("openai-agents");
|
|
2674
2697
|
const payload = {
|
|
2675
2698
|
id: randomUuid(),
|
|
2676
2699
|
type: "openai",
|
|
@@ -2735,52 +2758,110 @@ function summarizeGenerate(result, model) {
|
|
|
2735
2758
|
}
|
|
2736
2759
|
return summary;
|
|
2737
2760
|
}
|
|
2738
|
-
function accumulateStream(onComplete, model) {
|
|
2761
|
+
function accumulateStream(source, onComplete, model) {
|
|
2762
|
+
const reader = source.getReader();
|
|
2739
2763
|
let text = "";
|
|
2740
2764
|
const toolCalls = [];
|
|
2741
2765
|
let usage;
|
|
2742
2766
|
let finishReason;
|
|
2743
2767
|
let completed = false;
|
|
2744
|
-
|
|
2768
|
+
let streamFailure;
|
|
2769
|
+
const complete = (failure = streamFailure) => {
|
|
2745
2770
|
if (completed) {
|
|
2746
2771
|
return;
|
|
2747
2772
|
}
|
|
2748
2773
|
completed = true;
|
|
2749
|
-
|
|
2774
|
+
let error;
|
|
2775
|
+
if (failure !== void 0) {
|
|
2776
|
+
try {
|
|
2777
|
+
error = failure.error instanceof Error ? failure.error.message : String(
|
|
2778
|
+
failure.error ?? (failure.cancelled === true ? "Stream cancelled" : "Stream failed")
|
|
2779
|
+
);
|
|
2780
|
+
} catch {
|
|
2781
|
+
error = "Stream failed";
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
onComplete({
|
|
2750
2785
|
text,
|
|
2751
2786
|
toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
2752
2787
|
usage,
|
|
2753
|
-
finishReason
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
}
|
|
2758
|
-
onComplete(summary);
|
|
2788
|
+
finishReason,
|
|
2789
|
+
...model !== void 0 && { model },
|
|
2790
|
+
...failure !== void 0 && { error },
|
|
2791
|
+
...failure?.cancelled === true && { cancelled: true }
|
|
2792
|
+
});
|
|
2759
2793
|
};
|
|
2760
|
-
return new
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2794
|
+
return new ReadableStream(
|
|
2795
|
+
{
|
|
2796
|
+
start(controller) {
|
|
2797
|
+
void reader.closed.then(
|
|
2798
|
+
() => {
|
|
2799
|
+
queueMicrotask(() => {
|
|
2800
|
+
if (!completed) {
|
|
2801
|
+
complete();
|
|
2802
|
+
reader.releaseLock();
|
|
2803
|
+
controller.close();
|
|
2804
|
+
}
|
|
2805
|
+
});
|
|
2806
|
+
},
|
|
2807
|
+
(error) => {
|
|
2808
|
+
if (!completed) {
|
|
2809
|
+
complete({ error });
|
|
2810
|
+
controller.error(error);
|
|
2811
|
+
reader.releaseLock();
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
);
|
|
2815
|
+
},
|
|
2816
|
+
async pull(controller) {
|
|
2817
|
+
try {
|
|
2818
|
+
const { done, value: part } = await reader.read();
|
|
2819
|
+
if (completed) {
|
|
2820
|
+
return;
|
|
2821
|
+
}
|
|
2822
|
+
if (done) {
|
|
2823
|
+
complete();
|
|
2824
|
+
reader.releaseLock();
|
|
2825
|
+
controller.close();
|
|
2826
|
+
return;
|
|
2827
|
+
}
|
|
2828
|
+
try {
|
|
2829
|
+
if (part?.type === "text-delta") {
|
|
2830
|
+
text += part.delta ?? part.textDelta ?? "";
|
|
2831
|
+
} else if (part?.type === "tool-call") {
|
|
2832
|
+
toolCalls.push({
|
|
2833
|
+
toolCallId: part.toolCallId,
|
|
2834
|
+
toolName: part.toolName,
|
|
2835
|
+
input: part.input ?? part.args
|
|
2836
|
+
});
|
|
2837
|
+
} else if (part?.type === "error") {
|
|
2838
|
+
streamFailure = { error: part.error };
|
|
2839
|
+
} else if (part?.type === "finish") {
|
|
2840
|
+
usage = part.usage;
|
|
2841
|
+
finishReason = part.finishReason;
|
|
2842
|
+
}
|
|
2843
|
+
} catch {
|
|
2844
|
+
}
|
|
2845
|
+
controller.enqueue(part);
|
|
2846
|
+
} catch (error) {
|
|
2847
|
+
if (!completed) {
|
|
2848
|
+
complete({ error });
|
|
2849
|
+
reader.releaseLock();
|
|
2850
|
+
controller.error(error);
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
},
|
|
2854
|
+
async cancel(reason) {
|
|
2855
|
+
complete({ error: reason, cancelled: true });
|
|
2856
|
+
try {
|
|
2857
|
+
await reader.cancel(reason);
|
|
2858
|
+
} finally {
|
|
2859
|
+
reader.releaseLock();
|
|
2775
2860
|
}
|
|
2776
|
-
} catch {
|
|
2777
2861
|
}
|
|
2778
|
-
controller.enqueue(part);
|
|
2779
2862
|
},
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
}
|
|
2783
|
-
});
|
|
2863
|
+
{ highWaterMark: 0 }
|
|
2864
|
+
);
|
|
2784
2865
|
}
|
|
2785
2866
|
var BitfabVercelAiHandler = class {
|
|
2786
2867
|
constructor(config) {
|
|
@@ -2800,7 +2881,8 @@ var BitfabVercelAiHandler = class {
|
|
|
2800
2881
|
{
|
|
2801
2882
|
type: "llm",
|
|
2802
2883
|
finalize: (result) => summarizeGenerate(result ?? {}, label),
|
|
2803
|
-
surface: "inherit"
|
|
2884
|
+
surface: "inherit",
|
|
2885
|
+
instrumentation: "vercel-ai"
|
|
2804
2886
|
},
|
|
2805
2887
|
() => doGenerate()
|
|
2806
2888
|
);
|
|
@@ -2818,11 +2900,24 @@ var BitfabVercelAiHandler = class {
|
|
|
2818
2900
|
// The wrapped fn returns immediately with the live stream, so the span
|
|
2819
2901
|
// output cannot be read from the return value. `finalize` instead
|
|
2820
2902
|
// awaits the summary the accumulator resolves once the stream drains.
|
|
2821
|
-
{
|
|
2903
|
+
{
|
|
2904
|
+
type: "llm",
|
|
2905
|
+
finalize: async () => {
|
|
2906
|
+
const output = await summary;
|
|
2907
|
+
if (output.error !== void 0) {
|
|
2908
|
+
throw new StreamFinalizationError(output.error, output);
|
|
2909
|
+
}
|
|
2910
|
+
return output;
|
|
2911
|
+
},
|
|
2912
|
+
surface: "inherit",
|
|
2913
|
+
instrumentation: "vercel-ai"
|
|
2914
|
+
},
|
|
2822
2915
|
async () => {
|
|
2823
2916
|
const result = await doStream();
|
|
2824
|
-
const stream =
|
|
2825
|
-
|
|
2917
|
+
const stream = accumulateStream(
|
|
2918
|
+
result.stream,
|
|
2919
|
+
resolveSummary,
|
|
2920
|
+
label
|
|
2826
2921
|
);
|
|
2827
2922
|
return { ...result, stream };
|
|
2828
2923
|
}
|
|
@@ -2835,6 +2930,19 @@ var BitfabVercelAiHandler = class {
|
|
|
2835
2930
|
|
|
2836
2931
|
// src/client.ts
|
|
2837
2932
|
var activeTraceStates = /* @__PURE__ */ new Map();
|
|
2933
|
+
function rootTraceFunctionKeyOf(payload) {
|
|
2934
|
+
const captured = payload[ROOT_TRACE_FUNCTION_KEY_FIELD];
|
|
2935
|
+
if (typeof captured === "string") {
|
|
2936
|
+
return captured;
|
|
2937
|
+
}
|
|
2938
|
+
const traceId = payload.traceId;
|
|
2939
|
+
const live = typeof traceId === "string" ? activeTraceStates.get(traceId)?.traceFunctionKey : void 0;
|
|
2940
|
+
if (typeof live === "string") {
|
|
2941
|
+
return live;
|
|
2942
|
+
}
|
|
2943
|
+
const own = payload.traceFunctionKey;
|
|
2944
|
+
return typeof own === "string" ? own : void 0;
|
|
2945
|
+
}
|
|
2838
2946
|
var asyncLocalStorage = null;
|
|
2839
2947
|
var SPAN_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.spanContextStorage");
|
|
2840
2948
|
var initializeAsyncContext = () => {
|
|
@@ -3239,6 +3347,14 @@ var Bitfab = class {
|
|
|
3239
3347
|
serviceUrl: this.serviceUrl,
|
|
3240
3348
|
timeout: this.timeout
|
|
3241
3349
|
});
|
|
3350
|
+
this.simulationPlan = new SimulationPlan(
|
|
3351
|
+
this.httpClient,
|
|
3352
|
+
config.simulationPlan ?? true
|
|
3353
|
+
);
|
|
3354
|
+
this.httpClient.externalSpanTransform = (payload, submit) => this.applySimulationPlan(payload, submit);
|
|
3355
|
+
this.httpClient.externalTraceTransform = (payload, submit) => this.simulationPlan.sendTrace(payload, submit);
|
|
3356
|
+
this.httpClient.releaseHeldExternalSpans = (timeoutMs) => this.simulationPlan.release(timeoutMs);
|
|
3357
|
+
this.httpClient.stopSimulationPlan = () => this.simulationPlan.stop();
|
|
3242
3358
|
this.datasets = new DatasetsClient(this.httpClient);
|
|
3243
3359
|
this.traces = new TracesClient(this.httpClient);
|
|
3244
3360
|
this.labels = new LabelsClient(this.httpClient);
|
|
@@ -3389,6 +3505,7 @@ var Bitfab = class {
|
|
|
3389
3505
|
}
|
|
3390
3506
|
createAutoTraceRoot(traceFunctionKey, name, options, fn) {
|
|
3391
3507
|
const self = this;
|
|
3508
|
+
self.simulationPlan.refresh();
|
|
3392
3509
|
const maxDepth = autoTraceLimit(
|
|
3393
3510
|
options.maxDepth,
|
|
3394
3511
|
DEFAULT_AUTO_TRACE_MAX_DEPTH
|
|
@@ -3404,7 +3521,8 @@ var Bitfab = class {
|
|
|
3404
3521
|
name: options.name,
|
|
3405
3522
|
nameFor: rootNameFor,
|
|
3406
3523
|
type: options.type ?? "custom",
|
|
3407
|
-
surface: "opt-out"
|
|
3524
|
+
surface: "opt-out",
|
|
3525
|
+
instrumentation: "trace"
|
|
3408
3526
|
};
|
|
3409
3527
|
const buildTracedRoot = (spanOptions) => this.withSpan(
|
|
3410
3528
|
traceFunctionKey,
|
|
@@ -3415,6 +3533,7 @@ var Bitfab = class {
|
|
|
3415
3533
|
traceFunctionKey
|
|
3416
3534
|
);
|
|
3417
3535
|
self.refreshAutoTraceCapturePolicy(traceFunctionKey);
|
|
3536
|
+
self.simulationPlan.refresh();
|
|
3418
3537
|
let spansUsed = 0;
|
|
3419
3538
|
let truncated = false;
|
|
3420
3539
|
const warnTruncated = () => {
|
|
@@ -3491,6 +3610,7 @@ var Bitfab = class {
|
|
|
3491
3610
|
type: nodeConfiguration?.type ?? "function",
|
|
3492
3611
|
captureWhen: "nested",
|
|
3493
3612
|
surface: "opt-out",
|
|
3613
|
+
instrumentation: "trace",
|
|
3494
3614
|
functionId: definition.id,
|
|
3495
3615
|
captureContent: nodeConfiguration !== void 0 || capturePolicy === void 0 || capturePolicy.has(definition.id),
|
|
3496
3616
|
autoTraceDefinition: definition,
|
|
@@ -3522,6 +3642,7 @@ var Bitfab = class {
|
|
|
3522
3642
|
type: "function",
|
|
3523
3643
|
captureWhen: "nested",
|
|
3524
3644
|
surface: "opt-out",
|
|
3645
|
+
instrumentation: "trace",
|
|
3525
3646
|
captureContent: true,
|
|
3526
3647
|
...link !== void 0 && { nestedTrace: link }
|
|
3527
3648
|
};
|
|
@@ -3587,38 +3708,36 @@ var Bitfab = class {
|
|
|
3587
3708
|
Object.defineProperty(autoTraceRoot, "_bitfabWrappedFn", { value: fn });
|
|
3588
3709
|
return autoTraceRoot;
|
|
3589
3710
|
}
|
|
3711
|
+
applySimulationPlan(payload, submit) {
|
|
3712
|
+
this.simulationPlan.send(payload, rootTraceFunctionKeyOf(payload), submit);
|
|
3713
|
+
}
|
|
3590
3714
|
refreshAutoTraceCapturePolicy(traceFunctionKey) {
|
|
3591
|
-
const
|
|
3592
|
-
const state = this.autoTracePolicyRefreshes.get(traceFunctionKey) ?? {
|
|
3593
|
-
refreshAfter: 0
|
|
3594
|
-
};
|
|
3595
|
-
if (state.inFlight || now < state.refreshAfter) {
|
|
3596
|
-
return;
|
|
3597
|
-
}
|
|
3598
|
-
const request = this.httpClient.getAutoTracePolicy(
|
|
3599
|
-
traceFunctionKey,
|
|
3600
|
-
AUTO_TRACE_PROTOCOL
|
|
3601
|
-
).then((policy) => {
|
|
3602
|
-
if (policy.protocol !== AUTO_TRACE_PROTOCOL) {
|
|
3603
|
-
state.refreshAfter = Date.now() + AUTO_TRACE_POLICY_RETRY_MS;
|
|
3604
|
-
return;
|
|
3605
|
-
}
|
|
3606
|
-
const functionIds = Array.isArray(policy.functionIds) ? policy.functionIds.filter(
|
|
3607
|
-
(id) => typeof id === "string" && id.startsWith(`${AUTO_TRACE_PROTOCOL}:`)
|
|
3608
|
-
).slice(0, DEFAULT_AUTO_TRACE_MAX_SPANS) : [];
|
|
3609
|
-
__setBitfabAutoTraceCapturePolicy(
|
|
3610
|
-
this,
|
|
3611
|
-
traceFunctionKey,
|
|
3612
|
-
policy.revision === null ? void 0 : functionIds
|
|
3613
|
-
);
|
|
3614
|
-
state.refreshAfter = Date.now() + AUTO_TRACE_POLICY_REFRESH_MS;
|
|
3615
|
-
}).catch(() => {
|
|
3616
|
-
state.refreshAfter = Date.now() + AUTO_TRACE_POLICY_RETRY_MS;
|
|
3617
|
-
}).finally(() => {
|
|
3618
|
-
state.inFlight = void 0;
|
|
3619
|
-
});
|
|
3620
|
-
state.inFlight = request;
|
|
3715
|
+
const state = this.autoTracePolicyRefreshes.get(traceFunctionKey) ?? new PolicyRefresh();
|
|
3621
3716
|
this.autoTracePolicyRefreshes.set(traceFunctionKey, state);
|
|
3717
|
+
state.run(
|
|
3718
|
+
() => this.httpClient.getAutoTracePolicy(
|
|
3719
|
+
traceFunctionKey,
|
|
3720
|
+
AUTO_TRACE_PROTOCOL
|
|
3721
|
+
),
|
|
3722
|
+
(policy) => {
|
|
3723
|
+
if (policy.protocol !== AUTO_TRACE_PROTOCOL) {
|
|
3724
|
+
state.hold(AUTO_TRACE_POLICY_RETRY_MS);
|
|
3725
|
+
return;
|
|
3726
|
+
}
|
|
3727
|
+
const functionIds = Array.isArray(policy.functionIds) ? policy.functionIds.filter(
|
|
3728
|
+
(id) => typeof id === "string" && id.startsWith(`${AUTO_TRACE_PROTOCOL}:`)
|
|
3729
|
+
).slice(0, DEFAULT_AUTO_TRACE_MAX_SPANS) : [];
|
|
3730
|
+
__setBitfabAutoTraceCapturePolicy(
|
|
3731
|
+
this,
|
|
3732
|
+
traceFunctionKey,
|
|
3733
|
+
policy.revision === null ? void 0 : functionIds
|
|
3734
|
+
);
|
|
3735
|
+
state.hold(AUTO_TRACE_POLICY_REFRESH_MS);
|
|
3736
|
+
},
|
|
3737
|
+
() => {
|
|
3738
|
+
state.hold(AUTO_TRACE_POLICY_RETRY_MS);
|
|
3739
|
+
}
|
|
3740
|
+
);
|
|
3622
3741
|
}
|
|
3623
3742
|
/**
|
|
3624
3743
|
* Flush and permanently close this client's tracing resources: its pending
|
|
@@ -4102,6 +4221,7 @@ var Bitfab = class {
|
|
|
4102
4221
|
* @returns A wrapped function with the same signature that creates spans for inputs and outputs
|
|
4103
4222
|
*/
|
|
4104
4223
|
withSpan(traceFunctionKey, optionsOrFn, maybeFn) {
|
|
4224
|
+
this.simulationPlan.refresh();
|
|
4105
4225
|
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
4106
4226
|
const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
|
|
4107
4227
|
const self = this;
|
|
@@ -4193,8 +4313,10 @@ var Bitfab = class {
|
|
|
4193
4313
|
const testRunId = replayCtxAtStart?.testRunId ?? options.testRunId;
|
|
4194
4314
|
if (isRootSpan && !activeTraceStates.has(traceId)) {
|
|
4195
4315
|
const dbSnapshotRef = buildSnapshotRef(self.dbSnapshot, startedAt);
|
|
4316
|
+
self.simulationPlan.refresh();
|
|
4196
4317
|
activeTraceStates.set(traceId, {
|
|
4197
4318
|
traceId,
|
|
4319
|
+
traceFunctionKey,
|
|
4198
4320
|
startedAt,
|
|
4199
4321
|
contexts: [],
|
|
4200
4322
|
...testRunId !== void 0 && { testRunId },
|
|
@@ -4209,8 +4331,10 @@ var Bitfab = class {
|
|
|
4209
4331
|
registeredTraceId = traceId;
|
|
4210
4332
|
}
|
|
4211
4333
|
const functionName = fn.name !== "" ? fn.name : void 0;
|
|
4334
|
+
const rootTraceFunctionKey = activeTraceStates.get(traceId)?.traceFunctionKey ?? traceFunctionKey;
|
|
4212
4335
|
const baseSpanParams = {
|
|
4213
4336
|
traceFunctionKey,
|
|
4337
|
+
rootTraceFunctionKey,
|
|
4214
4338
|
functionName,
|
|
4215
4339
|
spanName: options.name ?? options.nameFor?.(this) ?? qualifiedSpanName(this, functionName) ?? traceFunctionKey,
|
|
4216
4340
|
traceId,
|
|
@@ -4219,6 +4343,7 @@ var Bitfab = class {
|
|
|
4219
4343
|
inputs,
|
|
4220
4344
|
startedAt,
|
|
4221
4345
|
spanType: options.type ?? "custom",
|
|
4346
|
+
instrumentation: options.instrumentation ?? "span",
|
|
4222
4347
|
functionId: options.functionId,
|
|
4223
4348
|
captureContent: options.captureContent ?? true,
|
|
4224
4349
|
autoTraceDefinition: options.autoTraceDefinition,
|
|
@@ -4286,8 +4411,8 @@ var Bitfab = class {
|
|
|
4286
4411
|
void self.httpClient.trackDeferred(
|
|
4287
4412
|
Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
|
|
4288
4413
|
(error) => sendSpan({
|
|
4289
|
-
result: void 0,
|
|
4290
|
-
error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
4414
|
+
result: error instanceof StreamFinalizationError ? error.output : void 0,
|
|
4415
|
+
error: error instanceof StreamFinalizationError ? error.message : error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
|
|
4291
4416
|
})
|
|
4292
4417
|
)
|
|
4293
4418
|
);
|
|
@@ -4634,6 +4759,7 @@ var Bitfab = class {
|
|
|
4634
4759
|
* @returns A BitfabFunction instance for wrapping functions
|
|
4635
4760
|
*/
|
|
4636
4761
|
getFunction(traceFunctionKey) {
|
|
4762
|
+
this.simulationPlan.refresh();
|
|
4637
4763
|
return new BitfabFunction(this, traceFunctionKey);
|
|
4638
4764
|
}
|
|
4639
4765
|
/**
|
|
@@ -4721,6 +4847,7 @@ var Bitfab = class {
|
|
|
4721
4847
|
trace_id: params.traceId,
|
|
4722
4848
|
started_at: params.startedAt,
|
|
4723
4849
|
ended_at: params.endedAt,
|
|
4850
|
+
span_origin: makeSpanOrigin(params.instrumentation),
|
|
4724
4851
|
span_data: {
|
|
4725
4852
|
name: params.spanName,
|
|
4726
4853
|
type: params.spanType,
|
|
@@ -4781,6 +4908,9 @@ var Bitfab = class {
|
|
|
4781
4908
|
source: "typescript-sdk-function",
|
|
4782
4909
|
sourceTraceId: params.traceId,
|
|
4783
4910
|
traceFunctionKey: params.traceFunctionKey,
|
|
4911
|
+
...params.rootTraceFunctionKey !== void 0 && {
|
|
4912
|
+
[ROOT_TRACE_FUNCTION_KEY_FIELD]: params.rootTraceFunctionKey
|
|
4913
|
+
},
|
|
4784
4914
|
rawSpan: externalSpan,
|
|
4785
4915
|
...params.testRunId && { testRunId: params.testRunId },
|
|
4786
4916
|
...params.mocked && { mocked: true },
|
|
@@ -4849,6 +4979,7 @@ var Bitfab = class {
|
|
|
4849
4979
|
}
|
|
4850
4980
|
activeTraceStates.set(traceId, {
|
|
4851
4981
|
traceId,
|
|
4982
|
+
traceFunctionKey,
|
|
4852
4983
|
startedAt,
|
|
4853
4984
|
contexts: [],
|
|
4854
4985
|
ingestionType: "seeded",
|
|
@@ -4858,6 +4989,7 @@ var Bitfab = class {
|
|
|
4858
4989
|
try {
|
|
4859
4990
|
this.sendWrapperSpan({
|
|
4860
4991
|
traceFunctionKey,
|
|
4992
|
+
rootTraceFunctionKey: traceFunctionKey,
|
|
4861
4993
|
spanName: options.spanName ?? traceFunctionKey,
|
|
4862
4994
|
traceId,
|
|
4863
4995
|
spanId: randomUuid(),
|
|
@@ -4867,6 +4999,7 @@ var Bitfab = class {
|
|
|
4867
4999
|
startedAt,
|
|
4868
5000
|
endedAt: startedAt,
|
|
4869
5001
|
spanType: options.spanType ?? "agent",
|
|
5002
|
+
instrumentation: "span",
|
|
4870
5003
|
captureContent: true
|
|
4871
5004
|
});
|
|
4872
5005
|
this.sendTraceCompletion({
|
|
@@ -4912,6 +5045,7 @@ var Bitfab = class {
|
|
|
4912
5045
|
}
|
|
4913
5046
|
activeTraceStates.set(traceId, {
|
|
4914
5047
|
traceId,
|
|
5048
|
+
traceFunctionKey,
|
|
4915
5049
|
startedAt: nowIsoTimestamp(),
|
|
4916
5050
|
contexts: [],
|
|
4917
5051
|
ingestionType: "seeded",
|
|
@@ -4924,7 +5058,7 @@ var Bitfab = class {
|
|
|
4924
5058
|
await runWithSeedContext({ traceId }, async () => target(...args));
|
|
4925
5059
|
} finally {
|
|
4926
5060
|
try {
|
|
4927
|
-
const { flushTraces: flushTraces2 } = await import("./http-
|
|
5061
|
+
const { flushTraces: flushTraces2 } = await import("./http-PUEEHMKU.js");
|
|
4928
5062
|
await flushTraces2(3e4);
|
|
4929
5063
|
} finally {
|
|
4930
5064
|
unrecorded = activeTraceStates.delete(traceId);
|
|
@@ -4983,7 +5117,7 @@ var Bitfab = class {
|
|
|
4983
5117
|
`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.`
|
|
4984
5118
|
);
|
|
4985
5119
|
}
|
|
4986
|
-
const { replay: doReplay } = await import("./replay-
|
|
5120
|
+
const { replay: doReplay } = await import("./replay-SSJ72WEI.js");
|
|
4987
5121
|
return doReplay(
|
|
4988
5122
|
this.httpClient,
|
|
4989
5123
|
this.serviceUrl,
|
|
@@ -5267,7 +5401,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
|
|
|
5267
5401
|
sessionId: seedCase.sessionId
|
|
5268
5402
|
})
|
|
5269
5403
|
);
|
|
5270
|
-
const { flushTraces: flushTraces2 } = await import("./http-
|
|
5404
|
+
const { flushTraces: flushTraces2 } = await import("./http-PUEEHMKU.js");
|
|
5271
5405
|
await flushTraces2(3e4);
|
|
5272
5406
|
return { pipeline, traceFunctionKey, traceIds };
|
|
5273
5407
|
}
|
|
@@ -5304,4 +5438,4 @@ export {
|
|
|
5304
5438
|
reseedFromRegistry,
|
|
5305
5439
|
seedFromRegistry
|
|
5306
5440
|
};
|
|
5307
|
-
//# sourceMappingURL=chunk-
|
|
5441
|
+
//# sourceMappingURL=chunk-6SPWEVFD.js.map
|