@bitfab/sdk 0.52.0 → 0.52.1

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
@@ -536,7 +536,7 @@ declare class HttpClient {
536
536
  * {@link HttpClient.sendExternalSpan}; replay confirms persistence with the
537
537
  * server-authoritative barrier in `replay.ts`, not by awaiting this call.
538
538
  */
539
- sendExternalTrace(payload: Record<string, unknown>): void;
539
+ sendExternalTrace(rawPayload: Record<string, unknown>): void;
540
540
  /**
541
541
  * Partial update of an existing trace identified by its Bitfab trace ID.
542
542
  * Used by the detached `client.getTrace(id)` handle.
@@ -3288,7 +3288,7 @@ declare class BitfabFunction {
3288
3288
  /**
3289
3289
  * SDK version from package.json (injected at build time)
3290
3290
  */
3291
- declare const __version__ = "0.52.0";
3291
+ declare const __version__ = "0.52.1";
3292
3292
 
3293
3293
  /**
3294
3294
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -536,7 +536,7 @@ declare class HttpClient {
536
536
  * {@link HttpClient.sendExternalSpan}; replay confirms persistence with the
537
537
  * server-authoritative barrier in `replay.ts`, not by awaiting this call.
538
538
  */
539
- sendExternalTrace(payload: Record<string, unknown>): void;
539
+ sendExternalTrace(rawPayload: Record<string, unknown>): void;
540
540
  /**
541
541
  * Partial update of an existing trace identified by its Bitfab trace ID.
542
542
  * Used by the detached `client.getTrace(id)` handle.
@@ -3288,7 +3288,7 @@ declare class BitfabFunction {
3288
3288
  /**
3289
3289
  * SDK version from package.json (injected at build time)
3290
3290
  */
3291
- declare const __version__ = "0.52.0";
3291
+ declare const __version__ = "0.52.1";
3292
3292
 
3293
3293
  /**
3294
3294
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  getCurrentSpan,
19
19
  getCurrentTrace,
20
20
  seedFromRegistry
21
- } from "./chunk-VEDTNQQE.js";
21
+ } from "./chunk-XAT6WLCS.js";
22
22
  import "./chunk-ZUD7OFYB.js";
23
23
  import {
24
24
  BITFAB_PROGRESS_PREFIX,
@@ -27,7 +27,7 @@ import {
27
27
  ReplayError,
28
28
  reportReplayProgress,
29
29
  serializeReplayResult
30
- } from "./chunk-SJ65MW4K.js";
30
+ } from "./chunk-A5UGSRMK.js";
31
31
  import {
32
32
  BitfabError,
33
33
  DEFAULT_SERVICE_URL,
@@ -35,7 +35,7 @@ import {
35
35
  MixedTracingError,
36
36
  __version__,
37
37
  flushTraces
38
- } from "./chunk-4EOEBN3M.js";
38
+ } from "./chunk-6DIR65JW.js";
39
39
  import "./chunk-H6LZRFMN.js";
40
40
  export {
41
41
  BITFAB_PROGRESS_PREFIX,
package/dist/node.cjs CHANGED
@@ -88,7 +88,7 @@ var __version__, __packageName__;
88
88
  var init_version_generated = __esm({
89
89
  "src/version.generated.ts"() {
90
90
  "use strict";
91
- __version__ = "0.52.0";
91
+ __version__ = "0.52.1";
92
92
  __packageName__ = "@bitfab/sdk";
93
93
  }
94
94
  });
@@ -541,6 +541,69 @@ var init_serializePayload = __esm({
541
541
  }
542
542
  });
543
543
 
544
+ // src/traceMetadata.ts
545
+ function recordCallerTraceMetadata(traceId, metadata) {
546
+ if (typeof traceId !== "string" || traceId === "") {
547
+ return;
548
+ }
549
+ if (typeof metadata !== "object" || metadata === null) {
550
+ return;
551
+ }
552
+ if (Object.keys(metadata).length === 0) {
553
+ return;
554
+ }
555
+ callerMetadata.set(traceId, { ...callerMetadata.get(traceId), ...metadata });
556
+ }
557
+ function callerTraceMetadata(traceId) {
558
+ const recorded = callerMetadata.get(traceId);
559
+ return recorded ? { ...recorded } : void 0;
560
+ }
561
+ function forgetTraceMetadata(traceId) {
562
+ callerMetadata.delete(traceId);
563
+ derivedMetadata.delete(traceId);
564
+ }
565
+ function mergeCallerMetadataIntoTracePayload(payload) {
566
+ const externalTrace = payload.externalTrace;
567
+ if (typeof externalTrace !== "object" || externalTrace === null) {
568
+ return payload;
569
+ }
570
+ const external = externalTrace;
571
+ const traceId = typeof payload.id === "string" && payload.id !== "" ? payload.id : external.id;
572
+ if (typeof traceId !== "string" || traceId === "") {
573
+ return payload;
574
+ }
575
+ const caller = callerMetadata.get(traceId);
576
+ if (!caller) {
577
+ return payload;
578
+ }
579
+ const derived = derivedMetadata.get(traceId) ?? {};
580
+ const exported = external.metadata;
581
+ if (typeof exported === "object" && exported !== null) {
582
+ Object.assign(derived, exported);
583
+ }
584
+ derivedMetadata.set(traceId, derived);
585
+ const shadowed = Object.keys(derived).filter((key) => key in caller && caller[key] !== derived[key]).sort();
586
+ if (shadowed.length > 0) {
587
+ warnOnce(
588
+ `trace-metadata-shadowed:${shadowed.join(",")}`,
589
+ `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.`
590
+ );
591
+ }
592
+ return {
593
+ ...payload,
594
+ externalTrace: { ...external, metadata: { ...derived, ...caller } }
595
+ };
596
+ }
597
+ var callerMetadata, derivedMetadata;
598
+ var init_traceMetadata = __esm({
599
+ "src/traceMetadata.ts"() {
600
+ "use strict";
601
+ init_warnOnce();
602
+ callerMetadata = /* @__PURE__ */ new Map();
603
+ derivedMetadata = /* @__PURE__ */ new Map();
604
+ }
605
+ });
606
+
544
607
  // src/transportTypes.ts
