bitfab 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
@@ -27,7 +27,7 @@ import {
27
27
  getCurrentSpan,
28
28
  getCurrentTrace,
29
29
  seedFromRegistry
30
- } from "./chunk-KZKVSOBL.js";
30
+ } from "./chunk-XEARN7AS.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-LLS4QMFH.js";
39
+ } from "./chunk-6SYDHA4R.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-6M3EOIRH.js";
47
+ } from "./chunk-SPJPNJEW.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.0";
100
+ __version__ = "0.52.1";
101
101
  __packageName__ = "bitfab";
102
102
  }
103
103
  });
@@ -550,6 +550,69 @@ var init_serializePayload = __esm({
550
550
  }
551
551
  });
552
552
 
553
+ // src/traceMetadata.ts
554
+ function recordCallerTraceMetadata(traceId, metadata) {
555
+ if (typeof traceId !== "string" || traceId === "") {
556
+ return;
557
+ }
558
+ if (typeof metadata !== "object" || metadata === null) {
559
+ return;
560
+ }
561
+ if (Object.keys(metadata).length === 0) {
562
+ return;
563
+ }
564
+ callerMetadata.set(traceId, { ...callerMetadata.get(traceId), ...metadata });
565
+ }
566
+ function callerTraceMetadata(traceId) {
567
+ const recorded = callerMetadata.get(traceId);
568
+ return recorded ? { ...recorded } : void 0;
569
+ }
570
+ function forgetTraceMetadata(traceId) {
571
+ callerMetadata.delete(traceId);
572
+ derivedMetadata.delete(traceId);
573
+ }
574
+ function mergeCallerMetadataIntoTracePayload(payload) {
575
+ const externalTrace = payload.externalTrace;
576
+ if (typeof externalTrace !== "object" || externalTrace === null) {
577
+ return payload;
578
+ }
579
+ const external = externalTrace;
580
+ const traceId = typeof payload.id === "string" && payload.id !== "" ? payload.id : external.id;
581
+ if (typeof traceId !== "string" || traceId === "") {
582
+ return payload;
583
+ }
584
+ const caller = callerMetadata.get(traceId);
585
+ if (!caller) {
586
+ return payload;
587
+ }
588
+ const derived = derivedMetadata.get(traceId) ?? {};
589
+ const exported = external.metadata;
590
+ 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
+ );
600
+ }
601
+ return {
602
+ ...payload,
603
+ externalTrace: { ...external, metadata: { ...derived, ...caller } }
604
+ };
605
+ }
606
+ var callerMetadata, derivedMetadata;
607
+ var init_traceMetadata = __esm({
608
+ "src/traceMetadata.ts"() {
609
+ "use strict";
610
+ init_warnOnce();
611
+ callerMetadata = /* @__PURE__ */ new Map();
612
+ derivedMetadata = /* @__PURE__ */ new Map();
613
+ }
614
+ });
615
+
553
616
  // src/transportTypes.ts
554
617
  var DeliveryError;
