@bitfab/sdk 0.43.0 → 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.
package/dist/index.d.cts CHANGED
@@ -98,6 +98,9 @@ declare class BitfabError extends Error {
98
98
  */
99
99
  retryAfterMs?: number | undefined);
100
100
  }
101
+ declare class MixedTracingError extends Error {
102
+ constructor(message: string);
103
+ }
101
104
 
102
105
  /**
103
106
  * Selective mock overrides for replay.
@@ -1434,12 +1437,6 @@ declare class BitfabOpenAIAgentHandler {
1434
1437
  */
1435
1438
 
1436
1439
  type MockStrategy = "none" | "all" | "marked";
1437
- /**
1438
- * How a source trace came to exist. A `seeded` trace was written from a case
1439
- * with {@link Bitfab.seedTrace} rather than executed, so it has no recorded
1440
- * child spans to mock from and no database state to restore, and its recorded
1441
- * output is the value the case expected rather than a previous run's result.
1442
- */
1443
1440
  type TraceIngestionType = "captured" | "seeded";
1444
1441
  /**
1445
1442
  * How the DB-snapshot branch each replay item runs against is sized and warmed.
@@ -1787,11 +1784,6 @@ interface ReplayItem<T> {
1787
1784
  input: unknown[];
1788
1785
  /** The result returned by the function during replay, or undefined on error. */
1789
1786
  result: T | undefined;
1790
- /**
1791
- * The original output from the historical trace. For a `seeded` source this
1792
- * is the value the case expected, not a previous run's result, so a
1793
- * difference means the code missed the expectation rather than drifted.
1794
- */
1795
1787
  originalOutput: unknown;
1796
1788
  /**
1797
1789
  * How the source trace came to exist. Absent on servers that predate the
@@ -2107,6 +2099,7 @@ declare class BitfabOpenAITracingProcessor implements TracingProcessor {
2107
2099
  }
2108
2100
 
2109
2101
  type CaptureSurface = "opt-in" | "opt-out";
2102
+
2110
2103
  /**
2111
2104
  * Options for wrapBAML.
2112
2105
  */
@@ -3089,7 +3082,7 @@ declare class BitfabFunction {
3089
3082
  /**
3090
3083
  * SDK version from package.json (injected at build time)
3091
3084
  */
3092
- declare const __version__ = "0.43.0";
3085
+ declare const __version__ = "0.44.0";
3093
3086
 
3094
3087
  /**
3095
3088
  * Constants for the Bitfab SDK.
@@ -3219,4 +3212,4 @@ declare function seedFromRegistry(registry: ReplayRegistry, pipeline: string, ca
3219
3212
  run?: boolean;
3220
3213
  }): Promise<SeedResult>;
3221
3214
 
3222
- export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AddDatasetGradersResult, type AddDatasetTracesResult, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabLangGraphIntegration, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureSurface, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type Dataset, type DatasetGraderRef, type DatasetTraceIds, DatasetsClient, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type GraderRerun, type GraderRerunProgress, type GraderRerunResult, type GraderRerunStatus, HttpClient, type LangGraphIntegrationOptions, type ListDatasetsParams, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, type RemoveDatasetGradersResult, type RemoveDatasetTracesResult, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, type RerunGradersOptions, type RerunGradersResult, SUPPORTED_PROVIDERS, type SaveDatasetParams, type SaveDatasetResult, type SeedCase, type SeedCaseOptions, type SeedResult, type SeedRunOptions, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceIngestionType, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, seedFromRegistry, serializeReplayResult };
3215
+ export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AddDatasetGradersResult, type AddDatasetTracesResult, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabLangGraphIntegration, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureSurface, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type Dataset, type DatasetGraderRef, type DatasetTraceIds, DatasetsClient, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type GraderRerun, type GraderRerunProgress, type GraderRerunResult, type GraderRerunStatus, HttpClient, type LangGraphIntegrationOptions, type ListDatasetsParams, MixedTracingError, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, type RemoveDatasetGradersResult, type RemoveDatasetTracesResult, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, type RerunGradersOptions, type RerunGradersResult, SUPPORTED_PROVIDERS, type SaveDatasetParams, type SaveDatasetResult, type SeedCase, type SeedCaseOptions, type SeedResult, type SeedRunOptions, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceIngestionType, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, seedFromRegistry, serializeReplayResult };
package/dist/index.d.ts CHANGED
@@ -98,6 +98,9 @@ declare class BitfabError extends Error {
98
98
  */
99
99
  retryAfterMs?: number | undefined);
