bitfab 0.52.4 → 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 (41) hide show
  1. package/README.md +2 -0
  2. package/dist/autoTrace.cjs +84 -34
  3. package/dist/autoTrace.cjs.map +1 -1
  4. package/dist/autoTrace.d.cts +19 -4
  5. package/dist/autoTrace.d.ts +19 -4
  6. package/dist/autoTrace.js +9 -3
  7. package/dist/{chunk-HKTODDFP.js → chunk-5KVK733P.js} +3 -3
  8. package/dist/chunk-5KVK733P.js.map +1 -0
  9. package/dist/{chunk-U2D7ACC4.js → chunk-DRTHTSHO.js} +110 -13
  10. package/dist/chunk-DRTHTSHO.js.map +1 -0
  11. package/dist/{chunk-ZUD7OFYB.js → chunk-E5BLYL5X.js} +81 -34
  12. package/dist/chunk-E5BLYL5X.js.map +1 -0
  13. package/dist/{chunk-IG3CPSRQ.js → chunk-GJKU7VWG.js} +2 -2
  14. package/dist/{chunk-IG3CPSRQ.js.map → chunk-GJKU7VWG.js.map} +1 -1
  15. package/dist/{chunk-34B7PVAM.js → chunk-NXC6NYIY.js} +3 -2
  16. package/dist/{chunk-34B7PVAM.js.map → chunk-NXC6NYIY.js.map} +1 -1
  17. package/dist/{chunk-AUROMI67.js → chunk-P26KVTI5.js} +371 -46
  18. package/dist/chunk-P26KVTI5.js.map +1 -0
  19. package/dist/{http-F3AXLOJT.js → http-ER2NMEKI.js} +2 -2
  20. package/dist/{http-RFNQ7LSU.js → http-MGES3ZVX.js} +2 -2
  21. package/dist/index.cjs +561 -104
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +10 -2
  24. package/dist/index.d.ts +10 -2
  25. package/dist/index.js +4 -4
  26. package/dist/node.cjs +561 -104
  27. package/dist/node.cjs.map +1 -1
  28. package/dist/node.d.cts +1 -1
  29. package/dist/node.d.ts +1 -1
  30. package/dist/node.js +4 -4
  31. package/dist/{replay-ZOTYMBMD.js → replay-5XES2LBL.js} +3 -3
  32. package/dist/replayCli.js +2 -2
  33. package/dist/seedCli.js +2 -2
  34. package/package.json +1 -1
  35. package/dist/chunk-AUROMI67.js.map +0 -1
  36. package/dist/chunk-HKTODDFP.js.map +0 -1
  37. package/dist/chunk-U2D7ACC4.js.map +0 -1
  38. package/dist/chunk-ZUD7OFYB.js.map +0 -1
  39. /package/dist/{http-F3AXLOJT.js.map → http-ER2NMEKI.js.map} +0 -0
  40. /package/dist/{http-RFNQ7LSU.js.map → http-MGES3ZVX.js.map} +0 -0
  41. /package/dist/{replay-ZOTYMBMD.js.map → replay-5XES2LBL.js.map} +0 -0
