bitfab 0.58.3 → 0.58.4

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.
@@ -17,7 +17,7 @@ import {
17
17
  serializeValue,
18
18
  toJsonSafe,
19
19
  toJsonSafeReport
20
- } from "./chunk-HJLWJ3L2.js";
20
+ } from "./chunk-NSD5YKCE.js";
21
21
  import {
22
22
  BitfabError,
23
23
  CONTENT_OFF_KEY,
@@ -36,7 +36,7 @@ import {
36
36
  recordCallerTraceMetadata,
37
37
  retireTraceMetadata,
38
38
  warnOnce
39
- } from "./chunk-EIWNY3FF.js";
39
+ } from "./chunk-KADON3SF.js";
40
40
  import {
41
41
  __privateAdd,
42
42
  __privateGet,
@@ -5217,13 +5217,23 @@ var Bitfab = class {
5217
5217
  traceFunctionKey
5218
5218
  );
5219
5219
  const openAiAgentsSpanIds = openAiAgentsSpanChain();
5220
+ const functionNameAtOpen = fn.name !== "" ? fn.name : void 0;
5220
5221
  const newContext = {
5221
5222
  traceId,
5222
5223
  spanId,
5223
5224
  contexts: [],
5225
+ spanName: options.name ?? options.nameFor?.(this) ?? qualifiedSpanName(this, functionNameAtOpen) ?? traceFunctionKey,
5226
+ rootTraceFunctionKey: rootTraceFunctionKeyOfTrace(
5227
+ traceId,
5228
+ traceFunctionKey
5229
+ ),
5230
+ instrumentation: options.instrumentation ?? "span",
5231
+ declaredNode: options.declaredNode === true,
5232
+ isRoot: isRootSpan,
5224
5233
  ...surface !== void 0 && { surface },
5225
5234
  ...openAiAgentsSpanIds.length > 0 && { openAiAgentsSpanIds }
5226
5235
  };
5236
+ const nearestCapturedAncestorSpanId = self.nearestCapturedAncestorSpanIdOf(currentStack);
5227
5237
  newStack = [...currentStack, newContext];
5228
5238
  const inputs = args;
5229
5239
  const startedAt = nowIsoTimestamp();
@@ -5250,19 +5260,16 @@ var Bitfab = class {
5250
5260
  }
5251
5261
  self.httpClient.traceCompletion.start(traceId, spanId);
5252
5262
  startedSpan = { traceId, spanId };
5253
- const functionName = fn.name !== "" ? fn.name : void 0;
5254
- const rootTraceFunctionKey = rootTraceFunctionKeyOfTrace(
5255
- traceId,
5256
- traceFunctionKey
5257
- );
5263
+ const functionName = functionNameAtOpen;
5258
5264
  const baseSpanParams = {
5259
5265
  traceFunctionKey,
5260
- rootTraceFunctionKey,
5266
+ rootTraceFunctionKey: newContext.rootTraceFunctionKey,
5261
5267
  functionName,
5262
- spanName: options.name ?? options.nameFor?.(this) ?? qualifiedSpanName(this, functionName) ?? traceFunctionKey,
5268
+ spanName: newContext.spanName,
5263
5269
  traceId,
5264
5270
  spanId,
5265
5271
  parentSpanId,
5272
+ nearestCapturedAncestorSpanId,
5266
5273
  inputs,
5267
5274
  startedAt,
5268
5275
  spanType: options.type ?? "custom",
@@ -5781,6 +5788,21 @@ var Bitfab = class {
5781
5788
  ...params.testRunId && { testRunId: params.testRunId }
5782
5789
  });
5783
5790
  }
5791
+ sendsSpanOnCompletion(context) {
5792
+ return context.isRoot || context.declaredNode || isFrameworkInstrumentation(context.instrumentation) || !this.simulationPlan.contentOffNow(
5793
+ context.rootTraceFunctionKey,
5794
+ context.spanName
5795
+ );
5796
+ }
5797
+ nearestCapturedAncestorSpanIdOf(stack) {
5798
+ for (let index = stack.length - 1; index >= 0; index -= 1) {
5799
+ const candidate = stack[index];
5800
+ if (candidate !== void 0 && this.sendsSpanOnCompletion(candidate)) {
5801
+ return candidate.spanId;
5802
+ }
5803
+ }
5804
+ return null;
5805
+ }
5784
5806
  contentOffBySimulationPlan(params) {
5785
5807
  if (params.rootTraceFunctionKey === void 0 || isFrameworkInstrumentation(params.instrumentation)) {
5786
5808
  return false;
@@ -5857,6 +5879,9 @@ var Bitfab = class {
5857
5879
  if (params.parentSpanId) {
5858
5880
  externalSpan.parent_id = params.parentSpanId;
5859
5881
  }
5882
+ if (params.nearestCapturedAncestorSpanId !== void 0 && params.nearestCapturedAncestorSpanId !== null && params.nearestCapturedAncestorSpanId !== params.parentSpanId) {
5883
+ externalSpan.nearest_captured_ancestor_id = params.nearestCapturedAncestorSpanId;
5884
+ }
5860
5885
  if (params.inputSourceSpanId) {
5861
5886
  externalSpan.input_source_span_id = params.inputSourceSpanId;
5862
5887
  }
@@ -6018,7 +6043,7 @@ var Bitfab = class {
6018
6043
  await runWithSeedContext({ traceId }, async () => target(...args));
6019
6044
  } finally {
6020
6045
  try {
6021
- const { flushTraces: flushTraces2 } = await import("./http-XH36DD6T.js");
6046
+ const { flushTraces: flushTraces2 } = await import("./http-TIOONTDB.js");
6022
6047
  await flushTraces2(3e4);
6023
6048
  } finally {
6024
6049
  unrecorded = activeTraceStates.delete(traceId);
@@ -6077,7 +6102,7 @@ var Bitfab = class {
6077
6102
  `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.`
6078
6103
  );
6079
6104
  }
6080
- const { replay: doReplay } = await import("./replay-QN6M3Q6H.js");
6105
+ const { replay: doReplay } = await import("./replay-CUHT4GUT.js");
6081
6106
  return doReplay(
6082
6107
  this.httpClient,
6083
6108
  this.serviceUrl,
@@ -6397,7 +6422,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
6397
6422
  sessionId: seedCase.sessionId
6398
6423
  })
6399
6424
  );
6400
- const { flushTraces: flushTraces2 } = await import("./http-XH36DD6T.js");
6425
+ const { flushTraces: flushTraces2 } = await import("./http-TIOONTDB.js");
6401
6426
  await flushTraces2(3e4);
6402
6427
  return { pipeline, traceFunctionKey, traceIds };
6403
6428
  }
@@ -6437,4 +6462,4 @@ export {
6437
6462
  reseedFromRegistry,
6438
6463
  seedFromRegistry
6439
6464
  };
6440
- //# sourceMappingURL=chunk-34VY4J27.js.map
6465
+ //# sourceMappingURL=chunk-IVF7JQHF.js.map