100
100
  }
101
+ declare class MixedTracingError extends Error {
102
+ constructor(message: string);
103
+ }
101
104
 
102
105
  /**
103
106
  * Selective mock overrides for replay.
@@ -1434,12 +1437,6 @@ declare class BitfabOpenAIAgentHandler {
1434
1437
  */
1435
1438
 
1436
1439
  type MockStrategy = "none" | "all" | "marked";
1437
- /**
1438
- * How a source trace came to exist. A `seeded` trace was written from a case
1439
- * with {@link Bitfab.seedTrace} rather than executed, so it has no recorded
1440
- * child spans to mock from and no database state to restore, and its recorded
1441
- * output is the value the case expected rather than a previous run's result.
1442
- */
1443
1440
  type TraceIngestionType = "captured" | "seeded";
1444
1441
  /**
1445
1442
  * How the DB-snapshot branch each replay item runs against is sized and warmed.
@@ -1787,11 +1784,6 @@ interface ReplayItem<T> {
1787
1784
  input: unknown[];
1788
1785
  /** The result returned by the function during replay, or undefined on error. */
1789
1786
  result: T | undefined;
1790
- /**
1791
- * The original output from the historical trace. For a `seeded` source this
1792
- * is the value the case expected, not a previous run's result, so a
1793
- * difference means the code missed the expectation rather than drifted.
1794
- */
1795
1787
  originalOutput: unknown;
1796
1788
  /**
1797
1789
  * How the source trace came to exist. Absent on servers that predate the
@@ -2107,6 +2099,7 @@ declare class BitfabOpenAITracingProcessor implements TracingProcessor {
2107
2099
  }
2108
2100
 
2109
2101
  type CaptureSurface = "opt-in" | "opt-out";
2102
+
2110
2103
  /**
2111
2104
  * Options for wrapBAML.
2112
2105
  */