555
618
  var init_transportTypes = __esm({
@@ -1368,6 +1431,7 @@ var init_http = __esm({
1368
1431
  init_errors();
1369
1432
  init_replayContext();
1370
1433
  init_serializePayload();
1434
+ init_traceMetadata();
1371
1435
  init_transport();
1372
1436
  init_transportTypes();
1373
1437
  init_unrefTimer();
@@ -1831,7 +1895,8 @@ var init_http = __esm({
1831
1895
  * {@link HttpClient.sendExternalSpan}; replay confirms persistence with the
1832
1896
  * server-authoritative barrier in `replay.ts`, not by awaiting this call.
1833
1897
  */
1834
- sendExternalTrace(payload) {
1898
+ sendExternalTrace(rawPayload) {
1899
+ const payload = mergeCallerMetadataIntoTracePayload(rawPayload);
1835
1900
  this.getTraceTransport()?.submit(
1836
1901
  "external_trace",
1837
1902
  {
@@ -5723,6 +5788,7 @@ function runWithSeedContext(ctx, fn) {
5723
5788
 
5724
5789
  // src/client.ts
5725
5790
  init_serialize();
5791
+ init_traceMetadata();
5726
5792
 
5727
5793
  // src/tracing.ts
5728
5794
  init_constants();
@@ -6403,8 +6469,7 @@ function getCurrentTrace() {
6403
6469
  if (typeof metadata !== "object" || metadata === null) {
6404
6470
  return;
6405
6471
  }
6406
- const traceState = getOrCreateTraceState();
6407
- traceState.metadata = { ...traceState.metadata, ...metadata };
6472
+ recordCallerTraceMetadata(traceId, metadata);
6408
6473
  } catch {
6409
6474
  }
6410
6475
  },
@@ -7397,7 +7462,7 @@ var Bitfab = class {
7397
7462
  endedAt,
7398
7463
  sessionId: traceState?.sessionId,
7399
7464
  name: traceState?.name,
7400
- metadata: traceState?.metadata,
7465
+ metadata: callerTraceMetadata(traceId),
7401
7466
  contexts: traceState?.contexts ?? [],
7402
7467
  testRunId: traceState?.testRunId,
7403
7468
  inputSourceTraceId: traceState?.inputSourceTraceId,
@@ -7421,6 +7486,7 @@ var Bitfab = class {
7421
7486
  }
7422
7487
  });
7423
7488
  activeTraceStates.delete(traceId);
7489
+ forgetTraceMetadata(traceId);
7424
7490
  }
7425
7491
  } catch {
7426
7492
  }
@@ -7613,6 +7679,7 @@ var Bitfab = class {
7613
7679
  } catch (setupError) {
7614
7680
  if (registeredTraceId) {
7615
7681
  activeTraceStates.delete(registeredTraceId);
7682
+ forgetTraceMetadata(registeredTraceId);
7616
7683
  }
7617
7684
  if (setupError instanceof MixedTracingError) {
7618
7685
  throw setupError;
@@ -7973,14 +8040,16 @@ var Bitfab = class {
7973
8040
  }
7974
8041
  const traceId = randomUuid();
7975
8042
  const startedAt = nowIsoTimestamp();
8043
+ if (options.metadata !== void 0) {
8044
+ recordCallerTraceMetadata(traceId, options.metadata);
8045
+ }
7976
8046
  activeTraceStates.set(traceId, {
7977
8047
  traceId,
7978
8048
  startedAt,
7979
8049
  contexts: [],
7980
8050
  ingestionType: "seeded",
7981
8051
  ...options.sessionId !== void 0 && { sessionId: options.sessionId },
7982
- ...options.name !== void 0 && { name: options.name },
7983
- ...options.metadata !== void 0 && { metadata: options.metadata }
8052
+ ...options.name !== void 0 && { name: options.name }
7984
8053
  });
7985
8054
  try {
7986
8055
  this.sendWrapperSpan({
@@ -8003,12 +8072,13 @@ var Bitfab = class {
8003
8072
  endedAt: startedAt,
8004
8073
  sessionId: options.sessionId,
8005
8074
  name: options.name,
8006
- metadata: options.metadata,
8075
+ metadata: callerTraceMetadata(traceId),
8007
8076
  contexts: [],
8008
8077
  ingestionType: "seeded"
8009
8078
  });
8010
8079
  } finally {
8011
8080
  activeTraceStates.delete(traceId);
8081
+ forgetTraceMetadata(traceId);
8012
8082
  }
8013
8083
  return traceId;
8014
8084
  }
@@ -8033,14 +8103,16 @@ var Bitfab = class {
8033
8103
  }
8034
8104
  await seedContextReady;
8035
8105
  const traceId = randomUuid();
8106
+ if (options?.metadata !== void 0) {
8107
+ recordCallerTraceMetadata(traceId, options.metadata);
8108
+ }
8036
8109
  activeTraceStates.set(traceId, {
8037
8110
  traceId,
8038
8111
  startedAt: nowIsoTimestamp(),
8039
8112
  contexts: [],
8040
8113
  ingestionType: "seeded",
8041
8114
  ...options?.sessionId !== void 0 && { sessionId: options.sessionId },
8042
- ...options?.name !== void 0 && { name: options.name },
8043
- ...options?.metadata !== void 0 && { metadata: options.metadata }
8115
+ ...options?.name !== void 0 && { name: options.name }
8044
8116
  });
8045
8117
  const args = options?.args ?? [];
8046
8118
  let unrecorded = true;
@@ -8052,6 +8124,7 @@ var Bitfab = class {
8052
8124
  await flushTraces2(3e4);
8053
8125
  } finally {
8054
8126
  unrecorded = activeTraceStates.delete(traceId);
8127
+ forgetTraceMetadata(traceId);
8055
8128
  }
8056
8129
  }
8057
8130
  if (unrecorded) {