@bitfab/sdk 0.57.8 → 0.58.1

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.cjs CHANGED
@@ -42,7 +42,7 @@ var __version__, __packageName__;
42
42
  var init_version_generated = __esm({
43
43
  "src/version.generated.ts"() {
44
44
  "use strict";
45
- __version__ = "0.57.8";
45
+ __version__ = "0.58.1";
46
46
  __packageName__ = "@bitfab/sdk";
47
47
  }
48
48
  });
@@ -1039,7 +1039,14 @@ function isTraceRootSpan(payload) {
1039
1039
  const parentId = rawSpanOf(payload)?.parent_id;
1040
1040
  return parentId === void 0 || parentId === null;
1041
1041
  }
1042
- var SIMULATION_PLAN_REFRESH_MS, SIMULATION_PLAN_RETRY_MS, SIMULATION_PLAN_READ_TIMEOUT_MS, SIMULATION_PLAN_MAX_HELD, DISABLE_SIMULATION_PLAN_ENV, ROOT_TRACE_FUNCTION_KEY_FIELD, CONTENT_OFF_KEY, CONTENT_KEYS, SimulationPlan;
1042
+ function declaredInCode(payload) {
1043
+ return payload[DECLARED_NODE_FIELD] === true;
1044
+ }
1045
+ function recordedError(payload) {
1046
+ const error = spanDataOf(payload)?.error;
1047
+ return error !== void 0 && error !== null;
1048
+ }
1049
+ var SIMULATION_PLAN_REFRESH_MS, SIMULATION_PLAN_RETRY_MS, SIMULATION_PLAN_READ_TIMEOUT_MS, SIMULATION_PLAN_MAX_HELD, DISABLE_SIMULATION_PLAN_ENV, ROOT_TRACE_FUNCTION_KEY_FIELD, DECLARED_NODE_FIELD, CONTENT_OFF_KEY, CONTENT_KEYS, SimulationPlan;
1043
1050
  var init_simulationPlan = __esm({
1044
1051
  "src/simulationPlan.ts"() {
1045
1052
  "use strict";
@@ -1054,6 +1061,7 @@ var init_simulationPlan = __esm({
1054
1061
  SIMULATION_PLAN_MAX_HELD = 1e3;
1055
1062
  DISABLE_SIMULATION_PLAN_ENV = "BITFAB_DISABLE_SIM_PLAN";
1056
1063
  ROOT_TRACE_FUNCTION_KEY_FIELD = "rootTraceFunctionKey";
1064
+ DECLARED_NODE_FIELD = "declaredNode";
1057
1065
  CONTENT_OFF_KEY = "content_off_by_simulation_plan";
1058
1066
  CONTENT_KEYS = [
1059
1067
  "input",
@@ -1225,7 +1233,7 @@ var init_simulationPlan = __esm({
1225
1233
  }
1226
1234
  }
1227
1235
  payloadToSend(entry) {
1228
- if (entry.traceFunctionKey === void 0) {
1236
+ if (entry.traceFunctionKey === void 0 || declaredInCode(entry.payload)) {
1229
1237
  return entry.payload;
1230
1238
  }
1231
1239
  if (this.contentOffByKey !== void 0) {
@@ -1237,6 +1245,10 @@ var init_simulationPlan = __esm({
1237
1245
  return stripContent(entry.payload);
1238
1246
  }
1239
1247
  submitEntry(entry) {
1248
+ if (entry.traceFunctionKey !== void 0 && this.skipsSpan(entry.payload, entry.traceFunctionKey)) {
1249
+ entry.drop?.();
1250
+ return;
1251
+ }
1240
1252
  try {
1241
1253
  entry.submit(this.payloadToSend(entry));
1242
1254
  } catch (error) {
@@ -1299,8 +1311,12 @@ var init_simulationPlan = __esm({
1299
1311
  contentOffNow(traceFunctionKey, spanName) {
1300
1312
  return !this.stopped && !this.disabled() && this.contentOff(traceFunctionKey, spanName);
1301
1313
  }
1314
+ skipsSpan(payload, traceFunctionKey) {
1315
+ const name = spanNameOf(payload);
1316
+ return name !== void 0 && this.contentOff(traceFunctionKey, name) && !isTraceRootSpan(payload) && !declaredInCode(payload) && spanInstrumentationOf(payload) !== void 0 && !recordedByFramework(payload) && !recordedError(payload);
1317
+ }
1302
1318
  apply(payload, traceFunctionKey) {
1303
- if (recordedByFramework(payload)) {
1319
+ if (recordedByFramework(payload) || declaredInCode(payload)) {
1304
1320
  return payload;
1305
1321
  }
1306
1322
  const name = spanNameOf(payload);
@@ -1696,7 +1712,7 @@ var init_otel = __esm({
1696
1712
  EXPORT_CONCURRENCY_ENV = "BITFAB_OTEL_EXPORT_CONCURRENCY";
1697
1713
  MAX_QUEUE_SIZE = 16384;
1698
1714
  DIRECT_MAX_EXPORT_BATCH_SIZE = 512;
1699
- DIRECT_MAX_REQUEST_BATCH_SIZE = 128;
1715
+ DIRECT_MAX_REQUEST_BATCH_SIZE = 256;
1700
1716
  DEFAULT_EXPORT_CONCURRENCY = 32;
1701
1717
  MAX_EXPORT_CONCURRENCY = 64;
1702
1718
  SCHEDULE_DELAY_MILLIS = 5e3;
@@ -2579,7 +2595,6 @@ var init_http = __esm({
2579
2595
  this.closed = true;
2580
2596
  this.externalSpanTransform = void 0;
2581
2597
  this.externalTraceTransform = void 0;
2582
- this.frameworkSpanStart = void 0;
2583
2598
  this.releaseHeldExternalSpans = void 0;
2584
2599
  this.stopSimulationPlan = void 0;
2585
2600
  const transport = this.traceTransport;
@@ -2762,16 +2777,6 @@ var init_http = __esm({
2762
2777
  carrierMeta("internal_trace", body, void 0)
2763
2778
  );
2764
2779
  }
2765
- reserveFrameworkSpan(traceId, spanId, parentSpanId) {
2766
- try {
2767
- this.frameworkSpanStart?.(traceId, spanId, parentSpanId ?? null);
2768
- } catch (error) {
2769
- warnOnce(
2770
- "framework-span-reservation-failed",
2771
- `a framework span could not be counted toward its trace's span limit: ${describeError(error)}`
2772
- );
2773
- }
2774
- }
2775
2780
  sendExternalSpan(payload) {
2776
2781
  const ref2 = carrierRef(payload);
2777
2782
  if (ref2?.spanId !== void 0) {
@@ -2800,6 +2805,7 @@ var init_http = __esm({
2800
2805
  sdkVersion: __version__
2801
2806
  };
2802
2807
  delete body[ROOT_TRACE_FUNCTION_KEY_FIELD];
2808
+ delete body[DECLARED_NODE_FIELD];
2803
2809
  this.getTraceTransport()?.submit(
2804
2810
  "external_span",
2805
2811
  body,
@@ -4676,11 +4682,6 @@ var BitfabClaudeAgentHandler = class {
4676
4682
  }
4677
4683
  this.runToSpan.set(spanId, spanInfo);
4678
4684
  this.httpClient.traceCompletion.start(spanInfo.traceId, spanInfo.spanId);
4679
- this.httpClient.reserveFrameworkSpan(
4680
- spanInfo.traceId,
4681
- spanInfo.spanId,
4682
- spanInfo.parentId
4683
- );
4684
4685
  return spanInfo;
4685
4686
  }
4686
4687
  completeSpan(spanId, output, error, extraContexts) {
@@ -4960,11 +4961,6 @@ var BitfabClaudeAgentHandler = class {
4960
4961
  this.conversationHistory.push(...this.pendingMessages);
4961
4962
  this.pendingMessages = [];
4962
4963
  this.currentLlmSpanId = randomUuid();
4963
- this.httpClient.reserveFrameworkSpan(
4964
- this.ensureTrace(),
4965
- this.currentLlmSpanId,
4966
- this.getParentId()
4967
- );
4968
4964
  this.currentLlmMessageId = messageId ?? null;
4969
4965
  this.currentLlmContent = [];
4970
4966
  this.currentLlmModel = inner.model ?? null;
@@ -6375,11 +6371,6 @@ var BitfabLangGraphCallbackHandler = class {
6375
6371
  this.runToSpan.set(runId, spanInfo);
6376
6372
  if (spanInfo.hidden !== true) {
6377
6373
  this.httpClient.traceCompletion.start(spanInfo.traceId, spanInfo.spanId);
6378
- this.httpClient.reserveFrameworkSpan(
6379
- spanInfo.traceId,
6380
- spanInfo.spanId,
6381
- spanInfo.parentId
6382
- );
6383
6374
  }
6384
6375
  if (isRootInvocation) {
6385
6376
  this.sendTraceStart(spanInfo);
@@ -7928,11 +7919,6 @@ var BitfabOpenAITracingProcessor = class {
7928
7919
  const mapping = this.activeSpanMappings[span.traceId];
7929
7920
  const traceId = mapping?.traceId ?? span.traceId;
7930
7921
  this.httpClient.traceCompletion.start(traceId, span.spanId);
7931
- this.httpClient.reserveFrameworkSpan(
7932
- traceId,
7933
- span.spanId,
7934
- span.parentId ?? mapping?.spanId
7935
- );
7936
7922
  }
7937
7923
  }
7938
7924
  /**
@@ -8321,56 +8307,9 @@ var BitfabVercelAiHandler = class {
8321
8307
  init_warnOnce();
8322
8308
  var TRUNCATION_LIMIT_ORDER = [
8323
8309
  "max_depth",
8324
- "max_spans",
8325
8310
  "max_captured_subtree_spans"
8326
8311
  ];
8327
8312
  var activeTraceStates = /* @__PURE__ */ new Map();
8328
- var REFUSED_FRAMEWORK_SPAN_TRACES_RETAINED = 1024;
8329
- var refusedFrameworkSpans = /* @__PURE__ */ new Map();
8330
- function frameworkSpanRefused(traceId, spanId) {
8331
- return refusedFrameworkSpans.get(traceId)?.has(spanId) === true;
8332
- }
8333
- function refuseFrameworkSpan(traceId, spanId) {
8334
- const refused = refusedFrameworkSpans.get(traceId);
8335
- if (refused !== void 0) {
8336
- refused.add(spanId);
8337
- return;
8338
- }
8339
- refusedFrameworkSpans.set(traceId, /* @__PURE__ */ new Set([spanId]));
8340
- while (refusedFrameworkSpans.size > REFUSED_FRAMEWORK_SPAN_TRACES_RETAINED) {
8341
- const oldest = refusedFrameworkSpans.keys().next();
8342
- if (oldest.done) {
8343
- return;
8344
- }
8345
- refusedFrameworkSpans.delete(oldest.value);
8346
- }
8347
- }
8348
- function reserveFrameworkSpan(traceId, spanId, parentSpanId) {
8349
- const spanBudget = activeTraceStates.get(traceId)?.spanBudget;
8350
- const parentRefused = parentSpanId !== null && frameworkSpanRefused(traceId, parentSpanId);
8351
- if (!parentRefused && (spanBudget === void 0 || spanBudget.spansUsed < spanBudget.maxSpans)) {
8352
- if (spanBudget !== void 0) {
8353
- spanBudget.spansUsed += 1;
8354
- }
8355
- return;
8356
- }
8357
- refuseFrameworkSpan(traceId, spanId);
8358
- spanBudget?.truncate("max_spans");
8359
- }
8360
- function isRefusedFrameworkSpan(payload) {
8361
- if (!recordedByFramework(payload)) {
8362
- return false;
8363
- }
8364
- const rawSpan = payload.rawSpan;
8365
- const spanId = rawSpan?.id;
8366
- if (typeof spanId !== "string") {
8367
- return false;
8368
- }
8369
- const traceIds = [payload.sourceTraceId, traceIdOf(payload)];
8370
- return traceIds.some(
8371
- (traceId) => typeof traceId === "string" && frameworkSpanRefused(traceId, spanId)
8372
- );
8373
- }
8374
8313
  function truncationMetadata(truncation) {
8375
8314
  if (truncation === void 0 || truncation.limits.size === 0) {
8376
8315
  return void 0;
@@ -8760,7 +8699,6 @@ function readBooleanEnv(name) {
8760
8699
  return void 0;
8761
8700
  }
8762
8701
  var DEFAULT_AUTO_TRACE_MAX_DEPTH = 30;
8763
- var DEFAULT_AUTO_TRACE_MAX_SPANS = 1e4;
8764
8702
  var DEFAULT_AUTO_TRACE_MAX_CAPTURED_SUBTREE_SPANS = 500;
8765
8703
  function spanOwnerName(receiver) {
8766
8704
  if (typeof receiver === "function") {
@@ -8828,7 +8766,6 @@ var Bitfab = class {
8828
8766
  config.simulationPlan ?? true
8829
8767
  );
8830
8768
  this.httpClient.externalSpanTransform = (payload, submit, drop) => this.applySimulationPlan(payload, submit, drop);
8831
- this.httpClient.frameworkSpanStart = reserveFrameworkSpan;
8832
8769
  this.httpClient.externalTraceTransform = (payload, submit) => this.simulationPlan.sendTrace(payload, submit);
8833
8770
  this.httpClient.releaseHeldExternalSpans = (timeoutMs) => this.simulationPlan.release(timeoutMs);
8834
8771
  this.httpClient.stopSimulationPlan = () => this.simulationPlan.stop();
@@ -8991,21 +8928,9 @@ var Bitfab = class {
8991
8928
  options.maxDepth,
8992
8929
  DEFAULT_AUTO_TRACE_MAX_DEPTH
8993
8930
  );
8994
- if (options.maxSpans !== void 0 && options.maxSpans < 1) {
8995
- throw new BitfabError(
8996
- `maxSpans must be at least 1 because the root span counts toward it (got ${options.maxSpans})`
8997
- );
8998
- }
8999
- const maxSpans = autoTraceLimit(
9000
- options.maxSpans,
9001
- DEFAULT_AUTO_TRACE_MAX_SPANS
9002
- );
9003
- const maxCapturedSubtreeSpans = Math.min(
9004
- autoTraceLimit(
9005
- options.maxCapturedSubtreeSpans,
9006
- DEFAULT_AUTO_TRACE_MAX_CAPTURED_SUBTREE_SPANS
9007
- ),
9008
- maxSpans
8931
+ const maxCapturedSubtreeSpans = autoTraceLimit(
8932
+ options.maxCapturedSubtreeSpans,
8933
+ DEFAULT_AUTO_TRACE_MAX_CAPTURED_SUBTREE_SPANS
9009
8934
  );
9010
8935
  const rootIsAsync = fn.constructor.name === "AsyncFunction";
9011
8936
  const excluded = new Set(options.exclude ?? []);
@@ -9036,19 +8961,11 @@ var Bitfab = class {
9036
8961
  truncation.droppedSpans += 1;
9037
8962
  warnOnce(
9038
8963
  `auto-trace-truncated:${traceFunctionKey}`,
9039
- `"${traceFunctionKey}" hit an automatic subtree capture limit (maxDepth=${maxDepth}, maxCapturedSubtreeSpans=${maxCapturedSubtreeSpans}, maxSpans=${maxSpans}); its trace is incomplete. Raise the limits, declare the calls you need with node(), or narrow the subtree with exclude.`
8964
+ `"${traceFunctionKey}" hit an automatic subtree capture limit (maxDepth=${maxDepth}, maxCapturedSubtreeSpans=${maxCapturedSubtreeSpans}); its trace is incomplete. Raise the limits, declare the calls you need with node(), or narrow the subtree with exclude.`
9040
8965
  );
9041
8966
  };
9042
- const spanBudget = {
9043
- spansUsed: 1,
9044
- maxSpans,
9045
- truncate
9046
- };
9047
8967
  if (rootTraceState !== void 0) {
9048
8968
  rootTraceState.truncation = truncation;
9049
- if (rootTraceState.spanBudget === void 0) {
9050
- rootTraceState.spanBudget = spanBudget;
9051
- }
9052
8969
  }
9053
8970
  const spanStackOf = (entry) => entry.spanStack;
9054
8971
  const openChild = (entry, childOptions, inputs, isAsync, invokeFn) => {
@@ -9084,16 +9001,16 @@ var Bitfab = class {
9084
9001
  return innermost === void 0 ? traceFunctionKey : rootTraceFunctionKeyOfTrace(innermost.traceId, traceFunctionKey);
9085
9002
  };
9086
9003
  const recordsSpan = (entry, spanName, declared) => {
9087
- const countsTowardCapturedSubtree = !declared && !self.simulationPlan.contentOffNow(
9004
+ const contentOff = !declared && self.simulationPlan.contentOffNow(
9088
9005
  rootTraceFunctionKeyOfEntry(entry),
9089
9006
  spanName
9090
9007
  );
9091
- const refusedBy = entry.depth >= maxDepth ? "max_depth" : spanBudget.spansUsed >= maxSpans ? "max_spans" : countsTowardCapturedSubtree && capturedSubtreeCount >= maxCapturedSubtreeSpans ? "max_captured_subtree_spans" : void 0;
9008
+ const countsTowardCapturedSubtree = !declared && !contentOff;
9009
+ const refusedBy = entry.depth >= maxDepth ? "max_depth" : countsTowardCapturedSubtree && capturedSubtreeCount >= maxCapturedSubtreeSpans ? "max_captured_subtree_spans" : void 0;
9092
9010
  if (refusedBy !== void 0) {
9093
9011
  truncate(refusedBy);
9094
9012
  return false;
9095
9013
  }
9096
- spanBudget.spansUsed += 1;
9097
9014
  if (countsTowardCapturedSubtree) {
9098
9015
  capturedSubtreeCount += 1;
9099
9016
  }
@@ -9112,7 +9029,8 @@ var Bitfab = class {
9112
9029
  return clearAutoTraceNodeConfiguration(invokeFn);
9113
9030
  }
9114
9031
  const spanName = nodeConfiguration?.name ?? definition.name;
9115
- if (!recordsSpan(entry, spanName, nodeConfiguration !== void 0)) {
9032
+ const declaredNode = nodeConfiguration !== void 0;
9033
+ if (!recordsSpan(entry, spanName, declaredNode)) {
9116
9034
  return invokeWithoutNode();
9117
9035
  }
9118
9036
  const mockOnReplay = nodeConfiguration?.mockOnReplay ?? options.mockOnReplayDefault;
@@ -9125,6 +9043,7 @@ var Bitfab = class {
9125
9043
  functionId: definition.id,
9126
9044
  captureContent: true,
9127
9045
  autoTraceDefinition: definition,
9046
+ ...declaredNode && { declaredNode },
9128
9047
  ...nodeConfiguration?.testRunId !== void 0 && {
9129
9048
  testRunId: nodeConfiguration.testRunId
9130
9049
  },
@@ -9154,6 +9073,7 @@ var Bitfab = class {
9154
9073
  surface: "opt-out",
9155
9074
  instrumentation: "trace",
9156
9075
  captureContent: true,
9076
+ declaredNode: true,
9157
9077
  ...link !== void 0 && { nestedTrace: link }
9158
9078
  };
9159
9079
  return openChild(entry, childOptions, inputs, false, invokeFn);
@@ -9225,10 +9145,6 @@ var Bitfab = class {
9225
9145
  return autoTraceRoot;
9226
9146
  }
9227
9147
  applySimulationPlan(payload, submit, drop) {
9228
- if (isRefusedFrameworkSpan(payload)) {
9229
- drop();
9230
- return;
9231
- }
9232
9148
  this.simulationPlan.send(
9233
9149
  payload,
9234
9150
  rootTraceFunctionKeyOf(payload),
@@ -9903,9 +9819,6 @@ var Bitfab = class {
9903
9819
  registeredTraceId = traceId;
9904
9820
  }
9905
9821
  self.httpClient.traceCompletion.start(traceId, spanId);
9906
- if (isFrameworkInstrumentation(options.instrumentation)) {
9907
- reserveFrameworkSpan(traceId, spanId, parentSpanId);
9908
- }
9909
9822
  startedSpan = { traceId, spanId };
9910
9823
  const functionName = fn.name !== "" ? fn.name : void 0;
9911
9824
  const rootTraceFunctionKey = rootTraceFunctionKeyOfTrace(
@@ -9927,6 +9840,7 @@ var Bitfab = class {
9927
9840
  functionId: options.functionId,
9928
9841
  captureContent: options.captureContent ?? true,
9929
9842
  autoTraceDefinition: options.autoTraceDefinition,
9843
+ declaredNode: options.declaredNode === true,
9930
9844
  nestedTrace: options.nestedTrace,
9931
9845
  enclosingTrace: options.enclosingTrace
9932
9846
  };
@@ -10452,7 +10366,7 @@ var Bitfab = class {
10452
10366
  * Queued on the client's span transport; delivery is the transport's job.
10453
10367
  */
10454
10368
  sendWrapperSpan(params) {
10455
- const contentOff = this.contentOffBySimulationPlan(params);
10369
+ const contentOff = params.declaredNode !== true && this.contentOffBySimulationPlan(params);
10456
10370
  const buildsContent = params.captureContent && !contentOff;
10457
10371
  const serializedInputs = buildsContent ? serializeValue(params.inputs) : void 0;
10458
10372
  const serializedResult = buildsContent ? serializeValue(params.result) : void 0;
@@ -10526,6 +10440,7 @@ var Bitfab = class {
10526
10440
  ...params.rootTraceFunctionKey !== void 0 && {
10527
10441
  [ROOT_TRACE_FUNCTION_KEY_FIELD]: params.rootTraceFunctionKey
10528
10442
  },
10443
+ ...params.declaredNode === true && { [DECLARED_NODE_FIELD]: true },
10529
10444
  rawSpan: externalSpan,
10530
10445
  ...params.testRunId && { testRunId: params.testRunId },
10531
10446
  ...params.mocked && { mocked: true },