@@ -3089,7 +3082,7 @@ declare class BitfabFunction {
3089
3082
  /**
3090
3083
  * SDK version from package.json (injected at build time)
3091
3084
  */
3092
- declare const __version__ = "0.43.0";
3085
+ declare const __version__ = "0.44.0";
3093
3086
 
3094
3087
  /**
3095
3088
  * Constants for the Bitfab SDK.
@@ -3219,4 +3212,4 @@ declare function seedFromRegistry(registry: ReplayRegistry, pipeline: string, ca
3219
3212
  run?: boolean;
3220
3213
  }): Promise<SeedResult>;
3221
3214
 
3222
- export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AddDatasetGradersResult, type AddDatasetTracesResult, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabLangGraphIntegration, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureSurface, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type Dataset, type DatasetGraderRef, type DatasetTraceIds, DatasetsClient, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type GraderRerun, type GraderRerunProgress, type GraderRerunResult, type GraderRerunStatus, HttpClient, type LangGraphIntegrationOptions, type ListDatasetsParams, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, type RemoveDatasetGradersResult, type RemoveDatasetTracesResult, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, type RerunGradersOptions, type RerunGradersResult, SUPPORTED_PROVIDERS, type SaveDatasetParams, type SaveDatasetResult, type SeedCase, type SeedCaseOptions, type SeedResult, type SeedRunOptions, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceIngestionType, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, seedFromRegistry, serializeReplayResult };
3215
+ export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AddDatasetGradersResult, type AddDatasetTracesResult, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabLangGraphIntegration, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureSurface, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type Dataset, type DatasetGraderRef, type DatasetTraceIds, DatasetsClient, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type GraderRerun, type GraderRerunProgress, type GraderRerunResult, type GraderRerunStatus, HttpClient, type LangGraphIntegrationOptions, type ListDatasetsParams, MixedTracingError, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, type RemoveDatasetGradersResult, type RemoveDatasetTracesResult, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, type RerunGradersOptions, type RerunGradersResult, SUPPORTED_PROVIDERS, type SaveDatasetParams, type SaveDatasetResult, type SeedCase, type SeedCaseOptions, type SeedResult, type SeedRunOptions, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceIngestionType, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, seedFromRegistry, serializeReplayResult };
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  getCurrentSpan,
16
16
  getCurrentTrace,
17
17
  seedFromRegistry
18
- } from "./chunk-5BBJ5BQD.js";
18
+ } from "./chunk-XYMG2FH7.js";
19
19
  import "./chunk-ZUD7OFYB.js";
20
20
  import {
21
21
  BITFAB_PROGRESS_PREFIX,
@@ -24,14 +24,15 @@ import {
24
24
  ReplayError,
25
25
  reportReplayProgress,
26
26
  serializeReplayResult
27
- } from "./chunk-BXBRVWWW.js";
27
+ } from "./chunk-3WIN3VU3.js";
28
28
  import {
29
29
  BitfabError,
30
30
  DEFAULT_SERVICE_URL,
31
31
  HttpClient,
32
+ MixedTracingError,
32
33
  __version__,
33
34
  flushTraces
34
- } from "./chunk-6EM2S5H5.js";
35
+ } from "./chunk-6JTVCM2L.js";
35
36
  import "./chunk-H6LZRFMN.js";
36
37
  export {
37
38
  BITFAB_PROGRESS_PREFIX,
@@ -49,6 +50,7 @@ export {
49
50
  DatasetsClient,
50
51
  DbBranchReplayError,
51
52
  HttpClient,
53
+ MixedTracingError,
52
54
  NO_MOCK_OVERRIDE,
53
55
  ReplayError,
54
56
  SUPPORTED_PROVIDERS,
package/dist/node.cjs CHANGED
@@ -88,7 +88,7 @@ var __version__, __packageName__;
88
88
  var init_version_generated = __esm({
89
89
  "src/version.generated.ts"() {
90
90
  "use strict";
91
- __version__ = "0.43.0";
91
+ __version__ = "0.44.0";
92
92
  __packageName__ = "@bitfab/sdk";
93
93
  }
94
94
  });
@@ -210,7 +210,7 @@ var init_compress = __esm({
210
210
  });
211
211
 
212
212
  // src/errors.ts
213
- var BitfabError;
213
+ var BitfabError, MixedTracingError;
214
214
  var init_errors = __esm({
215
215
  "src/errors.ts"() {
216
216
  "use strict";
@@ -223,6 +223,12 @@ var init_errors = __esm({
223
223
  this.name = "BitfabError";
224
224
  }
225
225
  };
226
+ MixedTracingError = class extends Error {
227
+ constructor(message) {
228
+ super(message);
229
+ this.name = "MixedTracingError";
230
+ }
231
+ };
226
232
  }
227
233
  });
228
234
 
@@ -3262,6 +3268,7 @@ __export(node_exports, {
3262
3268
  DatasetsClient: () => DatasetsClient,
3263
3269
  DbBranchReplayError: () => DbBranchReplayError,
3264
3270
  HttpClient: () => HttpClient,
3271
+ MixedTracingError: () => MixedTracingError,
3265
3272
  NO_MOCK_OVERRIDE: () => NO_MOCK_OVERRIDE,
3266
3273
  ReplayError: () => ReplayError,
3267
3274
  SUPPORTED_PROVIDERS: () => SUPPORTED_PROVIDERS,
@@ -4342,6 +4349,50 @@ async function runFunctionWithBaml(bamlSource, inputs, providers, envVars) {
4342
4349
  };
4343
4350
  }
4344
4351
 
4352
+ // src/captureSurface.ts
4353
+ init_errors();
4354
+ var DEFAULT_SURFACE = "opt-in";
4355
+ var SURFACE_API = {
4356
+ "opt-in": "withSpan()",
4357
+ "opt-out": "withTrace()"
4358
+ };
4359
+ var MIXED_SURFACE_REMEDY = {
4360
+ "opt-in": "Inside a withTrace/trace subtree, configure a discovered call with node()/withNode() instead, or trace this workflow with withSpan() only.",
4361
+ "opt-out": "Wrap the caller with withTrace()/trace() as well, or wrap this function with withSpan()."
4362
+ };
4363
+ function resolveSurface(requested, parentSurface) {
4364
+ if (requested === "neutral") {
4365
+ return void 0;
4366
+ }
4367
+ if (requested === "inherit") {
4368
+ return parentSurface ?? DEFAULT_SURFACE;
4369
+ }
4370
+ return requested;
4371
+ }
4372
+ function mixedTracingError(enteredApi, entered, enclosing, traceFunctionKey) {
4373
+ const subject = traceFunctionKey === void 0 ? "" : ` for "${traceFunctionKey}"`;
4374
+ return new MixedTracingError(
4375
+ `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]}`
4376
+ );
4377
+ }
4378
+ function assertSurfacesCompatible(requested, resolved, parentSurface, traceFunctionKey) {
4379
+ if (requested === "inherit" || requested === "neutral") {
4380
+ return;
4381
+ }
4382
+ if (resolved === void 0 || parentSurface === void 0) {
4383
+ return;
4384
+ }
4385
+ if (parentSurface === resolved) {
4386
+ return;
4387
+ }
4388
+ throw mixedTracingError(
4389
+ SURFACE_API[resolved],
4390
+ resolved,
4391
+ parentSurface,
4392
+ traceFunctionKey
4393
+ );
4394
+ }
4395
+
4345
4396
  // src/client.ts
4346
4397
  init_constants();
4347
4398
 
@@ -4488,6 +4539,7 @@ function buildSnapshotRef(config, sdkWallClockBeforeFn) {
4488
4539
  }
4489
4540
 
4490
4541
  // src/client.ts
4542
+ init_errors();
4491
4543
  init_http();
4492
4544
 
4493
4545
  // src/langgraph.ts
@@ -5877,18 +5929,6 @@ var BitfabVercelAiHandler = class {
5877
5929
 
5878
5930
  // src/client.ts
5879
5931
  init_warnOnce();
5880
- var MIXED_SURFACE_REMEDY = {
5881
- "opt-in": "Inside a withTrace/trace subtree, configure a discovered call with node()/withNode() instead, or trace this workflow with withSpan() only.",
5882
- "opt-out": "Wrap the caller with withTrace()/trace() as well, or wrap this function with withSpan()."
5883
- };
5884
- function warnMixedTracingSurfaces(traceFunctionKey, entered, enclosing) {
5885
- const enteredApi = entered === "opt-in" ? "withSpan()" : "withTrace()";
5886
- const enclosingApi = enclosing === "opt-in" ? "withSpan()" : "withTrace()";
5887
- warnOnce(
5888
- `mixed-tracing-surface:${traceFunctionKey}:${entered}`,
5889
- `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]}`
5890
- );
5891
- }
5892
5932
  var activeTraceStates = /* @__PURE__ */ new Map();
5893
5933
  var asyncLocalStorage = null;
5894
5934
  var SPAN_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.spanContextStorage");
@@ -5918,6 +5958,10 @@ function getSpanStack() {
5918
5958
  }
5919
5959
  return browserSpanStack;
5920
5960
  }
