bitfab 0.52.1 → 0.52.3

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.
package/dist/index.d.cts CHANGED
@@ -1656,12 +1656,16 @@ interface ReplayOptions {
1656
1656
  * Maximum number of traces to replay (1-5,000, default 5). Ignored when
1657
1657
  * `traceIds` is passed (with a warning), or when `datasetId` / `datasetIds`
1658
1658
  * is passed, because either source already determines how many traces replay.
1659
+ * To replay part of a dataset selection, name the members to run in
1660
+ * `traceIds` rather than bounding it here.
1659
1661
  */
1660
1662
  limit?: number;
1661
1663
  attempts?: number;
1662
1664
  /**
1663
- * Optional list of specific trace IDs to replay (max 100). Mutually exclusive
1664
- * with `datasetId` and `datasetIds`.
1665
+ * Optional list of specific trace IDs to replay (max 100). Passed alongside
1666
+ * `datasetId` or `datasetIds` it pins which members of that selection replay,
1667
+ * and the server rejects any ID none of those datasets contains. On its own
1668
+ * it selects by ID with no dataset attribution.
1665
1669
  */
1666
1670
  traceIds?: string[];
1667
1671
  /** Optional display name for the resulting experiment/test run. */
@@ -1719,8 +1723,9 @@ interface ReplayOptions {
1719
1723
  /** Group ID to associate this replay with an experiment group for live streaming in Studio. */
1720
1724
  experimentGroupId?: string;
1721
1725
  /**
1722
- * Dataset this replay runs against. Mutually exclusive with `traceIds` and
1723
- * with `datasetIds`. When set, the resulting experiment is
1726
+ * Dataset this replay runs against. Mutually exclusive with `datasetIds`.
1727
+ * Alone it replays the dataset's full membership, and with `traceIds` it
1728
+ * replays only those members. When set, the resulting experiment is
1724
1729
  * durably attributed to the dataset (stored on the test run), so it appears
1725
1730
  * under the dataset's experiments even if the trace lineage can't be
1726
1731
  * reconstructed. Validated server-side against the org.
@@ -3288,7 +3293,7 @@ declare class BitfabFunction {
3288
3293
  /**
3289
3294
  * SDK version from package.json (injected at build time)
3290
3295
  */
3291
- declare const __version__ = "0.52.1";
3296
+ declare const __version__ = "0.52.3";
3292
3297
 
3293
3298
  /**
3294
3299
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -1656,12 +1656,16 @@ interface ReplayOptions {
1656
1656
  * Maximum number of traces to replay (1-5,000, default 5). Ignored when
1657
1657
  * `traceIds` is passed (with a warning), or when `datasetId` / `datasetIds`
1658
1658
  * is passed, because either source already determines how many traces replay.
1659
+ * To replay part of a dataset selection, name the members to run in
1660
+ * `traceIds` rather than bounding it here.
1659
1661
  */
1660
1662
  limit?: number;
1661
1663
  attempts?: number;
1662
1664
  /**
1663
- * Optional list of specific trace IDs to replay (max 100). Mutually exclusive
1664
- * with `datasetId` and `datasetIds`.
1665
+ * Optional list of specific trace IDs to replay (max 100). Passed alongside
1666
+ * `datasetId` or `datasetIds` it pins which members of that selection replay,
1667
+ * and the server rejects any ID none of those datasets contains. On its own
1668
+ * it selects by ID with no dataset attribution.
1665
1669
  */
1666
1670
  traceIds?: string[];
1667
1671
  /** Optional display name for the resulting experiment/test run. */
@@ -1719,8 +1723,9 @@ interface ReplayOptions {
1719
1723
  /** Group ID to associate this replay with an experiment group for live streaming in Studio. */
1720
1724
  experimentGroupId?: string;
1721
1725
  /**
1722
- * Dataset this replay runs against. Mutually exclusive with `traceIds` and
1723
- * with `datasetIds`. When set, the resulting experiment is
1726
+ * Dataset this replay runs against. Mutually exclusive with `datasetIds`.
1727
+ * Alone it replays the dataset's full membership, and with `traceIds` it
1728
+ * replays only those members. When set, the resulting experiment is
1724
1729
  * durably attributed to the dataset (stored on the test run), so it appears
1725
1730
  * under the dataset's experiments even if the trace lineage can't be
1726
1731
  * reconstructed. Validated server-side against the org.
@@ -3288,7 +3293,7 @@ declare class BitfabFunction {
3288
3293
  /**
3289
3294
  * SDK version from package.json (injected at build time)
3290
3295
  */
3291
- declare const __version__ = "0.52.1";
3296
+ declare const __version__ = "0.52.3";
3292
3297
 
3293
3298
  /**
3294
3299
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  getCurrentSpan,
28
28
  getCurrentTrace,
29
29
  seedFromRegistry
30
- } from "./chunk-XEARN7AS.js";
30
+ } from "./chunk-EAET3MSX.js";
31
31
  import "./chunk-ZUD7OFYB.js";
32
32
  import {
33
33
  BITFAB_PROGRESS_PREFIX,
@@ -36,7 +36,7 @@ import {
36
36
  ReplayError,
37
37
  reportReplayProgress,
38
38
  serializeReplayResult
39
- } from "./chunk-6SYDHA4R.js";
39
+ } from "./chunk-NZGYJWHY.js";
40
40
  import {
41
41
  BitfabError,
42
42
  DEFAULT_SERVICE_URL,
@@ -44,7 +44,7 @@ import {
44
44
  MixedTracingError,
45
45
  __version__,
46
46
  flushTraces
47
- } from "./chunk-SPJPNJEW.js";
47
+ } from "./chunk-XRSOWDOP.js";
48
48
  import "./chunk-H6LZRFMN.js";
49
49
  export {
50
50
  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.1";
100
+ __version__ = "0.52.3";
101
101
  __packageName__ = "bitfab";
102
102
  }
103
103
  });
@@ -401,15 +401,18 @@ var init_payloadBudget = __esm({
401
401
  });
402
402
 
403
403
  // src/warnOnce.ts
404
+ function warn(message) {
405
+ try {
406
+ console.warn(`[bitfab] ${message}`);
407
+ } catch {
408
+ }
409
+ }
404
410
  function warnOnce(key, message) {
405
411
  if (warned.has(key)) {
406
412
  return;
407
413
  }
408
414
  warned.add(key);
409
- try {
410
- console.warn(`[bitfab] ${message}`);
411
- } catch {
412
- }
415
+ warn(message);
413
416
  }
414
417
  var warned;
415
418
  var init_warnOnce = __esm({
@@ -551,6 +554,9 @@ var init_serializePayload = __esm({
551
554
  });
552
555
 
553
556
  // src/traceMetadata.ts
557
+ function findRecord(traceId) {
558
+ return activeRecords.get(traceId) ?? completedRecords.get(traceId);
559
+ }
554
560
  function recordCallerTraceMetadata(traceId, metadata) {
555
561
  if (typeof traceId !== "string" || traceId === "") {
556
562
  return;
@@ -561,15 +567,52 @@ function recordCallerTraceMetadata(traceId, metadata) {
561
567
  if (Object.keys(metadata).length === 0) {
562
568
  return;
563
569
  }
564
- callerMetadata.set(traceId, { ...callerMetadata.get(traceId), ...metadata });
570
+ const existing = findRecord(traceId);
571
+ if (existing) {
572
+ Object.assign(existing.caller, metadata);
573
+ return;
574
+ }
575
+ activeRecords.set(traceId, {
576
+ caller: { ...metadata },
577
+ derived: {},
578
+ warnedKeys: /* @__PURE__ */ new Set()
579
+ });
565
580
  }