@@ -1,21 +1,25 @@
1
1
  import {
2
2
  __bitfabAutoTraceActive,
3
3
  __setBitfabAutoTraceCapturePolicy,
4
+ clearAutoTraceNodeConfiguration,
5
+ currentAutoTraceEntries,
4
6
  getAutoTraceCapturePolicy,
5
- runWithAutoTraceContext,
7
+ invokeThroughAutoTraceEntries,
8
+ runWithAutoTraceEntry,
6
9
  runWithAutoTraceNodeConfiguration,
7
10
  runWithAutoTraceRootContext
8
- } from "./chunk-ZUD7OFYB.js";
11
+ } from "./chunk-E5BLYL5X.js";
9
12
  import {
10
13
  NO_MOCK_OVERRIDE,
11
14
  deserializeInputs,
12
15
  deserializeValue,
16
+ gitRunner,
13
17
  randomUuid,
14
18
  resolveMockValue,
15
19
  serializeValue,
16
20
  toJsonSafe,
17
21
  toJsonSafeReport
18
- } from "./chunk-U2D7ACC4.js";
22
+ } from "./chunk-DRTHTSHO.js";
19
23
  import {
20
24
  BitfabError,
21
25
  DEFAULT_SERVICE_URL,
@@ -23,10 +27,11 @@ import {
23
27
  MixedTracingError,
24
28
  callerTraceMetadata,
25
29
  getReplayContext,
30
+ readEnv,
26
31
  recordCallerTraceMetadata,
27
32
  retireTraceMetadata,
28
33
  warnOnce
29
- } from "./chunk-34B7PVAM.js";
34
+ } from "./chunk-NXC6NYIY.js";
30
35
  import {
31
36
  __privateAdd,
32
37
  __privateGet,
@@ -1017,24 +1022,237 @@ function mixedTracingError(enteredApi, entered, enclosing, traceFunctionKey) {
1017
1022
  `opt-in and opt-out tracing can't be mixed in one call stack: ${enteredApi} (${entered})${subject} was entered inside a ${SURFACE_API[enclosing]} call (${enclosing}). ${MIXED_SURFACE_REMEDY[entered]}`
1018
1023
  );
1019
1024
  }
