@brizz/sdk 0.1.51 → 0.1.53

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.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  configure,
7
7
  getSDKVersion
8
- } from "./chunk-G6GTIFEQ.js";
8
+ } from "./chunk-XV3ZJO5K.js";
9
9
  import {
10
10
  DEFAULT_LOG_LEVEL,
11
11
  LogLevel,
@@ -426,6 +426,217 @@ function attachRunToIteration(stream, run) {
426
426
  return iterable;
427
427
  }
428
428
 
429
+ // src/internal/instrumentation/typesafe.ts
430
+ import { createRequire as createRequire2 } from "module";
431
+ import { SpanKind, SpanStatusCode as SpanStatusCode2, context as context2, trace as trace2 } from "@opentelemetry/api";
432
+ import {
433
+ InstrumentationBase as InstrumentationBase2,
434
+ InstrumentationNodeModuleDefinition as InstrumentationNodeModuleDefinition2
435
+ } from "@opentelemetry/instrumentation";
436
+ var INSTRUMENTATION_NAME2 = "@brizz/sdk/typesafe";
437
+ var MODULE_NAME2 = "@typesafe-ai/sdk";
438
+ var SUPPORTED_VERSIONS2 = [">=0.5.7 <1"];
439
+ var SPAN_NAME = "typesafe.system_one";
440
+ var PROVIDER_NAME = "typesafe";
441
+ var OPERATION_NAME = "classify";
442
+ var ATTR_OPERATION_NAME = "gen_ai.operation.name";
443
+ var ATTR_PROVIDER_NAME = "gen_ai.provider.name";
444
+ var ATTR_REQUEST_MODEL = "gen_ai.request.model";
445
+ var ATTR_RESPONSE_MODEL = "gen_ai.response.model";
446
+ var ATTR_INPUT_TOKENS = "gen_ai.usage.input_tokens";
447
+ var ATTR_OUTPUT_TOKENS = "gen_ai.usage.output_tokens";
448
+ var ATTR_INPUT_MESSAGES = "gen_ai.input.messages";
449
+ var ATTR_QUESTIONS = "typesafe.questions";
450
+ var ATTR_ANSWERS = "typesafe.answers";
451
+ var PATCHED_FLAG2 = /* @__PURE__ */ Symbol.for("brizz.typesafe.patched");
452
+ var TypeSafeInstrumentation = class extends InstrumentationBase2 {
453
+ constructor(config = {}) {
454
+ super(INSTRUMENTATION_NAME2, getSDKVersion(), config);
455
+ }
456
+ init() {
457
+ return [
458
+ new InstrumentationNodeModuleDefinition2(
459
+ MODULE_NAME2,
460
+ SUPPORTED_VERSIONS2,
461
+ (moduleExports) => {
462
+ this.manuallyInstrument(moduleExports);
463
+ return moduleExports;
464
+ },
465
+ (moduleExports) => moduleExports
466
+ )
467
+ ];
468
+ }
469
+ /**
470
+ * Patch a `@typesafe-ai/sdk` module the caller already imported. The
471
+ * module-load hook above only fires for CommonJS requires, so an ESM or
472
+ * bundled consumer reaches the instrumentation through here — from
473
+ * `patchInstalledTypeSafe`, or `instrumentModules: { typesafe }`.
474
+ */
475
+ manuallyInstrument(moduleExports) {
476
+ const client = moduleExports?.TypeSafeClient;
477
+ if (typeof client !== "function" || !client.prototype) {
478
+ logger.debug("Brizz TypeSafe: module does not expose TypeSafeClient \u2014 skipping patch");
479
+ return;
480
+ }
481
+ if (patchSystemOne(client.prototype, () => this.tracer)) {
482
+ logger.debug("Brizz TypeSafe: patched TypeSafeClient.systemOne");
483
+ }
484
+ }
485
+ };
486
+ function patchInstalledTypeSafe() {
487
+ let requireFromSdk;
488
+ let version;
489
+ try {
490
+ requireFromSdk = createRequire2(import.meta.url);
491
+ version = requireFromSdk(`${MODULE_NAME2}/package.json`).version;
492
+ } catch (error) {
493
+ logger.debug(`TypeSafe not resolved, not patched: ${String(error)}`);
494
+ return;
495
+ }
496
+ if (!isSupportedVersion2(version)) {
497
+ logger.debug(`TypeSafe ${version} is outside ${SUPPORTED_VERSIONS2.join(" ")}, not patched`);
498
+ return;
499
+ }
500
+ let instrumentation;
501
+ try {
502
+ instrumentation = new TypeSafeInstrumentation({ enabled: false });
503
+ } catch (error) {
504
+ logger.debug(`TypeSafe instrumentation not constructed: ${String(error)}`);
505
+ return;
506
+ }
507
+ try {
508
+ const loaded = requireFromSdk.cache[requireFromSdk.resolve(MODULE_NAME2)];
509
+ if (loaded) {
510
+ instrumentation.manuallyInstrument(loaded.exports);
511
+ }
512
+ } catch (error) {
513
+ logger.debug(`TypeSafe CJS build not patched: ${String(error)}`);
514
+ }
515
+ void (async () => {
516
+ try {
517
+ instrumentation.manuallyInstrument(await import("@typesafe-ai/sdk"));
518
+ } catch (error) {
519
+ logger.debug(`TypeSafe not patched: ${String(error)}`);
520
+ }
521
+ })();
522
+ }
523
+ function isSupportedVersion2(version) {
524
+ const [major, minor, patch] = version.split(".").map((part) => Number.parseInt(part, 10));
525
+ if ([major, minor, patch].some((part) => part === void 0 || Number.isNaN(part))) {
526
+ return false;
527
+ }
528
+ return major === 0 && (minor > 5 || minor === 5 && patch >= 7);
529
+ }
530
+ function patchSystemOne(proto, getTracer) {
531
+ const target = proto;
532
+ const original = proto.systemOne;
533
+ if (target[PATCHED_FLAG2] || typeof original !== "function") {
534
+ return false;
535
+ }
536
+ proto.systemOne = function brizzSystemOne(request, ...rest) {
537
+ const span = startSpan(getTracer, request);
538
+ if (!span) {
539
+ return original.call(this, request, ...rest);
540
+ }
541
+ let pending;
542
+ try {
543
+ pending = context2.with(
544
+ trace2.setSpan(context2.active(), span),
545
+ () => original.call(this, request, ...rest)
546
+ );
547
+ } catch (error) {
548
+ endSpan(span, error);
549
+ throw error;
550
+ }
551
+ return observe(pending, span);
552
+ };
553
+ target[PATCHED_FLAG2] = true;
554
+ return true;
555
+ }
556
+ function observe(pending, span) {
557
+ const onError = (error) => endSpan(span, error);
558
+ try {
559
+ if (typeof pending?.asResponse === "function") {
560
+ pending.asResponse().then((response) => {
561
+ if (typeof response?.clone !== "function") {
562
+ endSpan(span);
563
+ return;
564
+ }
565
+ response.clone().json().then((body) => {
566
+ recordResult(span, body);
567
+ endSpan(span);
568
+ }, onError);
569
+ }, onError);
570
+ return pending;
571
+ }
572
+ if (typeof pending?.then === "function") {
573
+ pending.then((result) => {
574
+ recordResult(span, result);
575
+ endSpan(span);
576
+ }, onError);
577
+ return pending;
578
+ }
579
+ } catch (error) {
580
+ logger.debug(`Brizz TypeSafe: could not observe the call: ${String(error)}`);
581
+ }
582
+ endSpan(span);
583
+ return pending;
584
+ }
585
+ function startSpan(getTracer, request) {
586
+ try {
587
+ const model = typeof request?.model === "string" && request.model !== "" ? request.model : void 0;
588
+ const attributes = {
589
+ [ATTR_OPERATION_NAME]: OPERATION_NAME,
590
+ [ATTR_PROVIDER_NAME]: PROVIDER_NAME,
591
+ [ATTR_INPUT_MESSAGES]: JSON.stringify([
592
+ { role: "user", parts: [{ type: "text", content: text(request?.state) }] }
593
+ ])
594
+ };
595
+ if (model) {
596
+ attributes[ATTR_REQUEST_MODEL] = model;
597
+ }
598
+ if (request?.questions !== void 0) {
599
+ attributes[ATTR_QUESTIONS] = JSON.stringify(request.questions);
600
+ }
601
+ return getTracer().startSpan(SPAN_NAME, { kind: SpanKind.CLIENT, attributes });
602
+ } catch (error) {
603
+ logger.debug(`Brizz TypeSafe: could not start span: ${String(error)}`);
604
+ return void 0;
605
+ }
606
+ }
607
+ function recordResult(span, result) {
608
+ try {
609
+ const { model, usage, answers } = result ?? {};
610
+ if (typeof model === "string" && model) {
611
+ span.setAttribute(ATTR_RESPONSE_MODEL, model);
612
+ }
613
+ if (typeof usage?.input_tokens === "number") {
614
+ span.setAttribute(ATTR_INPUT_TOKENS, usage.input_tokens);
615
+ }
616
+ if (typeof usage?.output_tokens === "number") {
617
+ span.setAttribute(ATTR_OUTPUT_TOKENS, usage.output_tokens);
618
+ }
619
+ if (answers !== void 0) {
620
+ span.setAttribute(ATTR_ANSWERS, JSON.stringify(answers));
621
+ }
622
+ } catch (error) {
623
+ logger.debug(`Brizz TypeSafe: could not record the answers: ${String(error)}`);
624
+ }
625
+ }
626
+ function endSpan(span, error) {
627
+ if (!span.isRecording()) {
628
+ return;
629
+ }
630
+ if (error !== void 0) {
631
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
632
+ span.setStatus({ code: SpanStatusCode2.ERROR, message: String(error) });
633
+ }
634
+ span.end();
635
+ }
636
+ function text(value) {
637
+ return typeof value === "string" ? value : JSON.stringify(value) ?? "";
638
+ }
639
+
429
640
  // src/internal/instrumentation/auto-init.ts
430
641
  var exceptionLogger = (error) => {
431
642
  logger.error(`Exception in instrumentation: ${String(error)}`);
@@ -468,7 +679,7 @@ function loadGenAIInstrumentations() {
468
679
  function loadMCPInstrumentation() {
469
680
  void (async () => {
470
681
  try {
471
- const { MCPInstrumentation } = await import("./mcp-2ZFV5BK5.js");
682
+ const { MCPInstrumentation } = await import("./mcp-DBLN5ZBE.js");
472
683
  const mcp = new MCPInstrumentation({ exceptionLogger });
473
684
  registerInstrumentations({ instrumentations: [mcp] });
474
685
  logger.debug("Auto-loaded MCP instrumentation");
@@ -487,6 +698,14 @@ function loadLangGraphInstrumentation() {
487
698
  logger.debug(`LangGraph instrumentation not loaded: ${String(error)}`);
488
699
  }
489
700
  }
701
+ function loadTypeSafeInstrumentation() {
702
+ try {
703
+ registerInstrumentations({ instrumentations: [new TypeSafeInstrumentation()] });
704
+ logger.debug("Auto-loaded TypeSafe instrumentation");
705
+ } catch (error) {
706
+ logger.debug(`TypeSafe instrumentation not loaded: ${String(error)}`);
707
+ }
708
+ }
490
709
  function loadVertexAIInstrumentation() {
491
710
  void (async () => {
492
711
  try {
@@ -565,6 +784,7 @@ function autoInitializeInstrumentations() {
565
784
  const genAIInstrumentations = loadGenAIInstrumentations();
566
785
  loadMCPInstrumentation();
567
786
  loadLangGraphInstrumentation();
787
+ loadTypeSafeInstrumentation();
568
788
  loadVertexAIInstrumentation();
569
789
  loadGoogleGenAIInstrumentation();
570
790
  loadVercelAITelemetry();
@@ -743,8 +963,8 @@ import { QdrantInstrumentation as QdrantInstrumentation2 } from "@traceloop/inst
743
963
  import { TogetherInstrumentation as TogetherInstrumentation2 } from "@traceloop/instrumentation-together";
744
964
 
745
965
  // src/internal/instrumentation/langchain.ts
746
- import { createRequire as createRequire2 } from "module";
747
- import { context as context2 } from "@opentelemetry/api";
966
+ import { createRequire as createRequire3 } from "module";
967
+ import { context as context3 } from "@opentelemetry/api";
748
968
  var SCOPE_NAME = "@arizeai/openinference-instrumentation-langchain";
749
969
  var PATCHED_MARKER = /* @__PURE__ */ Symbol.for("brizz.langchain.callbackManagerPatched");
750
970
  var OMITTED_KEYS = /* @__PURE__ */ new Set([
@@ -753,8 +973,11 @@ var OMITTED_KEYS = /* @__PURE__ */ new Set([
753
973
  ORGANIZATION_NAME,
754
974
  ORGANIZATION_DOMAIN
755
975
  ]);
976
+ var TOOL_CALL_ID_METADATA_KEY = "brizz_tool_call_id";
977
+ var TOOL_ID = "tool.id";
978
+ var TOOL_CALL_ID_ARG = 7;
756
979
  function runMetadataFromContext() {
757
- const bag = context2.active().getValue(PROPERTIES_CONTEXT_KEY);
980
+ const bag = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
758
981
  if (!bag) {
759
982
  return void 0;
760
983
  }
@@ -792,9 +1015,32 @@ function patchCallbackManagerModule(module2) {
792
1015
  }
793
1016
  return manager;
794
1017
  };
1018
+ patchToolStart(statics["prototype"]);
795
1019
  statics[PATCHED_MARKER] = true;
796
1020
  return true;
797
1021
  }
1022
+ function patchToolStart(prototype) {
1023
+ const proto = prototype;
1024
+ const original = proto?.["handleToolStart"];
1025
+ if (!proto || typeof original !== "function") {
1026
+ return;
1027
+ }
1028
+ const handleToolStart = original;
1029
+ proto["handleToolStart"] = function(...args) {
1030
+ try {
1031
+ const toolCallId = args[TOOL_CALL_ID_ARG];
1032
+ if (typeof toolCallId === "string" && toolCallId !== "") {
1033
+ this.addMetadata({ [TOOL_CALL_ID_METADATA_KEY]: toolCallId }, false);
1034
+ } else if (this.metadata && TOOL_CALL_ID_METADATA_KEY in this.metadata) {
1035
+ const rest = { ...this.metadata };
1036
+ delete rest[TOOL_CALL_ID_METADATA_KEY];
1037
+ this.metadata = rest;
1038
+ }
1039
+ } catch {
1040
+ }
1041
+ return handleToolStart.apply(this, args);
1042
+ };
1043
+ }
798
1044
  function patchInstalledCallbackManager() {
799
1045
  void (async () => {
800
1046
  try {
@@ -803,7 +1049,7 @@ function patchInstalledCallbackManager() {
803
1049
  logger.debug(`LangChain callback manager not patched: ${String(error)}`);
804
1050
  }
805
1051
  try {
806
- const requireFromSdk = createRequire2(import.meta.url);
1052
+ const requireFromSdk = createRequire3(import.meta.url);
807
1053
  patchCallbackManagerModule(requireFromSdk("@langchain/core/callbacks/manager"));
808
1054
  } catch (error) {
809
1055
  logger.debug(`LangChain CJS callback manager not patched: ${String(error)}`);
@@ -818,18 +1064,23 @@ function restampLangChainSpan(span) {
818
1064
  }
819
1065
  const attrs = span.attributes;
820
1066
  const metadata = attrs["metadata"];
821
- if (typeof metadata !== "string" || !metadata.includes(`"${BRIZZ}.`)) {
1067
+ if (typeof metadata !== "string" || !metadata.includes(`"${BRIZZ}.`) && !metadata.includes(`"${TOOL_CALL_ID_METADATA_KEY}"`)) {
822
1068
  return;
823
1069
  }
824
1070
  const parsed = JSON.parse(metadata);
825
1071
  if (typeof parsed !== "object" || parsed === null) {
826
1072
  return;
827
1073
  }
828
- for (const [key, value] of Object.entries(parsed)) {
1074
+ const entries = parsed;
1075
+ for (const [key, value] of Object.entries(entries)) {
829
1076
  if (key.startsWith(`${BRIZZ}.`) && value !== null && value !== void 0) {
830
1077
  attrs[key] = String(value);
831
1078
  }
832
1079
  }
1080
+ const toolCallId = entries[TOOL_CALL_ID_METADATA_KEY];
1081
+ if (typeof toolCallId === "string" && toolCallId !== "" && attrs[TOOL_ID] === void 0) {
1082
+ attrs[TOOL_ID] = toolCallId;
1083
+ }
833
1084
  } catch (error) {
834
1085
  logger.debug("Skipped LangChain span re-stamp", { err: error });
835
1086
  }
@@ -930,6 +1181,14 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
930
1181
  logger.error(`Failed to apply LangGraph instrumentation: ${String(error)}`);
931
1182
  }
932
1183
  }
1184
+ if (this.manualModules?.typesafe) {
1185
+ try {
1186
+ new TypeSafeInstrumentation().manuallyInstrument(this.manualModules.typesafe);
1187
+ logger.debug("Manual instrumentation enabled for TypeSafe");
1188
+ } catch (error) {
1189
+ logger.error(`Failed to apply TypeSafe instrumentation: ${String(error)}`);
1190
+ }
1191
+ }
933
1192
  if (this.manualModules?.google_vertexai) {
934
1193
  const vertexModule = this.manualModules.google_vertexai;
935
1194
  void (async () => {
@@ -964,7 +1223,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
964
1223
  const mcpModules = this.manualModules.mcp;
965
1224
  void (async () => {
966
1225
  try {
967
- const { MCPInstrumentation } = await import("./mcp-2ZFV5BK5.js");
1226
+ const { MCPInstrumentation } = await import("./mcp-DBLN5ZBE.js");
968
1227
  const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
969
1228
  instrumentation.manuallyInstrument(mcpModules);
970
1229
  logger.debug("Manual instrumentation enabled for MCP");
@@ -1007,9 +1266,9 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
1007
1266
  import { LoggerProvider } from "@opentelemetry/sdk-logs";
1008
1267
 
1009
1268
  // src/internal/trace/session.ts
1010
- import { context as context3, isSpanContextValid, trace as trace2, SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
1269
+ import { context as context4, isSpanContextValid, trace as trace3, SpanStatusCode as SpanStatusCode3 } from "@opentelemetry/api";
1011
1270
  function setCurrentSpanCustomProperties(properties) {
1012
- const current = trace2.getActiveSpan();
1271
+ const current = trace3.getActiveSpan();
1013
1272
  if (!current || !current.isRecording()) {
1014
1273
  return;
1015
1274
  }
@@ -1021,11 +1280,11 @@ function setCurrentSpanCustomProperties(properties) {
1021
1280
  }
1022
1281
  }
1023
1282
  function callWithProperties(properties, fn, thisArg, ...args) {
1024
- const base = context3.active();
1283
+ const base = context4.active();
1025
1284
  const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
1026
1285
  const merged = prev ? { ...prev, ...properties } : properties;
1027
1286
  const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
1028
- return context3.with(next, fn, thisArg, ...args);
1287
+ return context4.with(next, fn, thisArg, ...args);
1029
1288
  }
1030
1289
  function withProperties(properties, fn, thisArg) {
1031
1290
  return function wrapped(...args) {
@@ -1037,9 +1296,9 @@ function withProperties(properties, fn, thisArg) {
1037
1296
  );
1038
1297
  };
1039
1298
  }
1040
- function propagatePropertiesImperatively(properties, base = context3.active()) {
1299
+ function propagatePropertiesImperatively(properties, base = context4.active()) {
1041
1300
  try {
1042
- const manager = context3;
1301
+ const manager = context4;
1043
1302
  const mgr = manager._getContextManager?.();
1044
1303
  const store = mgr?._asyncLocalStorage;
1045
1304
  if (!store || typeof store.enterWith !== "function") {
@@ -1142,7 +1401,7 @@ function withServiceName(name, fn, thisArg) {
1142
1401
  return withProperties(serviceNameProperties(name), fn, thisArg);
1143
1402
  }
1144
1403
  function resolveServiceNameFromContext() {
1145
- const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
1404
+ const props = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
1146
1405
  return props?.[SERVICE_NAME];
1147
1406
  }
1148
1407
  function userProperties(user) {
@@ -1209,7 +1468,7 @@ function withMessageId(id, fn, thisArg) {
1209
1468
  return withProperties({ [MESSAGE_ID]: id }, fn, thisArg);
1210
1469
  }
1211
1470
  function inheritedMuteTools() {
1212
- const properties = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
1471
+ const properties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
1213
1472
  return properties?.[MUTE_TOOLS];
1214
1473
  }
1215
1474
  function muteProperties(options) {
@@ -1269,9 +1528,9 @@ var Session = class {
1269
1528
  * @param text - Text to append (null becomes a null/"hide marker")
1270
1529
  * @param context - Optional per-turn context bag to attach to this turn
1271
1530
  */
1272
- setInput(text, context7) {
1273
- this.inputs.push(text);
1274
- this.inputContexts.push(context7 ?? {});
1531
+ setInput(text2, context8) {
1532
+ this.inputs.push(text2);
1533
+ this.inputContexts.push(context8 ?? {});
1275
1534
  this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
1276
1535
  this.span.setAttribute(SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
1277
1536
  }
@@ -1285,9 +1544,9 @@ var Session = class {
1285
1544
  * @param text - Text to append (null becomes a null/"hide marker")
1286
1545
  * @param context - Optional per-turn context bag to attach to this turn
1287
1546
  */
1288
- setOutput(text, context7) {
1289
- this.outputs.push(text);
1290
- this.outputContexts.push(context7 ?? {});
1547
+ setOutput(text2, context8) {
1548
+ this.outputs.push(text2);
1549
+ this.outputContexts.push(context8 ?? {});
1291
1550
  this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
1292
1551
  this.span.setAttribute(SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
1293
1552
  }
@@ -1390,18 +1649,18 @@ var SessionTitle = class {
1390
1649
  }
1391
1650
  };
1392
1651
  function getActiveSession() {
1393
- return context3.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
1652
+ return context4.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
1394
1653
  }
1395
1654
  function resolveSessionIdFromContext() {
1396
1655
  const active = getActiveSession();
1397
1656
  if (active) {
1398
1657
  return active.sessionId;
1399
1658
  }
1400
- const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
1659
+ const props = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
1401
1660
  return props?.[SESSION_ID];
1402
1661
  }
1403
1662
  function resolveMessageIdFromContext() {
1404
- const props = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
1663
+ const props = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
1405
1664
  return props?.[MESSAGE_ID];
1406
1665
  }
1407
1666
  function emitExternalLink(sessionId, url, title, linkType) {
@@ -1583,14 +1842,14 @@ function recordMetricImpl(options) {
1583
1842
  );
1584
1843
  continue;
1585
1844
  }
1586
- let text = typeof attrValue === "string" ? attrValue : String(attrValue);
1587
- if (text.length > METRIC_ATTRIBUTE_VALUE_MAX_LEN) {
1845
+ let text2 = typeof attrValue === "string" ? attrValue : String(attrValue);
1846
+ if (text2.length > METRIC_ATTRIBUTE_VALUE_MAX_LEN) {
1588
1847
  logger.warn(
1589
1848
  `recordMetric(${name}) attribute ${JSON.stringify(normalizedKey)} exceeds ${METRIC_ATTRIBUTE_VALUE_MAX_LEN} characters; truncated.`
1590
1849
  );
1591
- text = text.slice(0, METRIC_ATTRIBUTE_VALUE_MAX_LEN);
1850
+ text2 = text2.slice(0, METRIC_ATTRIBUTE_VALUE_MAX_LEN);
1592
1851
  }
1593
- eventAttributes[`${METRIC_ATTRIBUTE_PREFIX}${normalizedKey}`] = text;
1852
+ eventAttributes[`${METRIC_ATTRIBUTE_PREFIX}${normalizedKey}`] = text2;
1594
1853
  accepted += 1;
1595
1854
  }
1596
1855
  }
@@ -1599,7 +1858,7 @@ function recordMetricImpl(options) {
1599
1858
  eventAttributes[METRIC_TRACE_ID] = traceId;
1600
1859
  }
1601
1860
  if (scope === METRIC_SCOPE_TRACE && traceId === void 0) {
1602
- const spanContext = trace2.getActiveSpan()?.spanContext();
1861
+ const spanContext = trace3.getActiveSpan()?.spanContext();
1603
1862
  if (!spanContext || !isSpanContextValid(spanContext)) {
1604
1863
  logger.warn(
1605
1864
  `recordMetric(${name}) called with scope 'trace' but no trace; metric dropped. Pass options.traceId, or call inside the span of the trace being scored.`
@@ -1615,7 +1874,7 @@ function recordMetricImpl(options) {
1615
1874
  );
1616
1875
  return;
1617
1876
  }
1618
- const base = context3.active();
1877
+ const base = context4.active();
1619
1878
  const ambient = base.getValue(PROPERTIES_CONTEXT_KEY);
1620
1879
  const properties = { ...ambient };
1621
1880
  if (sessionId === void 0) {
@@ -1628,7 +1887,7 @@ function recordMetricImpl(options) {
1628
1887
  properties[SERVICE_NAME] = options.serviceName;
1629
1888
  }
1630
1889
  try {
1631
- context3.with(
1890
+ context4.with(
1632
1891
  base.setValue(PROPERTIES_CONTEXT_KEY, properties),
1633
1892
  () => emitEvent(METRIC_EVENT_NAME, eventAttributes)
1634
1893
  );
@@ -1639,7 +1898,7 @@ function recordMetricImpl(options) {
1639
1898
  function startSession(sessionId, callback, extraProperties, options) {
1640
1899
  const isTitle = options?.mode === "title";
1641
1900
  const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
1642
- const tracer = trace2.getTracer("@brizz/sdk");
1901
+ const tracer = trace3.getTracer("@brizz/sdk");
1643
1902
  return tracer.startActiveSpan(spanName, (span) => {
1644
1903
  span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
1645
1904
  if (extraProperties) {
@@ -1658,8 +1917,8 @@ function startSession(sessionId, callback, extraProperties, options) {
1658
1917
  }
1659
1918
  }
1660
1919
  return callWithProperties(contextProperties, () => {
1661
- const sessionCtx = context3.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
1662
- return context3.with(sessionCtx, () => {
1920
+ const sessionCtx = context4.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
1921
+ return context4.with(sessionCtx, () => {
1663
1922
  try {
1664
1923
  const result = callback(session);
1665
1924
  if (result && typeof result.then === "function") {
@@ -1668,7 +1927,7 @@ function startSession(sessionId, callback, extraProperties, options) {
1668
1927
  return value;
1669
1928
  }).catch((error) => {
1670
1929
  span.recordException(error);
1671
- span.setStatus({ code: SpanStatusCode2.ERROR });
1930
+ span.setStatus({ code: SpanStatusCode3.ERROR });
1672
1931
  span.end();
1673
1932
  throw error;
1674
1933
  });
@@ -1677,7 +1936,7 @@ function startSession(sessionId, callback, extraProperties, options) {
1677
1936
  return result;
1678
1937
  } catch (error) {
1679
1938
  span.recordException(error);
1680
- span.setStatus({ code: SpanStatusCode2.ERROR });
1939
+ span.setStatus({ code: SpanStatusCode3.ERROR });
1681
1940
  span.end();
1682
1941
  throw error;
1683
1942
  }
@@ -1687,7 +1946,7 @@ function startSession(sessionId, callback, extraProperties, options) {
1687
1946
  }
1688
1947
  function startSessionTitle(callback, options) {
1689
1948
  const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
1690
- const tracer = trace2.getTracer("@brizz/sdk");
1949
+ const tracer = trace3.getTracer("@brizz/sdk");
1691
1950
  return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
1692
1951
  if (resolvedSessionId) {
1693
1952
  span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
@@ -1706,7 +1965,7 @@ function startSessionTitle(callback, options) {
1706
1965
  return value;
1707
1966
  }).catch((error) => {
1708
1967
  span.recordException(error);
1709
- span.setStatus({ code: SpanStatusCode2.ERROR });
1968
+ span.setStatus({ code: SpanStatusCode3.ERROR });
1710
1969
  span.end();
1711
1970
  throw error;
1712
1971
  });
@@ -1715,7 +1974,7 @@ function startSessionTitle(callback, options) {
1715
1974
  return result;
1716
1975
  } catch (error) {
1717
1976
  span.recordException(error);
1718
- span.setStatus({ code: SpanStatusCode2.ERROR });
1977
+ span.setStatus({ code: SpanStatusCode3.ERROR });
1719
1978
  span.end();
1720
1979
  throw error;
1721
1980
  }
@@ -1724,7 +1983,7 @@ function startSessionTitle(callback, options) {
1724
1983
  }
1725
1984
 
1726
1985
  // src/internal/log/processors/log-processor.ts
1727
- import { context as context4 } from "@opentelemetry/api";
1986
+ import { context as context5 } from "@opentelemetry/api";
1728
1987
  import { BatchLogRecordProcessor, SimpleLogRecordProcessor } from "@opentelemetry/sdk-logs";
1729
1988
 
1730
1989
  // src/internal/masking/patterns.ts
@@ -2108,10 +2367,12 @@ function maskValue(value, rule) {
2108
2367
  return maskStringByPatternBasedRule(value, rule);
2109
2368
  }
2110
2369
  if (typeof value === "boolean" || typeof value === "number") {
2111
- return maskStringByPatternBasedRule(String(value), rule);
2370
+ const masked = maskStringByPatternBasedRule(String(value), rule);
2371
+ return masked === String(value) ? value : masked;
2112
2372
  }
2113
2373
  if (Array.isArray(value)) {
2114
- return value.map((v) => maskStringByPatternBasedRule(String(v), rule));
2374
+ const masked = value.map((v) => maskStringByPatternBasedRule(String(v), rule));
2375
+ return masked.every((m, i) => m === String(value[i])) ? value : masked;
2115
2376
  }
2116
2377
  if (value !== null && typeof value === "object") {
2117
2378
  const result = {};
@@ -2162,7 +2423,7 @@ var BrizzSimpleLogRecordProcessor = class extends SimpleLogRecordProcessor {
2162
2423
  if (maskingConfig) {
2163
2424
  maskLog(logRecord, maskingConfig);
2164
2425
  }
2165
- const associationProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
2426
+ const associationProperties = context5.active().getValue(PROPERTIES_CONTEXT_KEY);
2166
2427
  if (associationProperties) {
2167
2428
  for (const [key, value] of Object.entries(associationProperties)) {
2168
2429
  logRecord.setAttribute(`${BRIZZ}.${key}`, value);
@@ -2182,7 +2443,7 @@ var BrizzBatchLogRecordProcessor = class extends BatchLogRecordProcessor {
2182
2443
  if (maskingConfig) {
2183
2444
  maskLog(logRecord, maskingConfig);
2184
2445
  }
2185
- const associationProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
2446
+ const associationProperties = context5.active().getValue(PROPERTIES_CONTEXT_KEY);
2186
2447
  if (associationProperties) {
2187
2448
  for (const [key, value] of Object.entries(associationProperties)) {
2188
2449
  logRecord.setAttribute(`${BRIZZ}.${key}`, value);
@@ -2669,13 +2930,13 @@ var BrizzSpanExporter = class {
2669
2930
  };
2670
2931
 
2671
2932
  // src/internal/trace/processors/span-processor.ts
2672
- import { context as context5 } from "@opentelemetry/api";
2933
+ import { context as context6 } from "@opentelemetry/api";
2673
2934
  import {
2674
2935
  BatchSpanProcessor,
2675
2936
  SimpleSpanProcessor
2676
2937
  } from "@opentelemetry/sdk-trace-base";
2677
2938
  function applyContextAttributes(span) {
2678
- const sessionProperties = context5.active().getValue(PROPERTIES_CONTEXT_KEY);
2939
+ const sessionProperties = context6.active().getValue(PROPERTIES_CONTEXT_KEY);
2679
2940
  if (sessionProperties) {
2680
2941
  for (const [key, value] of Object.entries(sessionProperties)) {
2681
2942
  span.setAttribute(`${BRIZZ}.${key}`, value);
@@ -2758,8 +3019,8 @@ function maskReadableSpan(span, config) {
2758
3019
  masked = maskAttributes(masked, config.rules);
2759
3020
  }
2760
3021
  if (!config.disableDefaultRules) {
2761
- const text = Object.fromEntries(Object.entries(masked).filter(([k]) => isText(attrs[k])));
2762
- Object.assign(masked, maskAttributes(text, DEFAULT_MASKING_RULES));
3022
+ const text2 = Object.fromEntries(Object.entries(masked).filter(([k]) => isText(attrs[k])));
3023
+ Object.assign(masked, maskAttributes(text2, DEFAULT_MASKING_RULES));
2763
3024
  }
2764
3025
  const maskedEntries = Object.entries(masked);
2765
3026
  for (const [k, v] of maskedEntries) {
@@ -2892,12 +3153,12 @@ function getSpanProcessor() {
2892
3153
 
2893
3154
  // src/internal/trace/agent.ts
2894
3155
  import { randomUUID } from "crypto";
2895
- import { context as context6, propagation } from "@opentelemetry/api";
3156
+ import { context as context7, propagation } from "@opentelemetry/api";
2896
3157
  function newInstanceId() {
2897
3158
  return randomUUID().replaceAll("-", "").slice(0, 8);
2898
3159
  }
2899
3160
  function activeProperties() {
2900
- return context6.active().getValue(PROPERTIES_CONTEXT_KEY) ?? {};
3161
+ return context7.active().getValue(PROPERTIES_CONTEXT_KEY) ?? {};
2901
3162
  }
2902
3163
  function encodeToken(agent) {
2903
3164
  const payload = {
@@ -2912,7 +3173,7 @@ function encodeToken(agent) {
2912
3173
  function currentTraceparent() {
2913
3174
  const carrier = {};
2914
3175
  try {
2915
- propagation.inject(context6.active(), carrier);
3176
+ propagation.inject(context7.active(), carrier);
2916
3177
  } catch {
2917
3178
  }
2918
3179
  return carrier["traceparent"] ?? "";
@@ -2956,7 +3217,7 @@ function resolveAgent(agent) {
2956
3217
  let parentId;
2957
3218
  let name;
2958
3219
  let sessionId = "";
2959
- let parentContext = context6.active();
3220
+ let parentContext = context7.active();
2960
3221
  if (options.token === void 0) {
2961
3222
  id = options.id || newInstanceId();
2962
3223
  parentId = options.parentId || activeProperties()[AGENT_ID] || "";
@@ -2993,7 +3254,7 @@ function startAgent(agent, callback) {
2993
3254
  return callback(unreadableAgent(agent));
2994
3255
  }
2995
3256
  const { id, parentId, name, properties, parentContext } = resolved;
2996
- return context6.with(
3257
+ return context7.with(
2997
3258
  parentContext,
2998
3259
  () => callWithProperties(properties, () => callback(agentHandle(id, parentId, name)))
2999
3260
  );
@@ -3049,6 +3310,7 @@ var _Brizz = class __Brizz {
3049
3310
  configure(resolveMcpSessionTracking(options.mcpSessionTracking));
3050
3311
  patchInstalledCallbackManager();
3051
3312
  patchInstalledLangGraph();
3313
+ patchInstalledTypeSafe();
3052
3314
  if (options.instrumentModules && Object.keys(options.instrumentModules).length > 0) {
3053
3315
  registry.setManualModules(options.instrumentModules);
3054
3316
  }