566
581
  function callerTraceMetadata(traceId) {
567
- const recorded = callerMetadata.get(traceId);
568
- return recorded ? { ...recorded } : void 0;
582
+ const record = findRecord(traceId);
583
+ if (!record || Object.keys(record.caller).length === 0) {
584
+ return void 0;
585
+ }
586
+ return { ...record.caller };
569
587
  }
570
- function forgetTraceMetadata(traceId) {
571
- callerMetadata.delete(traceId);
572
- derivedMetadata.delete(traceId);
588
+ function retireTraceMetadata(traceId) {
589
+ const record = activeRecords.get(traceId);
590
+ if (!record) {
591
+ return;
592
+ }
593
+ activeRecords.delete(traceId);
594
+ completedRecords.set(traceId, record);
595
+ while (completedRecords.size > RETAINED_COMPLETED_TRACES) {
596
+ const oldest = completedRecords.keys().next();
597
+ if (oldest.done) {
598
+ return;
599
+ }
600
+ completedRecords.delete(oldest.value);
601
+ }
602
+ }
603
+ function warnAboutShadowedKeys(traceId, record) {
604
+ const shadowed = Object.keys(record.derived).filter(
605
+ (key) => key in record.caller && record.caller[key] !== record.derived[key] && !record.warnedKeys.has(key)
606
+ ).sort();
607
+ if (shadowed.length === 0) {
608
+ return;
609
+ }
610
+ for (const key of shadowed) {
611
+ record.warnedKeys.add(key);
612
+ }
613
+ warn(
614
+ `trace metadata key(s) ${shadowed.join(", ")} on trace ${traceId} were set both by the caller and by an integration's own trace export; the caller's value is the one kept on the trace.`
615
+ );
573
616
  }
574
617
  function mergeCallerMetadataIntoTracePayload(payload) {
575
618
  const externalTrace = payload.externalTrace;
@@ -581,35 +624,31 @@ function mergeCallerMetadataIntoTracePayload(payload) {
581
624
  if (typeof traceId !== "string" || traceId === "") {
582
625
  return payload;
583
626
  }
584
- const caller = callerMetadata.get(traceId);
585
- if (!caller) {
627
+ const record = findRecord(traceId);
628
+ if (!record || Object.keys(record.caller).length === 0) {
586
629
  return payload;
587
630
  }
588
- const derived = derivedMetadata.get(traceId) ?? {};
589
631
  const exported = external.metadata;
590
632
  if (typeof exported === "object" && exported !== null) {
591
- Object.assign(derived, exported);
592
- }
593
- derivedMetadata.set(traceId, derived);
594
- const shadowed = Object.keys(derived).filter((key) => key in caller && caller[key] !== derived[key]).sort();
595
- if (shadowed.length > 0) {
596
- warnOnce(
597
- `trace-metadata-shadowed:${shadowed.join(",")}`,
598
- `trace metadata key(s) ${shadowed.join(", ")} were set both by the caller and by an integration's own trace export; the caller's value is the one kept on the trace.`
599
- );
633
+ Object.assign(record.derived, exported);
600
634
  }
635
+ warnAboutShadowedKeys(traceId, record);
601
636
  return {
602
637
  ...payload,
603
- externalTrace: { ...external, metadata: { ...derived, ...caller } }
638
+ externalTrace: {
639
+ ...external,
640
+ metadata: { ...record.derived, ...record.caller }
641
+ }
604
642
  };
605
643
  }
606
- var callerMetadata, derivedMetadata;
644
+ var RETAINED_COMPLETED_TRACES, activeRecords, completedRecords;
607
645
  var init_traceMetadata = __esm({
608
646
  "src/traceMetadata.ts"() {
609
647
  "use strict";
610
648
  init_warnOnce();
611
- callerMetadata = /* @__PURE__ */ new Map();
612
- derivedMetadata = /* @__PURE__ */ new Map();
649
+ RETAINED_COMPLETED_TRACES = 128;
650
+ activeRecords = /* @__PURE__ */ new Map();
651
+ completedRecords = /* @__PURE__ */ new Map();
613
652
  }
614
653
  });
615
654
 
@@ -3009,11 +3048,6 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
3009
3048
  }
3010
3049
  }
3011
3050
  const datasetIds = resolveDatasetIds(options);
3012
- if (options?.traceIds !== void 0 && datasetIds !== void 0) {
3013
- throw new BitfabError(
3014
- "traceIds and datasetIds select different replay sources and cannot be used together."
3015
- );
3016
- }
3017
3051
  if (options?.limit !== void 0 && options?.traceIds !== void 0) {
3018
3052
  try {
3019
3053
  console.warn(
@@ -7486,7 +7520,7 @@ var Bitfab = class {
7486
7520
  }
7487
7521
  });
7488
7522
  activeTraceStates.delete(traceId);
7489
- forgetTraceMetadata(traceId);
7523
+ retireTraceMetadata(traceId);
7490
7524
  }
7491
7525
  } catch {
7492
7526
  }
@@ -7679,7 +7713,7 @@ var Bitfab = class {
7679
7713
  } catch (setupError) {
7680
7714
  if (registeredTraceId) {
7681
7715
  activeTraceStates.delete(registeredTraceId);
7682
- forgetTraceMetadata(registeredTraceId);
7716
+ retireTraceMetadata(registeredTraceId);
7683
7717
  }
7684
7718
  if (setupError instanceof MixedTracingError) {
7685
7719
  throw setupError;
@@ -8078,7 +8112,7 @@ var Bitfab = class {
8078
8112
  });
8079
8113
  } finally {
8080
8114
  activeTraceStates.delete(traceId);
8081
- forgetTraceMetadata(traceId);
8115
+ retireTraceMetadata(traceId);
8082
8116
  }
8083
8117
  return traceId;
8084
8118
  }
@@ -8124,7 +8158,7 @@ var Bitfab = class {
8124
8158
  await flushTraces2(3e4);
8125
8159
  } finally {
8126
8160
  unrecorded = activeTraceStates.delete(traceId);
8127
- forgetTraceMetadata(traceId);
8161
+ retireTraceMetadata(traceId);
8128
8162
  }
8129
8163
  }
8130
8164
  if (unrecorded) {