@bitfab/sdk 0.52.5 → 0.52.6

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 (36) hide show
  1. package/dist/autoTrace.cjs +84 -34
  2. package/dist/autoTrace.cjs.map +1 -1
  3. package/dist/autoTrace.d.cts +19 -4
  4. package/dist/autoTrace.d.ts +19 -4
  5. package/dist/autoTrace.js +9 -3
  6. package/dist/{chunk-BEAGKWXY.js → chunk-3TL4SATS.js} +136 -31
  7. package/dist/chunk-3TL4SATS.js.map +1 -0
  8. package/dist/{chunk-IHAB7SPF.js → chunk-7KIRLN47.js} +2 -2
  9. package/dist/{chunk-IHAB7SPF.js.map → chunk-7KIRLN47.js.map} +1 -1
  10. package/dist/{chunk-ITIMJ24H.js → chunk-A6KY2IFA.js} +3 -3
  11. package/dist/{chunk-ZUD7OFYB.js → chunk-E5BLYL5X.js} +81 -34
  12. package/dist/chunk-E5BLYL5X.js.map +1 -0
  13. package/dist/{chunk-VAIXHJ7O.js → chunk-RC6XLP6M.js} +2 -2
  14. package/dist/{chunk-VAIXHJ7O.js.map → chunk-RC6XLP6M.js.map} +1 -1
  15. package/dist/{chunk-THKLMOHS.js → chunk-WYC4QRK3.js} +2 -2
  16. package/dist/{http-KZU56HZA.js → http-EL26HG5B.js} +2 -2
  17. package/dist/{http-6Y3IQQ2Z.js → http-YMBQ4XJO.js} +2 -2
  18. package/dist/index.cjs +182 -48
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.js +4 -4
  23. package/dist/node.cjs +182 -48
  24. package/dist/node.cjs.map +1 -1
  25. package/dist/node.js +4 -4
  26. package/dist/{replay-LZ7DIY5L.js → replay-DXDWFFJK.js} +3 -3
  27. package/dist/replayCli.js +2 -2
  28. package/dist/seedCli.js +2 -2
  29. package/package.json +1 -1
  30. package/dist/chunk-BEAGKWXY.js.map +0 -1
  31. package/dist/chunk-ZUD7OFYB.js.map +0 -1
  32. /package/dist/{chunk-ITIMJ24H.js.map → chunk-A6KY2IFA.js.map} +0 -0
  33. /package/dist/{chunk-THKLMOHS.js.map → chunk-WYC4QRK3.js.map} +0 -0
  34. /package/dist/{http-6Y3IQQ2Z.js.map → http-EL26HG5B.js.map} +0 -0
  35. /package/dist/{http-KZU56HZA.js.map → http-YMBQ4XJO.js.map} +0 -0
  36. /package/dist/{replay-LZ7DIY5L.js.map → replay-DXDWFFJK.js.map} +0 -0
@@ -5,7 +5,7 @@ import {
5
5
  replayContextReady,
6
6
  runWithReplayContext,
7
7
  warnOnce
8
- } from "./chunk-IHAB7SPF.js";
8
+ } from "./chunk-7KIRLN47.js";
9
9
 
10
10
  // src/gitCommand.ts
11
11
  var EXIT_GRACE_MS = 500;
@@ -1303,4 +1303,4 @@ export {
1303
1303
  sleepForReplayPersistence,
1304
1304
  replay
1305
1305
  };
1306
- //# sourceMappingURL=chunk-THKLMOHS.js.map
1306
+ //# sourceMappingURL=chunk-WYC4QRK3.js.map
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-IHAB7SPF.js";
9
+ } from "./chunk-7KIRLN47.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-KZU56HZA.js.map
20
+ //# sourceMappingURL=http-EL26HG5B.js.map
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-VAIXHJ7O.js";
9
+ } from "./chunk-RC6XLP6M.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-6Y3IQQ2Z.js.map
19
+ //# sourceMappingURL=http-YMBQ4XJO.js.map
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.52.5";
45
+ __version__ = "0.52.6";
46
46
  __packageName__ = "@bitfab/sdk";
47
47
  }
48
48
  });
@@ -4198,19 +4198,18 @@ init_asyncStorage();
4198
4198
  // src/autoTrace.ts
4199
4199
  init_asyncStorage();
4200
4200
  var autoTraceGlobal = globalThis;