545
608
  var DeliveryError;
546
609
  var init_transportTypes = __esm({
@@ -1359,6 +1422,7 @@ var init_http = __esm({
1359
1422
  init_errors();
1360
1423
  init_replayContext();
1361
1424
  init_serializePayload();
1425
+ init_traceMetadata();
1362
1426
  init_transport();
1363
1427
  init_transportTypes();
1364
1428
  init_unrefTimer();
@@ -1822,7 +1886,8 @@ var init_http = __esm({
1822
1886
  * {@link HttpClient.sendExternalSpan}; replay confirms persistence with the
1823
1887
  * server-authoritative barrier in `replay.ts`, not by awaiting this call.
1824
1888
  */
1825
- sendExternalTrace(payload) {
1889
+ sendExternalTrace(rawPayload) {
1890
+ const payload = mergeCallerMetadataIntoTracePayload(rawPayload);
1826
1891
  this.getTraceTransport()?.submit(
1827
1892
  "external_trace",
1828
1893
  {
@@ -5714,6 +5779,7 @@ function runWithSeedContext(ctx, fn) {
5714
5779
 
5715
5780
  // src/client.ts
5716
5781
  init_serialize();
5782
+ init_traceMetadata();
5717
5783
 
5718
5784
  // src/tracing.ts
5719
5785
  init_constants();
@@ -6394,8 +6460,7 @@ function getCurrentTrace() {
6394
6460
  if (typeof metadata !== "object" || metadata === null) {
6395
6461
  return;
6396
6462
  }
6397
- const traceState = getOrCreateTraceState();
6398
- traceState.metadata = { ...traceState.metadata, ...metadata };
6463
+ recordCallerTraceMetadata(traceId, metadata);
6399
6464
  } catch {
6400
6465
  }
6401
6466
  },
@@ -7388,7 +7453,7 @@ var Bitfab = class {
7388
7453
  endedAt,
7389
7454
  sessionId: traceState?.sessionId,
7390
7455
  name: traceState?.name,
7391
- metadata: traceState?.metadata,
7456
+ metadata: callerTraceMetadata(traceId),
7392
7457
  contexts: traceState?.contexts ?? [],
7393
7458
  testRunId: traceState?.testRunId,
7394
7459
  inputSourceTraceId: traceState?.inputSourceTraceId,
@@ -7412,6 +7477,7 @@ var Bitfab = class {
7412
7477
  }
7413
7478
  });
7414
7479
  activeTraceStates.delete(traceId);
7480
+ forgetTraceMetadata(traceId);
7415
7481
  }
7416
7482
  } catch {
7417
7483
  }
@@ -7604,6 +7670,7 @@ var Bitfab = class {
7604
7670
  } catch (setupError) {
7605
7671
  if (registeredTraceId) {
7606
7672
  activeTraceStates.delete(registeredTraceId);
7673
+ forgetTraceMetadata(registeredTraceId);
7607
7674
  }
7608
7675
  if (setupError instanceof MixedTracingError) {
7609
7676
  throw setupError;
@@ -7964,14 +8031,16 @@ var Bitfab = class {
7964
8031
  }
7965
8032
  const traceId = randomUuid();
7966
8033
  const startedAt = nowIsoTimestamp();
8034
+ if (options.metadata !== void 0) {
8035
+ recordCallerTraceMetadata(traceId, options.metadata);
8036
+ }
7967
8037
  activeTraceStates.set(traceId, {
7968
8038
  traceId,
7969
8039
  startedAt,
7970
8040
  contexts: [],
7971
8041
  ingestionType: "seeded",
7972
8042
  ...options.sessionId !== void 0 && { sessionId: options.sessionId },
7973
- ...options.name !== void 0 && { name: options.name },
7974
- ...options.metadata !== void 0 && { metadata: options.metadata }
8043
+ ...options.name !== void 0 && { name: options.name }
7975
8044
  });
7976
8045
  try {
7977
8046
  this.sendWrapperSpan({
@@ -7994,12 +8063,13 @@ var Bitfab = class {
7994
8063
  endedAt: startedAt,
7995
8064
  sessionId: options.sessionId,
7996
8065
  name: options.name,
7997
- metadata: options.metadata,
8066
+ metadata: callerTraceMetadata(traceId),
7998
8067
  contexts: [],
7999
8068
  ingestionType: "seeded"
8000
8069
  });
8001
8070
  } finally {
8002
8071
  activeTraceStates.delete(traceId);
8072
+ forgetTraceMetadata(traceId);
8003
8073
  }
8004
8074
  return traceId;
8005
8075
  }
@@ -8024,14 +8094,16 @@ var Bitfab = class {
8024
8094
  }
8025
8095
  await seedContextReady;
8026
8096
  const traceId = randomUuid();
8097
+ if (options?.metadata !== void 0) {
8098
+ recordCallerTraceMetadata(traceId, options.metadata);
8099
+ }
8027
8100
  activeTraceStates.set(traceId, {
8028
8101
  traceId,
8029
8102
  startedAt: nowIsoTimestamp(),
8030
8103
  contexts: [],
8031
8104
  ingestionType: "seeded",
8032
8105
  ...options?.sessionId !== void 0 && { sessionId: options.sessionId },
8033
- ...options?.name !== void 0 && { name: options.name },
8034
- ...options?.metadata !== void 0 && { metadata: options.metadata }
8106
+ ...options?.name !== void 0 && { name: options.name }
8035
8107
  });
8036
8108
  const args = options?.args ?? [];
8037
8109
  let unrecorded = true;
@@ -8043,6 +8115,7 @@ var Bitfab = class {
8043
8115
  await flushTraces2(3e4);
8044
8116
  } finally {
8045
8117
  unrecorded = activeTraceStates.delete(traceId);
8118
+ forgetTraceMetadata(traceId);
8046
8119
  }
8047
8120
  }
8048
8121
  if (unrecorded) {