bitfab 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-3QXNM62Y.js → chunk-5KVK733P.js} +3 -3
  7. package/dist/{chunk-6DRFQJ75.js → chunk-DRTHTSHO.js} +2 -2
  8. package/dist/{chunk-ZUD7OFYB.js → chunk-E5BLYL5X.js} +81 -34
  9. package/dist/chunk-E5BLYL5X.js.map +1 -0
  10. package/dist/{chunk-3D7FNJ5R.js → chunk-GJKU7VWG.js} +2 -2
  11. package/dist/{chunk-3D7FNJ5R.js.map → chunk-GJKU7VWG.js.map} +1 -1
  12. package/dist/{chunk-CAE7HE4C.js → chunk-NXC6NYIY.js} +2 -2
  13. package/dist/{chunk-CAE7HE4C.js.map → chunk-NXC6NYIY.js.map} +1 -1
  14. package/dist/{chunk-EMRHO6YW.js → chunk-P26KVTI5.js} +136 -31
  15. package/dist/chunk-P26KVTI5.js.map +1 -0
  16. package/dist/{http-UQT6QVBC.js → http-ER2NMEKI.js} +2 -2
  17. package/dist/{http-Q6UEKZRF.js → http-MGES3ZVX.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-UVSZFZW7.js → replay-5XES2LBL.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-EMRHO6YW.js.map +0 -1
  31. package/dist/chunk-ZUD7OFYB.js.map +0 -1
  32. /package/dist/{chunk-3QXNM62Y.js.map → chunk-5KVK733P.js.map} +0 -0
  33. /package/dist/{chunk-6DRFQJ75.js.map → chunk-DRTHTSHO.js.map} +0 -0
  34. /package/dist/{http-Q6UEKZRF.js.map → http-ER2NMEKI.js.map} +0 -0
  35. /package/dist/{http-UQT6QVBC.js.map → http-MGES3ZVX.js.map} +0 -0
  36. /package/dist/{replay-UVSZFZW7.js.map → replay-5XES2LBL.js.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -3326,7 +3326,7 @@ interface CommitRef {
3326
3326
  /**
3327
3327
  * SDK version from package.json (injected at build time)
3328
3328
  */
3329
- declare const __version__ = "0.52.5";
3329
+ declare const __version__ = "0.52.6";
3330
3330
 
3331
3331
  /**
3332
3332
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -3326,7 +3326,7 @@ interface CommitRef {
3326
3326
  /**
3327
3327
  * SDK version from package.json (injected at build time)
3328
3328
  */
3329
- declare const __version__ = "0.52.5";
3329
+ declare const __version__ = "0.52.6";
3330
3330
 
3331
3331
  /**
3332
3332
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -28,8 +28,8 @@ import {
28
28
  getCurrentTrace,
29
29
  reseedFromRegistry,
30
30
  seedFromRegistry
31
- } from "./chunk-EMRHO6YW.js";
32
- import "./chunk-ZUD7OFYB.js";
31
+ } from "./chunk-P26KVTI5.js";
32
+ import "./chunk-E5BLYL5X.js";
33
33
  import {
34
34
  BITFAB_PROGRESS_PREFIX,
35
35
  DbBranchReplayError,
@@ -37,7 +37,7 @@ import {
37
37
  ReplayError,
38
38
  reportReplayProgress,
39
39
  serializeReplayResult
40
- } from "./chunk-6DRFQJ75.js";
40
+ } from "./chunk-DRTHTSHO.js";
41
41
  import {
42
42
  BitfabError,
43
43
  DEFAULT_SERVICE_URL,
@@ -45,7 +45,7 @@ import {
45
45
  MixedTracingError,
46
46
  __version__,
47
47
  flushTraces
48
- } from "./chunk-CAE7HE4C.js";
48
+ } from "./chunk-NXC6NYIY.js";
49
49
  import "./chunk-H6LZRFMN.js";
50
50
  export {
51
51
  BITFAB_PROGRESS_PREFIX,
package/dist/node.cjs CHANGED
@@ -97,7 +97,7 @@ var __version__, __packageName__;
97
97
  var init_version_generated = __esm({
98
98
  "src/version.generated.ts"() {
99
99
  "use strict";
100
- __version__ = "0.52.5";
100
+ __version__ = "0.52.6";
101
101
  __packageName__ = "bitfab";
102
102
  }
103
103
  });
@@ -4221,19 +4221,18 @@ init_asyncStorage();
4221
4221
  // src/autoTrace.ts
4222
4222
  init_asyncStorage();
4223
4223
  var autoTraceGlobal = globalThis;
4224
- var autoTraceState = autoTraceGlobal.__bitfabAutoTraceStateV3 ?? {
4224
+ var autoTraceState = autoTraceGlobal.__bitfabAutoTraceStateV4 ?? {
4225
4225
  storage: null,
4226
4226
  browserScope: void 0,
4227
4227
  capturePolicies: /* @__PURE__ */ new WeakMap(),
4228
4228
  activeRoots: 0
4229
4229
  };
4230
- autoTraceGlobal.__bitfabAutoTraceStateV3 = autoTraceState;
4230
+ autoTraceGlobal.__bitfabAutoTraceStateV4 = autoTraceState;
4231
4231
  function initializeAutoTraceStorage() {
4232
4232
  autoTraceState.storage ?? (autoTraceState.storage = createAsyncLocalStorage());
4233
4233
  }
4234
- function runWithAutoTraceContext(context, fn, depth = 0) {
4234
+ function runWithAutoTraceScope(scope, fn) {
4235
4235
  initializeAutoTraceStorage();
4236
- const scope = { context, depth };
4237
4236
  if (autoTraceState.storage) {
4238
4237
  return autoTraceState.storage.run(scope, fn);
4239
4238
  }
@@ -4245,41 +4244,65 @@ function runWithAutoTraceContext(context, fn, depth = 0) {
4245
4244
  autoTraceState.browserScope = previous;
4246
4245
  }
4247
4246
  }
4247
+ function currentAutoTraceEntries() {
4248
+ return currentAutoTraceScope()?.entries ?? [];
4249
+ }
4250
+ function replaceEntry(entries, previous, updated) {
4251
+ return entries.map((entry) => entry === previous ? updated : entry);
4252
+ }
4253
+ function runWithAutoTraceEntry(previous, updated, fn) {
4254
+ const result = runWithAutoTraceScope(
4255
+ { entries: replaceEntry(currentAutoTraceEntries(), previous, updated) },
4256
+ fn
4257
+ );
4258
+ if (isAutoTraceAsyncGenerator(result)) {
4259
+ return wrapAutoTraceEntryAsyncGenerator(previous, updated, result);
4260
+ }
4261
+ return result;
4262
+ }
4263
+ function wrapAutoTraceEntryAsyncGenerator(previous, updated, source) {
4264
+ const step = (method, value) => runWithAutoTraceScope(
4265
+ { entries: replaceEntry(currentAutoTraceEntries(), previous, updated) },
4266
+ () => source[method](value)
4267
+ );
4268
+ const wrapped = {
4269
+ next: (value) => step("next", value),
4270
+ return: (value) => step("return", value),
4271
+ throw: (error) => step("throw", error),
4272
+ [Symbol.asyncIterator]: () => wrapped
4273
+ };
4274
+ return wrapped;
4275
+ }
4276
+ function clearAutoTraceNodeConfiguration(fn) {
4277
+ return runWithAutoTraceScope({ entries: currentAutoTraceEntries() }, fn);
4278
+ }
4248
4279
  function runWithAutoTraceNodeConfiguration(nodeConfiguration, fn) {
4249
4280
  const scope = currentAutoTraceScope();
4250
- if (!scope) {
4281
+ if (!scope || scope.entries.length === 0) {
4251
4282
  return fn();
4252
4283
  }
4253
- const configuredScope = { ...scope, nodeConfiguration };
4254
- let result;
4255
- if (autoTraceState.storage) {
4256
- result = autoTraceState.storage.run(configuredScope, fn);
4257
- } else {
4258
- const previous = autoTraceState.browserScope;
4259
- autoTraceState.browserScope = configuredScope;
4260
- try {
4261
- result = fn();
4262
- } finally {
4263
- autoTraceState.browserScope = previous;
4264
- }
4265
- }
4284
+ const result = runWithAutoTraceScope({ ...scope, nodeConfiguration }, fn);
4266
4285
  if (isAutoTraceAsyncGenerator(result)) {
4267
4286
  return wrapAutoTraceNodeAsyncGenerator(nodeConfiguration, result);
4268
4287
  }
4269
4288
  return result;
4270
4289
  }
4271
- function runWithAutoTraceRootContext(context, fn) {
4290
+ function runWithAutoTraceRootContext(context, spanStack, fn) {
4272
4291
  autoTraceState.activeRoots += 1;
4292
+ const entries = [
4293
+ ...currentAutoTraceEntries(),
4294
+ { context, depth: 0, spanStack }
4295
+ ];
4273
4296
  let result;
4274
4297
  try {
4275
- result = runWithAutoTraceContext(context, fn);
4298
+ result = runWithAutoTraceScope({ entries }, fn);
4276
4299
  } catch (error) {
4277
4300
  autoTraceState.activeRoots -= 1;
4278
4301
  throw error;
4279
4302
  }
4280
4303
  if (isAutoTraceAsyncGenerator(result)) {
4281
4304
  autoTraceState.activeRoots -= 1;
4282
- return wrapAutoTraceAsyncGenerator(context, result);
4305
+ return wrapAutoTraceAsyncGenerator(context, spanStack, result);
4283
4306
  }
4284
4307
  if (result instanceof Promise) {
4285
4308
  return result.finally(() => {
@@ -4289,6 +4312,15 @@ function runWithAutoTraceRootContext(context, fn) {
4289
4312
  autoTraceState.activeRoots -= 1;
4290
4313
  return result;
4291
4314
  }
4315
+ function invokeThroughAutoTraceEntries(entries, step, fn) {
4316
+ let run = fn;
4317
+ for (let index = entries.length - 1; index >= 0; index -= 1) {
4318
+ const entry = entries[index];
4319
+ const next = run;
4320
+ run = () => step(entry, next);
4321
+ }
4322
+ return run();
4323
+ }
4292
4324
  function isAutoTraceAsyncGenerator(value) {
4293
4325
  if (value === null || typeof value !== "object") {
4294
4326
  return false;
@@ -4296,8 +4328,8 @@ function isAutoTraceAsyncGenerator(value) {
4296
4328
  const candidate = value;
4297
4329
  return typeof candidate.next === "function" && typeof candidate.return === "function" && typeof candidate.throw === "function" && typeof candidate[Symbol.asyncIterator] === "function";
4298
4330
  }
4299
- function wrapAutoTraceAsyncGenerator(context, source) {
4300
- const step = (method, value) => runWithAutoTraceRootContext(context, () => source[method](value));
4331
+ function wrapAutoTraceAsyncGenerator(context, spanStack, source) {
4332
+ const step = (method, value) => runWithAutoTraceRootContext(context, spanStack, () => source[method](value));
4301
4333
  const wrapped = {
4302
4334
  next: (value) => step("next", value),
4303
4335
  return: (value) => step("return", value),
@@ -4323,7 +4355,7 @@ function __bitfabAutoTraceActive() {
4323
4355
  if (autoTraceState.activeRoots === 0) {
4324
4356
  return false;
4325
4357
  }
4326
- return currentAutoTraceScope() !== void 0;
4358
+ return currentAutoTraceEntries().length > 0;
4327
4359
  }
4328
4360
  function currentAutoTraceScope() {
4329
4361
  initializeAutoTraceStorage();
@@ -7076,11 +7108,15 @@ var Bitfab = class {
7076
7108
  type: options.type ?? "custom",
7077
7109
  surface: "opt-out"
7078
7110
  };
7079
- const tracedRoot = this.withSpan(
7111
+ const rootName = options.name ?? name;
7112
+ const buildTracedRoot = (spanOptions) => this.withSpan(
7080
7113
  traceFunctionKey,
7081
- rootOptions,
7114
+ spanOptions,
7082
7115
  function(...args) {
7083
- const capturePolicy = getAutoTraceCapturePolicy(self, traceFunctionKey);
7116
+ const capturePolicy = getAutoTraceCapturePolicy(
7117
+ self,
7118
+ traceFunctionKey
7119
+ );
7084
7120
  self.refreshAutoTraceCapturePolicy(traceFunctionKey);
7085
7121
  let spansUsed = 0;
7086
7122
  let truncated = false;
@@ -7101,19 +7137,54 @@ var Bitfab = class {
7101
7137
  `"${traceFunctionKey}" hit an automatic subtree capture limit (maxDepth=${maxDepth}, maxSpans=${maxSpans}); its trace is incomplete. Raise the limits or narrow the subtree with exclude.`
7102
7138
  );
7103
7139
  };
7140
+ const spanStackOf = (entry) => entry.spanStack;
7141
+ const openChild = (entry, childOptions, inputs, isAsync, invokeFn) => {
7142
+ const runInside = () => runWithAutoTraceEntry(
7143
+ entry,
7144
+ {
7145
+ context: autoTraceContext,
7146
+ depth: entry.depth + 1,
7147
+ spanStack: getSpanStack()
7148
+ },
7149
+ invokeFn
7150
+ );
7151
+ return runWithSpanStack(spanStackOf(entry), () => {
7152
+ if (isAsync) {
7153
+ const tracedAsyncChild = self.withSpan(
7154
+ traceFunctionKey,
7155
+ childOptions,
7156
+ async (..._inputs) => await runInside()
7157
+ );
7158
+ return tracedAsyncChild(...inputs);
7159
+ }
7160
+ const tracedChild = self.withSpan(
7161
+ traceFunctionKey,
7162
+ childOptions,
7163
+ (..._inputs) => runInside()
7164
+ );
7165
+ return tracedChild(...inputs);
7166
+ });
7167
+ };
7168
+ const overBudget = (entry) => {
7169
+ if (entry.depth < maxDepth && spansUsed < maxSpans) {
7170
+ return false;
7171
+ }
7172
+ runWithSpanStack(spanStackOf(entry), warnTruncated);
7173
+ return true;
7174
+ };
7104
7175
  const autoTraceContext = {
7105
- invoke(definition, inputs, invokeFn, depth, nodeConfiguration) {
7176
+ traceFunctionKey,
7177
+ invoke(definition, inputs, invokeFn, entry, nodeConfiguration) {
7106
7178
  const nameParts = definition.name.split(".");
7107
7179
  const simpleName = nameParts[nameParts.length - 1];
7108
- const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
7180
+ const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : clearAutoTraceNodeConfiguration(invokeFn);
7109
7181
  if (excluded.has(definition.name) || simpleName !== void 0 && excluded.has(simpleName) || nodeConfiguration === void 0 && definition.wrapper === true && !includeWrappers) {
7110
7182
  return invokeWithoutNode();
7111
7183
  }
7112
7184
  if (nodeConfiguration?.capture === false) {
7113
- return runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
7185
+ return clearAutoTraceNodeConfiguration(invokeFn);
7114
7186
  }
7115
- if (depth >= maxDepth || spansUsed >= maxSpans) {
7116
- warnTruncated();
7187
+ if (overBudget(entry)) {
7117
7188
  return invokeWithoutNode();
7118
7189
  }
7119
7190
  spansUsed += 1;
@@ -7136,34 +7207,81 @@ var Bitfab = class {
7136
7207
  finalize: nodeConfiguration.finalize
7137
7208
  }
7138
7209
  };
7139
- const invokeWithAutoTraceContext = () => runWithAutoTraceContext(autoTraceContext, invokeFn, depth + 1);
7140
- if (definition.async === true) {
7141
- const tracedAsyncChild = self.withSpan(
7142
- traceFunctionKey,
7143
- childOptions,
7144
- async (..._inputs) => await invokeWithAutoTraceContext()
7145
- );
7146
- return tracedAsyncChild(...inputs);
7147
- }
7148
- const tracedChild = self.withSpan(
7149
- traceFunctionKey,
7210
+ return openChild(
7211
+ entry,
7150
7212
  childOptions,
7151
- (..._inputs) => invokeWithAutoTraceContext()
7213
+ inputs,
7214
+ definition.async === true,
7215
+ invokeFn
7152
7216
  );
7153
- return tracedChild(...inputs);
7217
+ },
7218
+ invokeNestedRoot(nestedName, nestedFunctionName, inputs, invokeFn, entry, link) {
7219
+ if (excluded.has(nestedName) || excluded.has(nestedFunctionName) || overBudget(entry)) {
7220
+ return invokeFn();
7221
+ }
7222
+ spansUsed += 1;
7223
+ const childOptions = {
7224
+ name: nestedName,
7225
+ type: "function",
7226
+ captureWhen: "nested",
7227
+ surface: "opt-out",
7228
+ captureContent: true,
7229
+ ...link !== void 0 && { nestedTrace: link }
7230
+ };
7231
+ return openChild(entry, childOptions, inputs, false, invokeFn);
7154
7232
  }
7155
7233
  };
7156
7234
  return runWithAutoTraceRootContext(
7157
7235
  autoTraceContext,
7236
+ getSpanStack(),
7158
7237
  () => fn.apply(this, args)
7159
7238
  );
7160
7239
  }
7161
7240
  );
7241
+ const tracedRoot = buildTracedRoot(rootOptions);
7162
7242
  const autoTraceRoot = function(...args) {
7163
7243
  if (!self.shouldRecord()) {
7164
7244
  return fn.apply(this, args);
7165
7245
  }
7166
- return tracedRoot.apply(this, args);
7246
+ const enclosing = currentAutoTraceEntries();
7247
+ if (enclosing.length === 0) {
7248
+ return tracedRoot.apply(this, args);
7249
+ }
7250
+ const link = getReplayContext() || inSeedScope() ? void 0 : { traceFunctionKey };
7251
+ return invokeThroughAutoTraceEntries(
7252
+ enclosing,
7253
+ (entry, next) => entry.context.invokeNestedRoot(
7254
+ rootName,
7255
+ name,
7256
+ args,
7257
+ next,
7258
+ entry,
7259
+ link
7260
+ ),
7261
+ () => {
7262
+ if (link === void 0) {
7263
+ return fn.apply(this, args);
7264
+ }
7265
+ const innermost = enclosing[enclosing.length - 1];
7266
+ const innermostNow = currentAutoTraceEntries().find(
7267
+ (entry) => entry.context === innermost.context
7268
+ ) ?? innermost;
7269
+ const innermostStack = innermostNow.spanStack;
7270
+ const copy = innermostStack[innermostStack.length - 1];
7271
+ const detachedRoot = buildTracedRoot({
7272
+ ...rootOptions,
7273
+ ...copy !== void 0 && {
7274
+ enclosingTrace: {
7275
+ traceId: copy.traceId,
7276
+ spanId: copy.spanId,
7277
+ traceFunctionKey: innermost.context.traceFunctionKey,
7278
+ link
7279
+ }
7280
+ }
7281
+ });
7282
+ return runWithSpanStack([], () => detachedRoot.apply(this, args));
7283
+ }
7284
+ );
7167
7285
  };
7168
7286
  Object.defineProperty(autoTraceRoot, "_bitfabTraceFunctionKey", {
7169
7287
  value: traceFunctionKey
@@ -7752,6 +7870,10 @@ var Bitfab = class {
7752
7870
  const spanId = randomUuid();
7753
7871
  const parentSpanId = parentContext?.spanId ?? null;
7754
7872
  const isRootSpan = parentSpanId === null;
7873
+ if (options.enclosingTrace !== void 0) {
7874
+ options.enclosingTrace.link.traceId = traceId;
7875
+ options.enclosingTrace.link.rootSpanId = spanId;
7876
+ }
7755
7877
  const requestedSurface = options.surface ?? DEFAULT_SURFACE;
7756
7878
  const surface = resolveSurface(requestedSurface, parentContext?.surface);
7757
7879
  assertSurfacesCompatible(
@@ -7801,7 +7923,9 @@ var Bitfab = class {
7801
7923
  spanType: options.type ?? "custom",
7802
7924
  functionId: options.functionId,
7803
7925
  captureContent: options.captureContent ?? true,
7804
- autoTraceDefinition: options.autoTraceDefinition
7926
+ autoTraceDefinition: options.autoTraceDefinition,
7927
+ nestedTrace: options.nestedTrace,
7928
+ enclosingTrace: options.enclosingTrace
7805
7929
  };
7806
7930
  const sendSpan = async (params) => {
7807
7931
  const replayCtx = getReplayContext();
@@ -8311,6 +8435,16 @@ var Bitfab = class {
8311
8435
  function_line: params.autoTraceDefinition.line,
8312
8436
  function_column: params.autoTraceDefinition.column
8313
8437
  },
8438
+ ...params.nestedTrace?.traceId !== void 0 && {
8439
+ nested_trace_id: params.nestedTrace.traceId,
8440
+ nested_trace_function_key: params.nestedTrace.traceFunctionKey,
8441
+ nested_root_span_id: params.nestedTrace.rootSpanId
8442
+ },
8443
+ ...params.enclosingTrace !== void 0 && {
8444
+ enclosing_trace_id: params.enclosingTrace.traceId,
8445
+ enclosing_trace_function_key: params.enclosingTrace.traceFunctionKey,
8446
+ enclosing_span_id: params.enclosingTrace.spanId
8447
+ },
8314
8448
  ...serializedInputs !== void 0 && {
8315
8449
  input: serializedInputs.json,
8316
8450
  ...serializedInputs.meta !== void 0 && {