4201
- var autoTraceState = autoTraceGlobal.__bitfabAutoTraceStateV3 ?? {
4201
+ var autoTraceState = autoTraceGlobal.__bitfabAutoTraceStateV4 ?? {
4202
4202
  storage: null,
4203
4203
  browserScope: void 0,
4204
4204
  capturePolicies: /* @__PURE__ */ new WeakMap(),
4205
4205
  activeRoots: 0
4206
4206
  };
4207
- autoTraceGlobal.__bitfabAutoTraceStateV3 = autoTraceState;
4207
+ autoTraceGlobal.__bitfabAutoTraceStateV4 = autoTraceState;
4208
4208
  function initializeAutoTraceStorage() {
4209
4209
  autoTraceState.storage ?? (autoTraceState.storage = createAsyncLocalStorage());
4210
4210
  }
4211
- function runWithAutoTraceContext(context, fn, depth = 0) {
4211
+ function runWithAutoTraceScope(scope, fn) {
4212
4212
  initializeAutoTraceStorage();
4213
- const scope = { context, depth };
4214
4213
  if (autoTraceState.storage) {
4215
4214
  return autoTraceState.storage.run(scope, fn);
4216
4215
  }
@@ -4222,41 +4221,65 @@ function runWithAutoTraceContext(context, fn, depth = 0) {
4222
4221
  autoTraceState.browserScope = previous;
4223
4222
  }
4224
4223
  }
4224
+ function currentAutoTraceEntries() {
4225
+ return currentAutoTraceScope()?.entries ?? [];
4226
+ }
4227
+ function replaceEntry(entries, previous, updated) {
4228
+ return entries.map((entry) => entry === previous ? updated : entry);
4229
+ }
4230
+ function runWithAutoTraceEntry(previous, updated, fn) {
4231
+ const result = runWithAutoTraceScope(
4232
+ { entries: replaceEntry(currentAutoTraceEntries(), previous, updated) },
4233
+ fn
4234
+ );
4235
+ if (isAutoTraceAsyncGenerator(result)) {
4236
+ return wrapAutoTraceEntryAsyncGenerator(previous, updated, result);
4237
+ }
4238
+ return result;
4239
+ }
4240
+ function wrapAutoTraceEntryAsyncGenerator(previous, updated, source) {
4241
+ const step = (method, value) => runWithAutoTraceScope(
4242
+ { entries: replaceEntry(currentAutoTraceEntries(), previous, updated) },
4243
+ () => source[method](value)
4244
+ );
4245
+ const wrapped = {
4246
+ next: (value) => step("next", value),
4247
+ return: (value) => step("return", value),
4248
+ throw: (error) => step("throw", error),
4249
+ [Symbol.asyncIterator]: () => wrapped
4250
+ };
4251
+ return wrapped;
4252
+ }
4253
+ function clearAutoTraceNodeConfiguration(fn) {
4254
+ return runWithAutoTraceScope({ entries: currentAutoTraceEntries() }, fn);
4255
+ }
4225
4256
  function runWithAutoTraceNodeConfiguration(nodeConfiguration, fn) {
4226
4257
  const scope = currentAutoTraceScope();
4227
- if (!scope) {
4258
+ if (!scope || scope.entries.length === 0) {
4228
4259
  return fn();
4229
4260
  }
4230
- const configuredScope = { ...scope, nodeConfiguration };
4231
- let result;
4232
- if (autoTraceState.storage) {
4233
- result = autoTraceState.storage.run(configuredScope, fn);
4234
- } else {
4235
- const previous = autoTraceState.browserScope;
4236
- autoTraceState.browserScope = configuredScope;
4237
- try {
4238
- result = fn();
4239
- } finally {
4240
- autoTraceState.browserScope = previous;
4241
- }
4242
- }
4261
+ const result = runWithAutoTraceScope({ ...scope, nodeConfiguration }, fn);
4243
4262
  if (isAutoTraceAsyncGenerator(result)) {
4244
4263
  return wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, result);
4245
4264
  }
4246
4265
  return result;
4247
4266
  }
4248
- function runWithAutoTraceRootContext(context, fn) {
4267
+ function runWithAutoTraceRootContext(context, spanStack, fn) {
4249
4268
  autoTraceState.activeRoots += 1;
4269
+ const entries = [
4270
+ ...currentAutoTraceEntries(),
4271
+ { context, depth: 0, spanStack }
4272
+ ];
4250
4273
  let result;
4251
4274
  try {
4252
- result = runWithAutoTraceContext(context, fn);
4275
+ result = runWithAutoTraceScope({ entries }, fn);
4253
4276
  } catch (error) {
4254
4277
  autoTraceState.activeRoots -= 1;
4255
4278
  throw error;
4256
4279
  }
4257
4280
  if (isAutoTraceAsyncGenerator(result)) {
4258
4281
  autoTraceState.activeRoots -= 1;
4259
- return wrapAutoTraceAsyncGenerator(context, result);
4282
+ return wrapAutoTraceAsyncGenerator(context, spanStack, result);
4260
4283
  }
4261
4284
  if (result instanceof Promise) {
4262
4285
  return result.finally(() => {
@@ -4266,6 +4289,15 @@ function runWithAutoTraceRootContext(context, fn) {
4266
4289
  autoTraceState.activeRoots -= 1;
4267
4290
  return result;
4268
4291
  }
4292
+ function invokeThroughAutoTraceEntries(entries, step, fn) {
4293
+ let run = fn;
4294
+ for (let index = entries.length - 1; index >= 0; index -= 1) {
4295
+ const entry = entries[index];
4296
+ const next = run;
4297
+ run = () => step(entry, next);
4298
+ }
4299
+ return run();
4300
+ }
4269
4301
  function isAutoTraceAsyncGenerator(value) {
4270
4302
  if (value === null || typeof value !== "object") {
4271
4303
  return false;
@@ -4273,8 +4305,8 @@ function isAutoTraceAsyncGenerator(value) {
4273
4305
  const candidate = value;
4274
4306
  return typeof candidate.next === "function" && typeof candidate.return === "function" && typeof candidate.throw === "function" && typeof candidate[Symbol.asyncIterator] === "function";
4275
4307
  }
4276
- function wrapAutoTraceAsyncGenerator(context, source) {
4277
- const step = (method, value) => runWithAutoTraceRootContext(context, () => source[method](value));
4308
+ function wrapAutoTraceAsyncGenerator(context, spanStack, source) {
4309
+ const step = (method, value) => runWithAutoTraceRootContext(context, spanStack, () => source[method](value));
4278
4310
  const wrapped = {
4279
4311
  next: (value) => step("next", value),
4280
4312
  return: (value) => step("return", value),
@@ -4300,7 +4332,7 @@ function __bitfabAutoTraceActive() {
4300
4332
  if (autoTraceState.activeRoots === 0) {
4301
4333
  return false;
4302
4334
  }
4303
- return currentAutoTraceScope() !== void 0;
4335
+ return currentAutoTraceEntries().length > 0;
4304
4336
  }
4305
4337
  function currentAutoTraceScope() {
4306
4338
  initializeAutoTraceStorage();
@@ -7053,11 +7085,15 @@ var Bitfab = class {
7053
7085
  type: options.type ?? "custom",
7054
7086
  surface: "opt-out"
7055
7087
  };
7056
- const tracedRoot = this.withSpan(
7088
+ const rootName = options.name ?? name;
7089
+ const buildTracedRoot = (spanOptions) => this.withSpan(
7057
7090
  traceFunctionKey,
7058
- rootOptions,
7091
+ spanOptions,
7059
7092
  function(...args) {
7060
- const capturePolicy = getAutoTraceCapturePolicy(self, traceFunctionKey);
7093
+ const capturePolicy = getAutoTraceCapturePolicy(
7094
+ self,
7095
+ traceFunctionKey
7096
+ );
7061
7097
  self.refreshAutoTraceCapturePolicy(traceFunctionKey);
7062
7098
  let spansUsed = 0;
7063
7099
  let truncated = false;
@@ -7078,19 +7114,54 @@ var Bitfab = class {
7078
7114
  `"${traceFunctionKey}" hit an automatic subtree capture limit (maxDepth=${maxDepth}, maxSpans=${maxSpans}); its trace is incomplete. Raise the limits or narrow the subtree with exclude.`
7079
7115
  );
7080
7116
  };
7117
+ const spanStackOf = (entry) => entry.spanStack;
7118
+ const openChild = (entry, childOptions, inputs, isAsync, invokeFn) => {
7119
+ const runInside = () => runWithAutoTraceEntry(
7120
+ entry,
7121
+ {
7122
+ context: autoTraceContext,
7123
+ depth: entry.depth + 1,
7124
+ spanStack: getSpanStack()
7125
+ },
7126
+ invokeFn
7127
+ );
7128
+ return runWithSpanStack(spanStackOf(entry), () => {
7129
+ if (isAsync) {
7130
+ const tracedAsyncChild = self.withSpan(
7131
+ traceFunctionKey,
7132
+ childOptions,
7133
+ async (..._inputs) => await runInside()
7134
+ );
7135
+ return tracedAsyncChild(...inputs);
7136
+ }
7137
+ const tracedChild = self.withSpan(
7138
+ traceFunctionKey,
7139
+ childOptions,
7140
+ (..._inputs) => runInside()
7141
+ );
7142
+ return tracedChild(...inputs);
7143
+ });
7144
+ };
7145
+ const overBudget = (entry) => {
7146
+ if (entry.depth < maxDepth && spansUsed < maxSpans) {
7147
+ return false;
7148
+ }
7149
+ runWithSpanStack(spanStackOf(entry), warnTruncated);
7150
+ return true;
7151
+ };
7081
7152
  const autoTraceContext = {
7082
- invoke(definition, inputs, invokeFn, depth, nodeConfiguration) {
7153
+ traceFunctionKey,
7154
+ invoke(definition, inputs, invokeFn, entry, nodeConfiguration) {
7083
7155
  const nameParts = definition.name.split(".");
7084
7156
  const simpleName = nameParts[nameParts.length - 1];
7085
- const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
7157
+ const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : clearAutoTraceNodeConfiguration(invokeFn);
7086
7158
  if (excluded.has(definition.name) || simpleName !== void 0 && excluded.has(simpleName) || nodeConfiguration === void 0 && definition.wrapper === true && !includeWrappers) {
7087
7159
  return invokeWithoutNode();
7088
7160
  }
7089
7161
  if (nodeConfiguration?.capture === false) {
7090
- return runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
7162
+ return clearAutoTraceNodeConfiguration(invokeFn);
7091
7163
  }
7092
- if (depth >= maxDepth || spansUsed >= maxSpans) {
7093
- warnTruncated();
7164
+ if (overBudget(entry)) {
7094
7165
  return invokeWithoutNode();
7095
7166
  }
7096
7167
  spansUsed += 1;
@@ -7113,34 +7184,81 @@ var Bitfab = class {
7113
7184
  finalize: nodeConfiguration.finalize
7114
7185
  }
7115
7186
  };
7116
- const invokeWithAutoTraceContext = () => runWithAutoTraceContext(autoTraceContext, invokeFn, depth + 1);
7117
- if (definition.async === true) {
7118
- const tracedAsyncChild = self.withSpan(
7119
- traceFunctionKey,
7120
- childOptions,
7121
- async (..._inputs) => await invokeWithAutoTraceContext()
7122
- );
7123
- return tracedAsyncChild(...inputs);
7124
- }
7125
- const tracedChild = self.withSpan(
7126
- traceFunctionKey,
7187
+ return openChild(
7188
+ entry,
7127
7189
  childOptions,
7128
- (..._inputs) => invokeWithAutoTraceContext()
7190
+ inputs,
7191
+ definition.async === true,
7192
+ invokeFn
7129
7193
  );
7130
- return tracedChild(...inputs);
7194
+ },
7195
+ invokeNestedRoot(nestedName, nestedFunctionName, inputs, invokeFn, entry, link) {
7196
+ if (excluded.has(nestedName) || excluded.has(nestedFunctionName) || overBudget(entry)) {
7197
+ return invokeFn();
7198
+ }
7199
+ spansUsed += 1;
7200
+ const childOptions = {
7201
+ name: nestedName,
7202
+ type: "function",
7203
+ captureWhen: "nested",
7204
+ surface: "opt-out",
7205
+ captureContent: true,
7206
+ ...link !== void 0 && { nestedTrace: link }
7207
+ };
7208
+ return openChild(entry, childOptions, inputs, false, invokeFn);
7131
7209
  }
7132
7210
  };
7133
7211
  return runWithAutoTraceRootContext(
7134
7212
  autoTraceContext,
7213
+ getSpanStack(),
7135
7214
  () => fn.apply(this, args)
7136
7215
  );
7137
7216
  }
7138
7217
  );
7218
+ const tracedRoot = buildTracedRoot(rootOptions);
7139
7219
  const autoTraceRoot = function(...args) {
7140
7220
  if (!self.shouldRecord()) {
7141
7221
  return fn.apply(this, args);
7142
7222
  }
7143
- return tracedRoot.apply(this, args);
7223
+ const enclosing = currentAutoTraceEntries();
7224
+ if (enclosing.length === 0) {
7225
+ return tracedRoot.apply(this, args);
7226
+ }
7227
+ const link = getReplayContext() || inSeedScope() ? void 0 : { traceFunctionKey };
7228
+ return invokeThroughAutoTraceEntries(
7229
+ enclosing,
7230
+ (entry, next) => entry.context.invokeNestedRoot(
7231
+ rootName,
7232
+ name,
7233
+ args,
7234
+ next,
7235
+ entry,
7236
+ link
7237
+ ),
7238
+ () => {
7239
+ if (link === void 0) {
7240
+ return fn.apply(this, args);
7241
+ }
7242
+ const innermost = enclosing[enclosing.length - 1];
7243
+ const innermostNow = currentAutoTraceEntries().find(
7244
+ (entry) => entry.context === innermost.context
7245
+ ) ?? innermost;
7246
+ const innermostStack = innermostNow.spanStack;
7247
+ const copy = innermostStack[innermostStack.length - 1];
7248
+ const detachedRoot = buildTracedRoot({
7249
+ ...rootOptions,
7250
+ ...copy !== void 0 && {
7251
+ enclosingTrace: {
7252
+ traceId: copy.traceId,
7253
+ spanId: copy.spanId,
7254
+ traceFunctionKey: innermost.context.traceFunctionKey,
7255
+ link
7256
+ }
7257
+ }
7258
+ });
7259
+ return runWithSpanStack([], () => detachedRoot.apply(this, args));
7260
+ }
7261
+ );
7144
7262
  };
7145
7263
  Object.defineProperty(autoTraceRoot, "_bitfabTraceFunctionKey", {
7146
7264
  value: traceFunctionKey
@@ -7729,6 +7847,10 @@ var Bitfab = class {
7729
7847
  const spanId = randomUuid();
7730
7848
  const parentSpanId = parentContext?.spanId ?? null;
7731
7849
  const isRootSpan = parentSpanId === null;
7850
+ if (options.enclosingTrace !== void 0) {
7851
+ options.enclosingTrace.link.traceId = traceId;
7852
+ options.enclosingTrace.link.rootSpanId = spanId;
7853
+ }
7732
7854
  const requestedSurface = options.surface ?? DEFAULT_SURFACE;
7733
7855
  const surface = resolveSurface(requestedSurface, parentContext?.surface);
7734
7856
  assertSurfacesCompatible(
@@ -7778,7 +7900,9 @@ var Bitfab = class {
7778
7900
  spanType: options.type ?? "custom",
7779
7901
  functionId: options.functionId,
7780
7902
  captureContent: options.captureContent ?? true,
7781
- autoTraceDefinition: options.autoTraceDefinition
7903
+ autoTraceDefinition: options.autoTraceDefinition,
7904
+ nestedTrace: options.nestedTrace,
7905
+ enclosingTrace: options.enclosingTrace
7782
7906
  };
7783
7907
  const sendSpan = async (params) => {
7784
7908
  const replayCtx = getReplayContext();
@@ -8288,6 +8412,16 @@ var Bitfab = class {
8288
8412
  function_line: params.autoTraceDefinition.line,
8289
8413
  function_column: params.autoTraceDefinition.column
8290
8414
  },
8415
+ ...params.nestedTrace?.traceId !== void 0 && {
8416
+ nested_trace_id: params.nestedTrace.traceId,
8417
+ nested_trace_function_key: params.nestedTrace.traceFunctionKey,
8418
+ nested_root_span_id: params.nestedTrace.rootSpanId
8419
+ },
8420
+ ...params.enclosingTrace !== void 0 && {
8421
+ enclosing_trace_id: params.enclosingTrace.traceId,
8422
+ enclosing_trace_function_key: params.enclosingTrace.traceFunctionKey,
8423
+ enclosing_span_id: params.enclosingTrace.spanId
8424
+ },
8291
8425
  ...serializedInputs !== void 0 && {
8292
8426
  input: serializedInputs.json,
8293
8427
  ...serializedInputs.meta !== void 0 && {