1020
- function assertSurfacesCompatible(requested, resolved, parentSurface, traceFunctionKey) {
1025
+ function assertSurfacesCompatible(requested, resolved2, parentSurface, traceFunctionKey) {
1021
1026
  if (requested === "inherit" || requested === "neutral") {
1022
1027
  return;
1023
1028
  }
1024
- if (resolved === void 0 || parentSurface === void 0) {
1029
+ if (resolved2 === void 0 || parentSurface === void 0) {
1025
1030
  return;
1026
1031
  }
1027
- if (parentSurface === resolved) {
1032
+ if (parentSurface === resolved2) {
1028
1033
  return;
1029
1034
  }
1030
1035
  throw mixedTracingError(
1031
- SURFACE_API[resolved],
1032
- resolved,
1036
+ SURFACE_API[resolved2],
1037
+ resolved2,
1033
1038
  parentSurface,
1034
1039
  traceFunctionKey
1035
1040
  );
1036
1041
  }
1037
1042
 
1043
+ // src/commitRef.ts
1044
+ var EXPLICIT_SHA_ENV = "BITFAB_COMMIT_SHA";
1045
+ var DISABLE_ENV = "BITFAB_DISABLE_COMMIT_REF";
1046
+ var GIT_TIMEOUT_MS = 2e3;
1047
+ var GIT_MAX_BUFFER = 1024 * 1024;
1048
+ var VERCEL_PROVIDER_HOSTS = {
1049
+ github: "github.com",
1050
+ gitlab: "gitlab.com",
1051
+ bitbucket: "bitbucket.org"
1052
+ };
1053
+ function read(env, name) {
1054
+ if (name === null) {
1055
+ return null;
1056
+ }
1057
+ const value = env(name)?.trim();
1058
+ return value ? value : null;
1059
+ }
1060
+ function remoteFrom(...names) {
1061
+ return (env) => {
1062
+ const parts = names.map((name) => read(env, name));
1063
+ if (parts.some((part) => part === null)) {
1064
+ return null;
1065
+ }
1066
+ return normalizeRemote(parts.join("/"));
1067
+ };
1068
+ }
1069
+ function vercelRemote(env) {
1070
+ const provider = read(env, "VERCEL_GIT_PROVIDER")?.toLowerCase() ?? "";
1071
+ const host = VERCEL_PROVIDER_HOSTS[provider];
1072
+ const owner = read(env, "VERCEL_GIT_REPO_OWNER");
1073
+ const slug = read(env, "VERCEL_GIT_REPO_SLUG");
1074
+ if (!host || !owner || !slug) {
1075
+ return null;
1076
+ }
1077
+ return `${host}/${owner}/${slug}`;
1078
+ }
1079
+ function noRemote() {
1080
+ return null;
1081
+ }
1082
+ var PLATFORM_ENVS = [
1083
+ ["VERCEL_GIT_COMMIT_SHA", "VERCEL_GIT_COMMIT_REF", vercelRemote],
1084
+ [
1085
+ "GITHUB_SHA",
1086
+ "GITHUB_REF_NAME",
1087
+ remoteFrom("GITHUB_SERVER_URL", "GITHUB_REPOSITORY")
1088
+ ],
1089
+ ["RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH", noRemote],
1090
+ ["RENDER_GIT_COMMIT", "RENDER_GIT_BRANCH", noRemote],
1091
+ ["SOURCE_VERSION", null, noRemote],
1092
+ ["CF_PAGES_COMMIT_SHA", "CF_PAGES_BRANCH", noRemote],
1093
+ ["CI_COMMIT_SHA", "CI_COMMIT_REF_NAME", remoteFrom("CI_REPOSITORY_URL")],
1094
+ [
1095
+ "BUILD_SOURCEVERSION",
1096
+ "BUILD_SOURCEBRANCHNAME",
1097
+ remoteFrom("BUILD_REPOSITORY_URI")
1098
+ ],
1099
+ ["CIRCLE_SHA1", "CIRCLE_BRANCH", remoteFrom("CIRCLE_REPOSITORY_URL")]
1100
+ ];
1101
+ var COMMIT_REF_ENV_NAMES = [
1102
+ EXPLICIT_SHA_ENV,
1103
+ DISABLE_ENV,
1104
+ ...PLATFORM_ENVS.flatMap(
1105
+ ([sha, branch]) => branch === null ? [sha] : [sha, branch]
1106
+ ),
1107
+ "GITHUB_SERVER_URL",
1108
+ "GITHUB_REPOSITORY",
1109
+ "CI_REPOSITORY_URL",
1110
+ "BUILD_REPOSITORY_URI",
1111
+ "CIRCLE_REPOSITORY_URL",
1112
+ "VERCEL_GIT_PROVIDER",
1113
+ "VERCEL_GIT_REPO_OWNER",
1114
+ "VERCEL_GIT_REPO_SLUG"
1115
+ ];
1116
+ function normalizeRemote(raw) {
1117
+ const value = raw?.trim();
1118
+ if (!value) {
1119
+ return null;
1120
+ }
1121
+ let host = "";
1122
+ let path = value;
1123
+ if (value.includes("://")) {
1124
+ try {
1125
+ const parsed = new URL(value);
1126
+ host = parsed.hostname;
1127
+ path = parsed.pathname;
1128
+ } catch {
1129
+ return null;
1130
+ }
1131
+ } else {
1132
+ const separator = value.indexOf(":");
1133
+ if (separator !== -1) {
1134
+ const head = value.slice(0, separator);
1135
+ host = head.slice(head.lastIndexOf("@") + 1);
1136
+ path = value.slice(separator + 1);
1137
+ }
1138
+ }
1139
+ path = path.replace(/^\/+|\/+$/g, "");
1140
+ if (path.endsWith(".git")) {
1141
+ path = path.slice(0, -".git".length).replace(/\/+$/, "");
1142
+ }
1143
+ if (!host) {
1144
+ return path || null;
1145
+ }
1146
+ return path ? `${host}/${path}` : host;
1147
+ }
1148
+ function resolveCommitRefFromEnv(env) {
1149
+ const explicit = read(env, EXPLICIT_SHA_ENV);
1150
+ const platform = PLATFORM_ENVS.find(([sha]) => read(env, sha) !== null);
1151
+ if (!platform) {
1152
+ if (explicit === null) {
1153
+ return null;
1154
+ }
1155
+ return {
1156
+ sha: explicit,
1157
+ branch: null,
1158
+ dirty: null,
1159
+ remote: null,
1160
+ rootSha: null
1161
+ };
1162
+ }
1163
+ const [shaEnv, branchEnv, readRemote] = platform;
1164
+ return {
1165
+ sha: explicit ?? read(env, shaEnv),
1166
+ branch: read(env, branchEnv),
1167
+ dirty: null,
1168
+ remote: readRemote(env),
1169
+ rootSha: null
1170
+ };
1171
+ }
1172
+ async function resolveCommitRefFromGit(cwd) {
1173
+ const git = await gitRunner({
1174
+ timeoutMs: GIT_TIMEOUT_MS,
1175
+ maxBuffer: GIT_MAX_BUFFER,
1176
+ keepProcessAlive: false
1177
+ });
1178
+ if (!git) {
1179
+ return null;
1180
+ }
1181
+ const run = async (args) => (await git(cwd, args))?.trim() ?? null;
1182
+ const sha = await run(["rev-parse", "HEAD"]);
1183
+ if (!sha) {
1184
+ return null;
1185
+ }
1186
+ const [branch, status, remote, roots] = await Promise.all([
1187
+ run(["symbolic-ref", "--short", "-q", "HEAD"]),
1188
+ run(["status", "--porcelain"]),
1189
+ run(["remote", "get-url", "origin"]),
1190
+ run(["rev-list", "--max-parents=0", "HEAD"])
1191
+ ]);
1192
+ return {
1193
+ sha,
1194
+ branch: branch || null,
1195
+ dirty: status === null ? null : status.length > 0,
1196
+ remote: normalizeRemote(remote),
1197
+ rootSha: roots ? roots.split(/\s+/).sort()[0] ?? null : null
1198
+ };
1199
+ }
1200
+ function commitRefWire(ref2) {
1201
+ return {
1202
+ sha: ref2.sha,
1203
+ branch: ref2.branch,
1204
+ dirty: ref2.dirty,
1205
+ remote: ref2.remote,
1206
+ root_sha: ref2.rootSha
1207
+ };
1208
+ }
1209
+ var resolved = false;
1210
+ var ref = null;
1211
+ var gitStarted = false;
1212
+ var settled = Promise.resolve();
1213
+ function startCommitRefResolution() {
1214
+ if (resolved || gitStarted) {
1215
+ return;
1216
+ }
1217
+ if (read(readEnv, DISABLE_ENV) !== null) {
1218
+ resolved = true;
1219
+ return;
1220
+ }
1221
+ const fromEnv = resolveCommitRefFromEnv(readEnv);
1222
+ if (fromEnv) {
1223
+ ref = fromEnv;
1224
+ resolved = true;
1225
+ return;
1226
+ }
1227
+ gitStarted = true;
1228
+ if (typeof process === "undefined") {
1229
+ resolved = true;
1230
+ return;
1231
+ }
1232
+ let cwd;
1233
+ try {
1234
+ cwd = process.cwd?.() ?? ".";
1235
+ } catch {
1236
+ resolved = true;
1237
+ return;
1238
+ }
1239
+ settled = resolveCommitRefFromGit(cwd).then(
1240
+ (fromGit) => {
1241
+ if (!resolved) {
1242
+ ref = fromGit;
1243
+ resolved = true;
1244
+ }
1245
+ },
1246
+ () => {
1247
+ resolved = true;
1248
+ }
1249
+ );
1250
+ }
1251
+ function currentCommitRef() {
1252
+ startCommitRefResolution();
1253
+ return ref;
1254
+ }
1255
+
1038
1256
  // src/datasets.ts
1039
1257
  var DEFAULT_RERUN_TIMEOUT_MS = 9e4;
1040
1258
  var DEFAULT_RERUN_POLL_INTERVAL_MS = 1e3;
@@ -1512,11 +1730,11 @@ var BitfabLangGraphCallbackHandler = class {
1512
1730
  this.invocations.set(invocation.rootRunId, invocation);
1513
1731
  }
1514
1732
  if (!willHide) {
1515
- let resolved = parentSpan;
1516
- while (resolved?.hidden === true) {
1517
- resolved = resolved.parentId ? this.runToSpan.get(resolved.parentId) : void 0;
1733
+ let resolved2 = parentSpan;
1734
+ while (resolved2?.hidden === true) {
1735
+ resolved2 = resolved2.parentId ? this.runToSpan.get(resolved2.parentId) : void 0;
1518
1736
  }
1519
- effectiveParentId = resolved ? resolved.spanId : invocation.activeContext?.spanId ?? null;
1737
+ effectiveParentId = resolved2 ? resolved2.spanId : invocation.activeContext?.spanId ?? null;
1520
1738
  } else {
1521
1739
  effectiveParentId = parentRunId ?? null;
1522
1740
  }
@@ -2948,7 +3166,7 @@ function getCurrentTrace() {
2948
3166
  }
2949
3167
  };
2950
3168
  }
2951
- function readEnv(name) {
3169
+ function readEnv2(name) {
2952
3170
  if (typeof process !== "undefined" && process.env) {
2953
3171
  return process.env[name];
2954
3172
  }
@@ -2995,6 +3213,7 @@ var Bitfab = class {
2995
3213
  validateDbSnapshotConfig(config.dbSnapshot);
2996
3214
  }
2997
3215
  this.dbSnapshot = config.dbSnapshot;
3216
+ startCommitRefResolution();
2998
3217
  this.httpClient = new HttpClient({
2999
3218
  apiKey: () => this.resolveApiKey(),
3000
3219
  serviceUrl: this.serviceUrl,
@@ -3165,11 +3384,15 @@ var Bitfab = class {
3165
3384
  type: options.type ?? "custom",
3166
3385
  surface: "opt-out"
3167
3386
  };
3168
- const tracedRoot = this.withSpan(
3387
+ const rootName = options.name ?? name;
3388
+ const buildTracedRoot = (spanOptions) => this.withSpan(
3169
3389
  traceFunctionKey,
3170
- rootOptions,
3390
+ spanOptions,
3171
3391
  function(...args) {
3172
- const capturePolicy = getAutoTraceCapturePolicy(self, traceFunctionKey);
3392
+ const capturePolicy = getAutoTraceCapturePolicy(
3393
+ self,
3394
+ traceFunctionKey
3395
+ );
3173
3396
  self.refreshAutoTraceCapturePolicy(traceFunctionKey);
3174
3397
  let spansUsed = 0;
3175
3398
  let truncated = false;
@@ -3190,19 +3413,54 @@ var Bitfab = class {
3190
3413
  `"${traceFunctionKey}" hit an automatic subtree capture limit (maxDepth=${maxDepth}, maxSpans=${maxSpans}); its trace is incomplete. Raise the limits or narrow the subtree with exclude.`
3191
3414
  );
3192
3415
  };
3416
+ const spanStackOf = (entry) => entry.spanStack;
3417
+ const openChild = (entry, childOptions, inputs, isAsync, invokeFn) => {
3418
+ const runInside = () => runWithAutoTraceEntry(
3419
+ entry,
3420
+ {
3421
+ context: autoTraceContext,
3422
+ depth: entry.depth + 1,
3423
+ spanStack: getSpanStack()
3424
+ },
3425
+ invokeFn
3426
+ );
3427
+ return runWithSpanStack(spanStackOf(entry), () => {
3428
+ if (isAsync) {
3429
+ const tracedAsyncChild = self.withSpan(
3430
+ traceFunctionKey,
3431
+ childOptions,
3432
+ async (..._inputs) => await runInside()
3433
+ );
3434
+ return tracedAsyncChild(...inputs);
3435
+ }
3436
+ const tracedChild = self.withSpan(
3437
+ traceFunctionKey,
3438
+ childOptions,
3439
+ (..._inputs) => runInside()
3440
+ );
3441
+ return tracedChild(...inputs);
3442
+ });
3443
+ };
3444
+ const overBudget = (entry) => {
3445
+ if (entry.depth < maxDepth && spansUsed < maxSpans) {
3446
+ return false;
3447
+ }
3448
+ runWithSpanStack(spanStackOf(entry), warnTruncated);
3449
+ return true;
3450
+ };
3193
3451
  const autoTraceContext = {
3194
- invoke(definition, inputs, invokeFn, depth, nodeConfiguration) {
3452
+ traceFunctionKey,
3453
+ invoke(definition, inputs, invokeFn, entry, nodeConfiguration) {
3195
3454
  const nameParts = definition.name.split(".");
3196
3455
  const simpleName = nameParts[nameParts.length - 1];
3197
- const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
3456
+ const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : clearAutoTraceNodeConfiguration(invokeFn);
3198
3457
  if (excluded.has(definition.name) || simpleName !== void 0 && excluded.has(simpleName) || nodeConfiguration === void 0 && definition.wrapper === true && !includeWrappers) {
3199
3458
  return invokeWithoutNode();
3200
3459
  }
3201
3460
  if (nodeConfiguration?.capture === false) {
3202
- return runWithAutoTraceContext(autoTraceContext, invokeFn, depth);
3461
+ return clearAutoTraceNodeConfiguration(invokeFn);
3203
3462
  }
3204
- if (depth >= maxDepth || spansUsed >= maxSpans) {
3205
- warnTruncated();
3463
+ if (overBudget(entry)) {
3206
3464
  return invokeWithoutNode();
3207
3465
  }
3208
3466
  spansUsed += 1;
@@ -3225,34 +3483,81 @@ var Bitfab = class {
3225
3483
  finalize: nodeConfiguration.finalize
3226
3484
  }
3227
3485
  };
3228
- const invokeWithAutoTraceContext = () => runWithAutoTraceContext(autoTraceContext, invokeFn, depth + 1);
3229
- if (definition.async === true) {
3230
- const tracedAsyncChild = self.withSpan(
3231
- traceFunctionKey,
3232
- childOptions,
3233
- async (..._inputs) => await invokeWithAutoTraceContext()
3234
- );
3235
- return tracedAsyncChild(...inputs);
3236
- }
3237
- const tracedChild = self.withSpan(
3238
- traceFunctionKey,
3486
+ return openChild(
3487
+ entry,
3239
3488
  childOptions,
3240
- (..._inputs) => invokeWithAutoTraceContext()
3489
+ inputs,
3490
+ definition.async === true,
3491
+ invokeFn
3241
3492
  );
3242
- return tracedChild(...inputs);
3493
+ },
3494
+ invokeNestedRoot(nestedName, nestedFunctionName, inputs, invokeFn, entry, link) {
3495
+ if (excluded.has(nestedName) || excluded.has(nestedFunctionName) || overBudget(entry)) {
3496
+ return invokeFn();
3497
+ }
3498
+ spansUsed += 1;
3499
+ const childOptions = {
3500
+ name: nestedName,
3501
+ type: "function",
3502
+ captureWhen: "nested",
3503
+ surface: "opt-out",
3504
+ captureContent: true,
3505
+ ...link !== void 0 && { nestedTrace: link }
3506
+ };
3507
+ return openChild(entry, childOptions, inputs, false, invokeFn);
3243
3508
  }
3244
3509
  };
3245
3510
  return runWithAutoTraceRootContext(
3246
3511
  autoTraceContext,
3512
+ getSpanStack(),
3247
3513
  () => fn.apply(this, args)
3248
3514
  );
3249
3515
  }
3250
3516
  );
3517
+ const tracedRoot = buildTracedRoot(rootOptions);
3251
3518
  const autoTraceRoot = function(...args) {
3252
3519
  if (!self.shouldRecord()) {
3253
3520
  return fn.apply(this, args);
3254
3521
  }
3255
- return tracedRoot.apply(this, args);
3522
+ const enclosing = currentAutoTraceEntries();
3523
+ if (enclosing.length === 0) {
3524
+ return tracedRoot.apply(this, args);
3525
+ }
3526
+ const link = getReplayContext() || inSeedScope() ? void 0 : { traceFunctionKey };
3527
+ return invokeThroughAutoTraceEntries(
3528
+ enclosing,
3529
+ (entry, next) => entry.context.invokeNestedRoot(
3530
+ rootName,
3531
+ name,
3532
+ args,
3533
+ next,
3534
+ entry,
3535
+ link
3536
+ ),
3537
+ () => {
3538
+ if (link === void 0) {
3539
+ return fn.apply(this, args);
3540
+ }
3541
+ const innermost = enclosing[enclosing.length - 1];
3542
+ const innermostNow = currentAutoTraceEntries().find(
3543
+ (entry) => entry.context === innermost.context
3544
+ ) ?? innermost;
3545
+ const innermostStack = innermostNow.spanStack;
3546
+ const copy = innermostStack[innermostStack.length - 1];
3547
+ const detachedRoot = buildTracedRoot({
3548
+ ...rootOptions,
3549
+ ...copy !== void 0 && {
3550
+ enclosingTrace: {
3551
+ traceId: copy.traceId,
3552
+ spanId: copy.spanId,
3553
+ traceFunctionKey: innermost.context.traceFunctionKey,
3554
+ link
3555
+ }
3556
+ }
3557
+ });
3558
+ return runWithSpanStack([], () => detachedRoot.apply(this, args));
3559
+ }
3560
+ );
3256
3561
  };
3257
3562
  Object.defineProperty(autoTraceRoot, "_bitfabTraceFunctionKey", {
3258
3563
  value: traceFunctionKey
@@ -3330,7 +3635,7 @@ var Bitfab = class {
3330
3635
  return this.resolvedApiKey;
3331
3636
  }
3332
3637
  const fromConfig = typeof this.apiKeyConfig === "function" ? this.apiKeyConfig() : this.apiKeyConfig;
3333
- const candidate = fromConfig && fromConfig.trim() !== "" ? fromConfig : readEnv("BITFAB_API_KEY");
3638
+ const candidate = fromConfig && fromConfig.trim() !== "" ? fromConfig : readEnv2("BITFAB_API_KEY");
3334
3639
  const key = candidate && candidate.trim() !== "" ? candidate : void 0;
3335
3640
  if (key) {
3336
3641
  this.resolvedApiKey = key;
@@ -3841,6 +4146,10 @@ var Bitfab = class {
3841
4146
  const spanId = randomUuid();
3842
4147
  const parentSpanId = parentContext?.spanId ?? null;
3843
4148
  const isRootSpan = parentSpanId === null;
4149
+ if (options.enclosingTrace !== void 0) {
4150
+ options.enclosingTrace.link.traceId = traceId;
4151
+ options.enclosingTrace.link.rootSpanId = spanId;
4152
+ }
3844
4153
  const requestedSurface = options.surface ?? DEFAULT_SURFACE;
3845
4154
  const surface = resolveSurface(requestedSurface, parentContext?.surface);
3846
4155
  assertSurfacesCompatible(
@@ -3890,7 +4199,9 @@ var Bitfab = class {
3890
4199
  spanType: options.type ?? "custom",
3891
4200
  functionId: options.functionId,
3892
4201
  captureContent: options.captureContent ?? true,
3893
- autoTraceDefinition: options.autoTraceDefinition
4202
+ autoTraceDefinition: options.autoTraceDefinition,
4203
+ nestedTrace: options.nestedTrace,
4204
+ enclosingTrace: options.enclosingTrace
3894
4205
  };
3895
4206
  const sendSpan = async (params) => {
3896
4207
  const replayCtx = getReplayContext();
@@ -4088,15 +4399,15 @@ var Bitfab = class {
4088
4399
  );
4089
4400
  }
4090
4401
  return runWithSpanStack(newStack, async () => {
4091
- const resolved = await resolution;
4092
- if (resolved.matched) {
4402
+ const resolved2 = await resolution;
4403
+ if (resolved2.matched) {
4093
4404
  void sendSpan({
4094
- result: resolved.output,
4405
+ result: resolved2.output,
4095
4406
  mocked: true,
4096
4407
  mockTarget: "output",
4097
4408
  mockSource: "override"
4098
4409
  });
4099
- return resolved.output;
4410
+ return resolved2.output;
4100
4411
  }
4101
4412
  if (shouldMockWithBaseStrategy && !mockSpan) {
4102
4413
  throw new BitfabError(
@@ -4332,6 +4643,10 @@ var Bitfab = class {
4332
4643
  if (params.dbSnapshotRef) {
4333
4644
  rawTrace.db_snapshot_ref = params.dbSnapshotRef;
4334
4645
  }
4646
+ const commitRef = currentCommitRef();
4647
+ if (commitRef) {
4648
+ rawTrace.commit_ref = commitRefWire(commitRef);
4649
+ }
4335
4650
  if (params.ingestionType) {
4336
4651
  rawTrace.ingestion_type = params.ingestionType;
4337
4652
  }
@@ -4396,6 +4711,16 @@ var Bitfab = class {
4396
4711
  function_line: params.autoTraceDefinition.line,
4397
4712
  function_column: params.autoTraceDefinition.column
4398
4713
  },
4714
+ ...params.nestedTrace?.traceId !== void 0 && {
4715
+ nested_trace_id: params.nestedTrace.traceId,
4716
+ nested_trace_function_key: params.nestedTrace.traceFunctionKey,
4717
+ nested_root_span_id: params.nestedTrace.rootSpanId
4718
+ },
4719
+ ...params.enclosingTrace !== void 0 && {
4720
+ enclosing_trace_id: params.enclosingTrace.traceId,
4721
+ enclosing_trace_function_key: params.enclosingTrace.traceFunctionKey,
4722
+ enclosing_span_id: params.enclosingTrace.spanId
4723
+ },
4399
4724
  ...serializedInputs !== void 0 && {
4400
4725
  input: serializedInputs.json,
4401
4726
  ...serializedInputs.meta !== void 0 && {
@@ -4577,7 +4902,7 @@ var Bitfab = class {
4577
4902
  await runWithSeedContext({ traceId }, async () => target(...args));
4578
4903
  } finally {
4579
4904
  try {
4580
- const { flushTraces: flushTraces2 } = await import("./http-RFNQ7LSU.js");
4905
+ const { flushTraces: flushTraces2 } = await import("./http-MGES3ZVX.js");
4581
4906
  await flushTraces2(3e4);
4582
4907
  } finally {
4583
4908
  unrecorded = activeTraceStates.delete(traceId);
@@ -4636,7 +4961,7 @@ var Bitfab = class {
4636
4961
  `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.`
4637
4962
  );
4638
4963
  }
4639
- const { replay: doReplay } = await import("./replay-ZOTYMBMD.js");
4964
+ const { replay: doReplay } = await import("./replay-5XES2LBL.js");
4640
4965
  return doReplay(
4641
4966
  this.httpClient,
4642
4967
  this.serviceUrl,
@@ -4920,7 +5245,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
4920
5245
  sessionId: seedCase.sessionId
4921
5246
  })
4922
5247
  );
4923
- const { flushTraces: flushTraces2 } = await import("./http-RFNQ7LSU.js");
5248
+ const { flushTraces: flushTraces2 } = await import("./http-MGES3ZVX.js");
4924
5249
  await flushTraces2(3e4);
4925
5250
  return { pipeline, traceFunctionKey, traceIds };
4926
5251
  }
@@ -4957,4 +5282,4 @@ export {
4957
5282
  reseedFromRegistry,
4958
5283
  seedFromRegistry
4959
5284
  };
4960
- //# sourceMappingURL=chunk-AUROMI67.js.map
5285
+ //# sourceMappingURL=chunk-P26KVTI5.js.map