bitfab 0.58.3 → 0.58.5

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.
Files changed (40) hide show
  1. package/dist/autoTrace.cjs +50 -4
  2. package/dist/autoTrace.cjs.map +1 -1
  3. package/dist/autoTrace.d.cts +2 -1
  4. package/dist/autoTrace.d.ts +2 -1
  5. package/dist/autoTrace.js +4 -2
  6. package/dist/{chunk-EIWNY3FF.js → chunk-7SPNHC33.js} +6 -21
  7. package/dist/chunk-7SPNHC33.js.map +1 -0
  8. package/dist/{chunk-VCRFFCLY.js → chunk-BAOIRE5T.js} +20 -2
  9. package/dist/chunk-BAOIRE5T.js.map +1 -0
  10. package/dist/{chunk-RCHSYWKI.js → chunk-ETZUSSF6.js} +38 -8
  11. package/dist/chunk-ETZUSSF6.js.map +1 -0
  12. package/dist/{chunk-HNUEEGIB.js → chunk-OTQA6MCF.js} +3 -3
  13. package/dist/{chunk-YWWDW5FX.js → chunk-QIBFNIIF.js} +2 -2
  14. package/dist/{chunk-YWWDW5FX.js.map → chunk-QIBFNIIF.js.map} +1 -1
  15. package/dist/{chunk-HJLWJ3L2.js → chunk-TAEWAXPA.js} +6 -6
  16. package/dist/{chunk-34VY4J27.js → chunk-UYAQRSCB.js} +43 -18
  17. package/dist/chunk-UYAQRSCB.js.map +1 -0
  18. package/dist/{http-XH36DD6T.js → http-F6QV3YLY.js} +3 -3
  19. package/dist/{http-Q75A3OKB.js → http-XDKEIZNV.js} +2 -2
  20. package/dist/index.cjs +58 -12
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +3 -1
  23. package/dist/index.d.ts +3 -1
  24. package/dist/index.js +5 -5
  25. package/dist/node.cjs +58 -12
  26. package/dist/node.cjs.map +1 -1
  27. package/dist/node.js +5 -5
  28. package/dist/{replay-QN6M3Q6H.js → replay-WLJFWS6T.js} +4 -4
  29. package/dist/replayCli.js +2 -2
  30. package/dist/seedCli.js +2 -2
  31. package/package.json +1 -1
  32. package/dist/chunk-34VY4J27.js.map +0 -1
  33. package/dist/chunk-EIWNY3FF.js.map +0 -1
  34. package/dist/chunk-RCHSYWKI.js.map +0 -1
  35. package/dist/chunk-VCRFFCLY.js.map +0 -1
  36. /package/dist/{chunk-HNUEEGIB.js.map → chunk-OTQA6MCF.js.map} +0 -0
  37. /package/dist/{chunk-HJLWJ3L2.js.map → chunk-TAEWAXPA.js.map} +0 -0
  38. /package/dist/{http-Q75A3OKB.js.map → http-F6QV3YLY.js.map} +0 -0
  39. /package/dist/{http-XH36DD6T.js.map → http-XDKEIZNV.js.map} +0 -0
  40. /package/dist/{replay-QN6M3Q6H.js.map → replay-WLJFWS6T.js.map} +0 -0
@@ -6,8 +6,8 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-EIWNY3FF.js";
10
- import "./chunk-VCRFFCLY.js";
9
+ } from "./chunk-7SPNHC33.js";
10
+ import "./chunk-BAOIRE5T.js";
11
11
  export {
12
12
  BitfabError,
13
13
  HttpClient,
@@ -17,4 +17,4 @@ export {
17
17
  parseRetryAfterMs,
18
18
  serializePayloadBody
19
19
  };
20
- //# sourceMappingURL=http-XH36DD6T.js.map
20
+ //# sourceMappingURL=http-F6QV3YLY.js.map
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-YWWDW5FX.js";
9
+ } from "./chunk-QIBFNIIF.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-Q75A3OKB.js.map
19
+ //# sourceMappingURL=http-XDKEIZNV.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.58.3";
54
+ __version__ = "0.58.5";
55
55
  __packageName__ = "bitfab";