5961
+ function enclosingSurface() {
5962
+ const stack = getSpanStack();
5963
+ return stack[stack.length - 1]?.surface;
5964
+ }
5921
5965
  function runWithSpanStack(stack, fn) {
5922
5966
  if (asyncLocalStorage) {
5923
5967
  return asyncLocalStorage.run(stack, fn);
@@ -6404,6 +6448,9 @@ var Bitfab = class {
6404
6448
  const nodeConfiguration = { ...configuration, functionName };
6405
6449
  return function(...args) {
6406
6450
  if (!__bitfabAutoTraceActive()) {
6451
+ if (enclosingSurface() === "opt-in") {
6452
+ throw mixedTracingError("node()", "opt-out", "opt-in");
6453
+ }
6407
6454
  return fn.apply(this, args);
6408
6455
  }
6409
6456
  return runWithAutoTraceNodeConfiguration(
@@ -7105,20 +7152,19 @@ var Bitfab = class {
7105
7152
  const spanId = randomUuid();
7106
7153
  const parentSpanId = parentContext?.spanId ?? null;
7107
7154
  const isRootSpan = parentSpanId === null;
7108
- const requestedSurface = options.surface ?? "opt-in";
7109
- const surface = requestedSurface === "inherit" ? parentContext?.surface ?? "opt-in" : requestedSurface;
7110
- if (requestedSurface !== "inherit" && parentContext?.surface !== void 0 && parentContext.surface !== surface) {
7111
- warnMixedTracingSurfaces(
7112
- traceFunctionKey,
7113
- surface,
7114
- parentContext.surface
7115
- );
7116
- }
7155
+ const requestedSurface = options.surface ?? DEFAULT_SURFACE;
7156
+ const surface = resolveSurface(requestedSurface, parentContext?.surface);
7157
+ assertSurfacesCompatible(
7158
+ requestedSurface,
7159
+ surface,
7160
+ parentContext?.surface,
7161
+ traceFunctionKey
7162
+ );
7117
7163
  const newContext = {
7118
7164
  traceId,
7119
7165
  spanId,
7120
7166
  contexts: [],
7121
- surface
7167
+ ...surface !== void 0 && { surface }
7122
7168
  };
7123
7169
  newStack = [...currentStack, newContext];
7124
7170
  const inputs = args;
@@ -7401,6 +7447,9 @@ var Bitfab = class {
7401
7447
  if (registeredTraceId) {
7402
7448
  activeTraceStates.delete(registeredTraceId);
7403
7449
  }
7450
+ if (setupError instanceof MixedTracingError) {
7451
+ throw setupError;
7452
+ }
7404
7453
  if (getReplayContext() || inSeedScope()) {
7405
7454
  throw setupError;
7406
7455
  }
@@ -7800,9 +7849,14 @@ var Bitfab = class {
7800
7849
  const wrappedKey = fn._bitfabTraceFunctionKey;
7801
7850
  let target = fn;
7802
7851
  if (wrappedKey === void 0) {
7852
+ const seedRootOptions = {
7853
+ name: traceFunctionKey,
7854
+ type: "agent",
7855
+ surface: "neutral"
7856
+ };
7803
7857
  target = this.withSpan(
7804
7858
  traceFunctionKey,
7805
- { name: traceFunctionKey, type: "agent" },
7859
+ seedRootOptions,
7806
7860
  fn
7807
7861
  );
7808
7862
  } else if (wrappedKey !== traceFunctionKey) {
@@ -7844,11 +7898,12 @@ var Bitfab = class {
7844
7898
  const wrappedKey = fn._bitfabTraceFunctionKey;
7845
7899
  let replayFn = fn;
7846
7900
  if (wrappedKey === void 0) {
7847
- replayFn = this.withSpan(
7848
- traceFunctionKey,
7849
- { name: traceFunctionKey, type: "agent" },
7850
- fn
7851
- );
7901
+ const replayRootOptions = {
7902
+ name: traceFunctionKey,
7903
+ type: "agent",
7904
+ surface: "neutral"
7905
+ };
7906
+ replayFn = this.withSpan(traceFunctionKey, replayRootOptions, fn);
7852
7907
  } else if (wrappedKey !== traceFunctionKey) {
7853
7908
  throw new BitfabError(
7854
7909
  `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.`
@@ -8165,6 +8220,7 @@ assertAsyncStorageRegistered();
8165
8220
  DatasetsClient,
8166
8221
  DbBranchReplayError,
8167
8222
  HttpClient,
8223
+ MixedTracingError,
8168
8224
  NO_MOCK_OVERRIDE,
8169
8225
  ReplayError,
8170
8226
  SUPPORTED_PROVIDERS,