bitfab 0.43.1 → 0.44.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.
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-XFEEB6DH.js";
9
+ } from "./chunk-UUH6NLPT.js";
10
10
  export {
11
11
  BitfabError,
12
12
  HttpClient,
@@ -16,4 +16,4 @@ export {
16
16
  parseRetryAfterMs,
17
17
  serializePayloadBody
18
18
  };
19
- //# sourceMappingURL=http-QWLOMVEH.js.map
19
+ //# sourceMappingURL=http-N6ZAG2II.js.map
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-QP3ZDSMN.js";
9
+ } from "./chunk-DCF7NJK7.js";
10
10
  import "./chunk-H6LZRFMN.js";
11
11
  export {
12
12
  BitfabError,
@@ -17,4 +17,4 @@ export {
17
17
  parseRetryAfterMs,
18
18
  serializePayloadBody
19
19
  };
20
- //# sourceMappingURL=http-SV454Y6C.js.map
20
+ //# sourceMappingURL=http-TG6US6A2.js.map
package/dist/index.cjs CHANGED
@@ -51,7 +51,7 @@ var __version__, __packageName__;
51
51
  var init_version_generated = __esm({
52
52
  "src/version.generated.ts"() {
53
53
  "use strict";
54
- __version__ = "0.43.1";
54
+ __version__ = "0.44.0";
55
55
  __packageName__ = "bitfab";
56
56
  }
57
57
  });
@@ -173,7 +173,7 @@ var init_compress = __esm({
173
173
  });
174
174
 
175
175
  // src/errors.ts
176
- var BitfabError;
176
+ var BitfabError, MixedTracingError;
177
177
  var init_errors = __esm({
178
178
  "src/errors.ts"() {
179
179
  "use strict";
@@ -186,6 +186,12 @@ var init_errors = __esm({
186
186
  this.name = "BitfabError";
187
187
  }
188
188
  };
189
+ MixedTracingError = class extends Error {
190
+ constructor(message) {
191
+ super(message);
192
+ this.name = "MixedTracingError";
193
+ }
194
+ };
189
195
  }
190
196
  });
191
197
 
@@ -3264,6 +3270,7 @@ __export(index_exports, {
3264
3270
  DatasetsClient: () => DatasetsClient,
3265
3271
  DbBranchReplayError: () => DbBranchReplayError,
3266
3272
  HttpClient: () => HttpClient,
3273
+ MixedTracingError: () => MixedTracingError,
3267
3274
  NO_MOCK_OVERRIDE: () => NO_MOCK_OVERRIDE,
3268
3275
  ReplayError: () => ReplayError,
3269
3276
  SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
@@ -4337,6 +4344,50 @@ async function runFunctionWithBaml(bamlSource, inputs, providers, envVars) {
4337
4344
  };
4338
4345
  }
4339
4346
 
4347
+ // src/captureSurface.ts
4348
+ init_errors();
4349
+ var DEFAULT_SURFACE = "opt-in";
4350
+ var SURFACE_API = {
4351
+ "opt-in": "withSpan()",
4352
+ "opt-out": "withTrace()"
4353
+ };
4354
+ var MIXED_SURFACE_REMEDY = {
4355
+ "opt-in": "Inside a withTrace/trace subtree, configure a discovered call with node()/withNode() instead, or trace this workflow with withSpan() only.",
4356
+ "opt-out": "Wrap the caller with withTrace()/trace() as well, or wrap this function with withSpan()."
4357
+ };
4358
+ function resolveSurface(requested, parentSurface) {
4359
+ if (requested === "neutral") {
4360
+ return void 0;
4361
+ }
4362
+ if (requested === "inherit") {
4363
+ return parentSurface ?? DEFAULT_SURFACE;
4364
+ }
4365
+ return requested;
4366
+ }
4367
+ function mixedTracingError(enteredApi, entered, enclosing, traceFunctionKey) {
4368
+ const subject = traceFunctionKey === void 0 ? "" : ` for "${traceFunctionKey}"`;
4369
+ return new MixedTracingError(
4370
+ `opt-in and opt-out tracing can't be mixed in one call stack: ${enteredApi} (${entered})${subject} was entered inside a ${SURFACE_API[enclosing]} call (${enclosing}). ${MIXED_SURFACE_REMEDY[entered]}`
4371
+ );
4372
+ }
4373
+ function assertSurfacesCompatible(requested, resolved, parentSurface, traceFunctionKey) {
4374
+ if (requested === "inherit" || requested === "neutral") {
4375
+ return;
4376
+ }
4377
+ if (resolved === void 0 || parentSurface === void 0) {
4378
+ return;
4379
+ }
4380
+ if (parentSurface === resolved) {
4381
+ return;
4382
+ }
4383
+ throw mixedTracingError(
4384
+ SURFACE_API[resolved],
4385
+ resolved,
4386
+ parentSurface,
4387
+ traceFunctionKey
4388
+ );
4389
+ }
4390
+
4340
4391
  // src/client.ts
4341
4392
  init_constants();
4342
4393
 
@@ -4483,6 +4534,7 @@ function buildSnapshotRef(config, sdkWallClockBeforeFn) {
4483
4534
  }
4484
4535
 
4485
4536
  // src/client.ts
4537
+ init_errors();
4486
4538
  init_http();
4487
4539
 
4488
4540
  // src/langgraph.ts
@@ -5872,18 +5924,6 @@ var BitfabVercelAiHandler = class {
5872
5924
 
5873
5925
  // src/client.ts
5874
5926
  init_warnOnce();
5875
- var MIXED_SURFACE_REMEDY = {
5876
- "opt-in": "Inside a withTrace/trace subtree, configure a discovered call with node()/withNode() instead, or trace this workflow with withSpan() only.",
5877
- "opt-out": "Wrap the caller with withTrace()/trace() as well, or wrap this function with withSpan()."
5878
- };
5879
- function warnMixedTracingSurfaces(traceFunctionKey, entered, enclosing) {
5880
- const enteredApi = entered === "opt-in" ? "withSpan()" : "withTrace()";
5881
- const enclosingApi = enclosing === "opt-in" ? "withSpan()" : "withTrace()";
5882
- warnOnce(
5883
- `mixed-tracing-surface:${traceFunctionKey}:${entered}`,
5884
- `opt-in and opt-out tracing are mixed in one call stack: ${enteredApi} (${entered}) for "${traceFunctionKey}" was entered inside a ${enclosingApi} call (${enclosing}). Both are recorded, and the spans nest as written. ${MIXED_SURFACE_REMEDY[entered]}`
5885
- );
5886
- }
5887
5927
  var activeTraceStates = /* @__PURE__ */ new Map();
5888
5928
  var asyncLocalStorage = null;
5889
5929
  var SPAN_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.spanContextStorage");
@@ -5913,6 +5953,10 @@ function getSpanStack() {
5913
5953
  }
5914
5954
  return browserSpanStack;
5915
5955
  }
5956
+ function enclosingSurface() {
5957
+ const stack = getSpanStack();
5958
+ return stack[stack.length - 1]?.surface;
5959
+ }
5916
5960
  function runWithSpanStack(stack, fn) {
5917
5961
  if (asyncLocalStorage) {
5918
5962
  return asyncLocalStorage.run(stack, fn);
@@ -6399,6 +6443,9 @@ var Bitfab = class {
6399
6443
  const nodeConfiguration = { ...configuration, functionName };
6400
6444
  return function(...args) {
6401
6445
  if (!__bitfabAutoTraceActive()) {
6446
+ if (enclosingSurface() === "opt-in") {
6447
+ throw mixedTracingError("node()", "opt-out", "opt-in");
6448
+ }
6402
6449
  return fn.apply(this, args);
6403
6450
  }
6404
6451
  return runWithAutoTraceNodeConfiguration(
@@ -7100,20 +7147,19 @@ var Bitfab = class {
7100
7147
  const spanId = randomUuid();
7101
7148
  const parentSpanId = parentContext?.spanId ?? null;
7102
7149
  const isRootSpan = parentSpanId === null;
7103
- const requestedSurface = options.surface ?? "opt-in";
7104
- const surface = requestedSurface === "inherit" ? parentContext?.surface ?? "opt-in" : requestedSurface;
7105
- if (requestedSurface !== "inherit" && parentContext?.surface !== void 0 && parentContext.surface !== surface) {
7106
- warnMixedTracingSurfaces(
7107
- traceFunctionKey,
7108
- surface,
7109
- parentContext.surface
7110
- );
7111
- }
7150
+ const requestedSurface = options.surface ?? DEFAULT_SURFACE;
7151
+ const surface = resolveSurface(requestedSurface, parentContext?.surface);
7152
+ assertSurfacesCompatible(
7153
+ requestedSurface,
7154
+ surface,
7155
+ parentContext?.surface,
7156
+ traceFunctionKey
7157
+ );
7112
7158
  const newContext = {
7113
7159
  traceId,
7114
7160
  spanId,
7115
7161
  contexts: [],
7116
- surface
7162
+ ...surface !== void 0 && { surface }
7117
7163
  };
7118
7164
  newStack = [...currentStack, newContext];
7119
7165
  const inputs = args;
@@ -7396,6 +7442,9 @@ var Bitfab = class {
7396
7442
  if (registeredTraceId) {
7397
7443
  activeTraceStates.delete(registeredTraceId);
7398
7444
  }
7445
+ if (setupError instanceof MixedTracingError) {
7446
+ throw setupError;
7447
+ }
7399
7448
  if (getReplayContext() || inSeedScope()) {
7400
7449
  throw setupError;
7401
7450
  }
@@ -7795,9 +7844,14 @@ var Bitfab = class {
7795
7844
  const wrappedKey = fn._bitfabTraceFunctionKey;
7796
7845
  let target = fn;
7797
7846
  if (wrappedKey === void 0) {
7847
+ const seedRootOptions = {
7848
+ name: traceFunctionKey,
7849
+ type: "agent",
7850
+ surface: "neutral"
7851
+ };
7798
7852
  target = this.withSpan(
7799
7853
  traceFunctionKey,
7800
- { name: traceFunctionKey, type: "agent" },
7854
+ seedRootOptions,
7801
7855
  fn
7802
7856
  );
7803
7857
  } else if (wrappedKey !== traceFunctionKey) {
@@ -7839,11 +7893,12 @@ var Bitfab = class {
7839
7893
  const wrappedKey = fn._bitfabTraceFunctionKey;
7840
7894
  let replayFn = fn;
7841
7895
  if (wrappedKey === void 0) {
7842
- replayFn = this.withSpan(
7843
- traceFunctionKey,
7844
- { name: traceFunctionKey, type: "agent" },
7845
- fn
7846
- );
7896
+ const replayRootOptions = {
7897
+ name: traceFunctionKey,
7898
+ type: "agent",
7899
+ surface: "neutral"
7900
+ };
7901
+ replayFn = this.withSpan(traceFunctionKey, replayRootOptions, fn);
7847
7902
  } else if (wrappedKey !== traceFunctionKey) {
7848
7903
  throw new BitfabError(
7849
7904
  `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.`
@@ -8156,6 +8211,7 @@ function resolveTraceFunctionKey(registration) {
8156
8211
  DatasetsClient,
8157
8212
  DbBranchReplayError,
8158
8213
  HttpClient,
8214
+ MixedTracingError,
8159
8215
  NO_MOCK_OVERRIDE,
8160
8216
  ReplayError,
8161
8217
  SUPPORTED_PROVIDERS,