56
56
  }
57
57
  });
@@ -5106,6 +5106,7 @@ init_asyncStorage();
5106
5106
  // src/autoTrace.ts
5107
5107
  init_asyncStorage();
5108
5108
  init_captureSuppression();
5109
+ init_warnOnce();
5109
5110
  var autoTraceGlobal = globalThis;
5110
5111
  var autoTraceState = autoTraceGlobal.__bitfabAutoTraceStateV4 ?? {
5111
5112
  storage: null,
@@ -5173,6 +5174,26 @@ function runWithAutoTraceNodeConfiguration(nodeConfiguration, fn) {
5173
5174
  }
5174
5175
  return result;
5175
5176
  }
5177
+ var SUBTREE_TRACING_DOCS_URL = "https://docs.bitfab.ai/typescript-sdk#experimental-subtree-tracing";
5178
+ function transformInstalled() {
5179
+ return autoTraceGlobal.__bitfab_auto_trace_transformed_v1__ === true;
5180
+ }
5181
+ function runsOnNode() {
5182
+ return typeof process !== "undefined" && Boolean(process.versions?.node);
5183
+ }
5184
+ function closeAutoTraceRoot() {
5185
+ autoTraceState.activeRoots -= 1;
5186
+ }
5187
+ function settleAutoTraceRoot(context) {
5188
+ closeAutoTraceRoot();
5189
+ if (transformInstalled() || !runsOnNode()) {
5190
+ return;
5191
+ }
5192
+ warnOnce(
5193
+ "auto-trace-transform-missing",
5194
+ `trace root "${context.traceFunctionKey}" recorded only its own span. No module in this build was compiled by @bitfab/transform, so calls beneath the root were not discovered. Install @bitfab/transform and add its adapter to the server build: ${SUBTREE_TRACING_DOCS_URL}`
5195
+ );
5196
+ }
5176
5197
  function runWithAutoTraceRootContext(context, spanStack, fn) {
5177
5198
  autoTraceState.activeRoots += 1;
5178
5199
  const entries = [
@@ -5183,19 +5204,19 @@ function runWithAutoTraceRootContext(context, spanStack, fn) {
5183
5204
  try {
5184
5205
  result = runWithAutoTraceScope({ entries }, fn);
5185
5206
  } catch (error) {
5186
- autoTraceState.activeRoots -= 1;
5207
+ settleAutoTraceRoot(context);
5187
5208
  throw error;
5188
5209
  }
5189
5210
  if (isAutoTraceAsyncGenerator(result)) {
5190
- autoTraceState.activeRoots -= 1;
5211
+ closeAutoTraceRoot();
5191
5212
  return wrapAutoTraceAsyncGenerator(context, spanStack, result);
5192
5213
  }
5193
5214
  if (result instanceof Promise) {
5194
5215
  return result.finally(() => {
5195
- autoTraceState.activeRoots -= 1;
5216
+ settleAutoTraceRoot(context);
5196
5217
  });
5197
5218
  }
5198
- autoTraceState.activeRoots -= 1;
5219
+ settleAutoTraceRoot(context);
5199
5220
  return result;
5200
5221
  }
5201
5222
  function invokeThroughAutoTraceEntries(entries, step, fn) {
@@ -9818,13 +9839,23 @@ var Bitfab = class {
9818
9839
  traceFunctionKey
9819
9840
  );
9820
9841
  const openAiAgentsSpanIds = openAiAgentsSpanChain();
9842
+ const functionNameAtOpen = fn.name !== "" ? fn.name : void 0;
9821
9843
  const newContext = {
9822
9844
  traceId,
9823
9845
  spanId,
9824
9846
  contexts: [],
9847
+ spanName: options.name ?? options.nameFor?.(this) ?? qualifiedSpanName(this, functionNameAtOpen) ?? traceFunctionKey,
9848
+ rootTraceFunctionKey: rootTraceFunctionKeyOfTrace(
9849
+ traceId,
9850
+ traceFunctionKey
9851
+ ),
9852
+ instrumentation: options.instrumentation ?? "span",
9853
+ declaredNode: options.declaredNode === true,
9854
+ isRoot: isRootSpan,
9825
9855
  ...surface !== void 0 && { surface },
9826
9856
  ...openAiAgentsSpanIds.length > 0 && { openAiAgentsSpanIds }
9827
9857
  };
9858
+ const nearestCapturedAncestorSpanId = self.nearestCapturedAncestorSpanIdOf(currentStack);
9828
9859
  newStack = [...currentStack, newContext];
9829
9860
  const inputs = args;
9830
9861
  const startedAt = nowIsoTimestamp();
@@ -9851,19 +9882,16 @@ var Bitfab = class {
9851
9882
  }
9852
9883
  self.httpClient.traceCompletion.start(traceId, spanId);
9853
9884
  startedSpan = { traceId, spanId };
9854
- const functionName = fn.name !== "" ? fn.name : void 0;
9855
- const rootTraceFunctionKey = rootTraceFunctionKeyOfTrace(
9856
- traceId,
9857
- traceFunctionKey
9858
- );
9885
+ const functionName = functionNameAtOpen;
9859
9886
  const baseSpanParams = {
9860
9887
  traceFunctionKey,
9861
- rootTraceFunctionKey,
9888
+ rootTraceFunctionKey: newContext.rootTraceFunctionKey,
9862
9889
  functionName,
9863
- spanName: options.name ?? options.nameFor?.(this) ?? qualifiedSpanName(this, functionName) ?? traceFunctionKey,
9890
+ spanName: newContext.spanName,
9864
9891
  traceId,
9865
9892
  spanId,
9866
9893
  parentSpanId,
9894
+ nearestCapturedAncestorSpanId,
9867
9895
  inputs,
9868
9896
  startedAt,
9869
9897
  spanType: options.type ?? "custom",
@@ -10382,6 +10410,21 @@ var Bitfab = class {
10382
10410
  ...params.testRunId && { testRunId: params.testRunId }
10383
10411
  });
10384
10412
  }
10413
+ sendsSpanOnCompletion(context) {
10414
+ return context.isRoot || context.declaredNode || isFrameworkInstrumentation(context.instrumentation) || !this.simulationPlan.contentOffNow(
10415
+ context.rootTraceFunctionKey,
10416
+ context.spanName
10417
+ );
10418
+ }
10419
+ nearestCapturedAncestorSpanIdOf(stack) {
10420
+ for (let index = stack.length - 1; index >= 0; index -= 1) {
10421
+ const candidate = stack[index];
10422
+ if (candidate !== void 0 && this.sendsSpanOnCompletion(candidate)) {
10423
+ return candidate.spanId;
10424
+ }
10425
+ }
10426
+ return null;
10427
+ }
10385
10428
  contentOffBySimulationPlan(params) {
10386
10429
  if (params.rootTraceFunctionKey === void 0 || isFrameworkInstrumentation(params.instrumentation)) {
10387
10430
  return false;
@@ -10458,6 +10501,9 @@ var Bitfab = class {
10458
10501
  if (params.parentSpanId) {
10459
10502
  externalSpan.parent_id = params.parentSpanId;
10460
10503
  }
10504
+ if (params.nearestCapturedAncestorSpanId !== void 0 && params.nearestCapturedAncestorSpanId !== null && params.nearestCapturedAncestorSpanId !== params.parentSpanId) {
10505
+ externalSpan.nearest_captured_ancestor_id = params.nearestCapturedAncestorSpanId;
10506
+ }
10461
10507
  if (params.inputSourceSpanId) {
10462
10508
  externalSpan.input_source_span_id = params.inputSourceSpanId;
10463
10509
  }