@brizz/sdk 0.1.52 → 0.1.54

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 (39) hide show
  1. package/README.md +38 -0
  2. package/dist/chunk-DBN4NKIG.js +107 -0
  3. package/dist/{chunk-KFETJN5M.cjs → chunk-FQBVTIBR.cjs} +7 -0
  4. package/dist/{chunk-2T7OEV33.cjs → chunk-KGNFUQ6Z.cjs} +1 -1
  5. package/dist/{chunk-W7VSQ4KQ.js → chunk-MLMF2O5P.js} +1 -1
  6. package/dist/chunk-VZJNEST4.cjs +107 -0
  7. package/dist/{chunk-TEY6FAVZ.js → chunk-YGLDHCWC.js} +7 -0
  8. package/dist/google-genai-44O4QORJ.cjs +11 -0
  9. package/dist/{google-genai-T7I4FFIP.js → google-genai-PERR37LR.js} +2 -1
  10. package/dist/google-genai.cjs +3 -2
  11. package/dist/google-genai.js +2 -1
  12. package/dist/index.cjs +510 -107
  13. package/dist/index.js +486 -83
  14. package/dist/{mcp-MVZSP5NE.cjs → mcp-4M4XL46N.cjs} +39 -16
  15. package/dist/{mcp-TOZFTC5Y.js → mcp-KU7MFTOB.js} +29 -6
  16. package/dist/types/cjs/index.d.ts +1 -1
  17. package/dist/types/cjs/internal/config.d.ts +1 -0
  18. package/dist/types/cjs/internal/instrumentation/openai.d.ts +5 -0
  19. package/dist/types/cjs/internal/instrumentation/registry.d.ts +1 -0
  20. package/dist/types/cjs/internal/instrumentation/typesafe.d.ts +34 -0
  21. package/dist/types/cjs/internal/log/logging.d.ts +1 -0
  22. package/dist/types/cjs/internal/metric/metrics.d.ts +1 -0
  23. package/dist/types/cjs/internal/sdk.d.ts +3 -0
  24. package/dist/types/cjs/internal/trace/index.d.ts +1 -0
  25. package/dist/types/cjs/internal/trace/provider.d.ts +15 -0
  26. package/dist/types/cjs/internal/trace/tracing.d.ts +1 -0
  27. package/dist/types/esm/index.d.ts +1 -1
  28. package/dist/types/esm/internal/config.d.ts +1 -0
  29. package/dist/types/esm/internal/instrumentation/openai.d.ts +5 -0
  30. package/dist/types/esm/internal/instrumentation/registry.d.ts +1 -0
  31. package/dist/types/esm/internal/instrumentation/typesafe.d.ts +34 -0
  32. package/dist/types/esm/internal/log/logging.d.ts +1 -0
  33. package/dist/types/esm/internal/metric/metrics.d.ts +1 -0
  34. package/dist/types/esm/internal/sdk.d.ts +3 -0
  35. package/dist/types/esm/internal/trace/index.d.ts +1 -0
  36. package/dist/types/esm/internal/trace/provider.d.ts +15 -0
  37. package/dist/types/esm/internal/trace/tracing.d.ts +1 -0
  38. package/package.json +22 -15
  39. package/dist/google-genai-LMEZ62FB.cjs +0 -10
package/dist/index.cjs CHANGED
@@ -5,7 +5,16 @@ var _chunkUNLNNKZ7cjs = require('./chunk-UNLNNKZ7.cjs');
5
5
 
6
6
 
7
7
 
8
- var _chunk2T7OEV33cjs = require('./chunk-2T7OEV33.cjs');
8
+ var _chunkKGNFUQ6Zcjs = require('./chunk-KGNFUQ6Z.cjs');
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ var _chunkVZJNEST4cjs = require('./chunk-VZJNEST4.cjs');
9
18
 
10
19
 
11
20
 
@@ -83,7 +92,6 @@ var _chunkRV7JIIDGcjs = require('./chunk-RV7JIIDG.cjs');
83
92
  var _chunkOBGZSXTJcjs = require('./chunk-OBGZSXTJ.cjs');
84
93
 
85
94
  // src/internal/instrumentation/auto-init.ts
86
- var _openinferenceinstrumentationopenai = require('@arizeai/openinference-instrumentation-openai');
87
95
  var _instrumentation = require('@opentelemetry/instrumentation');
88
96
  var _instrumentationanthropic = require('@traceloop/instrumentation-anthropic');
89
97
  var _instrumentationbedrock = require('@traceloop/instrumentation-bedrock');
@@ -104,7 +112,7 @@ var _api = require('@opentelemetry/api');
104
112
 
105
113
  // src/internal/instrumentation/langgraph/attributes.ts
106
114
  var INSTRUMENTATION_NAME = "@brizz/sdk/langgraph";
107
- var INSTRUMENTATION_VERSION = _chunk2T7OEV33cjs.getSDKVersion.call(void 0, );
115
+ var INSTRUMENTATION_VERSION = _chunkKGNFUQ6Zcjs.getSDKVersion.call(void 0, );
108
116
  var MODULE_NAME = "@langchain/langgraph";
109
117
  var SUPPORTED_VERSIONS = [">=0.2.0 <2"];
110
118
  function isSupportedVersion(version) {
@@ -174,6 +182,7 @@ var parentRecorded = /* @__PURE__ */ new WeakSet();
174
182
  var LangGraphInstrumentation = class extends _instrumentation.InstrumentationBase {
175
183
  constructor(config = {}) {
176
184
  super(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION, config);
185
+ this.setTracerProvider(_chunkVZJNEST4cjs.brizzTracerProvider);
177
186
  }
178
187
  init() {
179
188
  return [
@@ -426,6 +435,226 @@ function attachRunToIteration(stream, run) {
426
435
  return iterable;
427
436
  }
428
437
 
438
+ // src/internal/instrumentation/openai.ts
439
+ var _openinferenceinstrumentationopenai = require('@arizeai/openinference-instrumentation-openai');
440
+ var BrizzOpenAIInstrumentation = class extends _openinferenceinstrumentationopenai.OpenAIInstrumentation {
441
+ get tracer() {
442
+ return _chunkVZJNEST4cjs.brizzTracerProvider.getTracer(this.instrumentationName, this.instrumentationVersion);
443
+ }
444
+ };
445
+
446
+ // src/internal/instrumentation/typesafe.ts
447
+
448
+
449
+
450
+
451
+
452
+
453
+ var INSTRUMENTATION_NAME2 = "@brizz/sdk/typesafe";
454
+ var MODULE_NAME2 = "@typesafe-ai/sdk";
455
+ var SUPPORTED_VERSIONS2 = [">=0.5.7 <1"];
456
+ var SPAN_NAME = "typesafe.system_one";
457
+ var PROVIDER_NAME = "typesafe";
458
+ var OPERATION_NAME = "classify";
459
+ var ATTR_OPERATION_NAME = "gen_ai.operation.name";
460
+ var ATTR_PROVIDER_NAME = "gen_ai.provider.name";
461
+ var ATTR_REQUEST_MODEL = "gen_ai.request.model";
462
+ var ATTR_RESPONSE_MODEL = "gen_ai.response.model";
463
+ var ATTR_INPUT_TOKENS = "gen_ai.usage.input_tokens";
464
+ var ATTR_OUTPUT_TOKENS = "gen_ai.usage.output_tokens";
465
+ var ATTR_INPUT_MESSAGES = "gen_ai.input.messages";
466
+ var ATTR_QUESTIONS = "typesafe.questions";
467
+ var ATTR_ANSWERS = "typesafe.answers";
468
+ var PATCHED_FLAG2 = /* @__PURE__ */ Symbol.for("brizz.typesafe.patched");
469
+ var TypeSafeInstrumentation = class extends _instrumentation.InstrumentationBase {
470
+ constructor(config = {}) {
471
+ super(INSTRUMENTATION_NAME2, _chunkKGNFUQ6Zcjs.getSDKVersion.call(void 0, ), config);
472
+ this.setTracerProvider(_chunkVZJNEST4cjs.brizzTracerProvider);
473
+ }
474
+ init() {
475
+ return [
476
+ new (0, _instrumentation.InstrumentationNodeModuleDefinition)(
477
+ MODULE_NAME2,
478
+ SUPPORTED_VERSIONS2,
479
+ (moduleExports) => {
480
+ this.manuallyInstrument(moduleExports);
481
+ return moduleExports;
482
+ },
483
+ (moduleExports) => moduleExports
484
+ )
485
+ ];
486
+ }
487
+ /**
488
+ * Patch a `@typesafe-ai/sdk` module the caller already imported. The
489
+ * module-load hook above only fires for CommonJS requires, so an ESM or
490
+ * bundled consumer reaches the instrumentation through here — from
491
+ * `patchInstalledTypeSafe`, or `instrumentModules: { typesafe }`.
492
+ */
493
+ manuallyInstrument(moduleExports) {
494
+ const client = _optionalChain([moduleExports, 'optionalAccess', _19 => _19.TypeSafeClient]);
495
+ if (typeof client !== "function" || !client.prototype) {
496
+ _chunkWC573FCIcjs.logger.debug("Brizz TypeSafe: module does not expose TypeSafeClient \u2014 skipping patch");
497
+ return;
498
+ }
499
+ if (patchSystemOne(client.prototype, () => this.tracer)) {
500
+ _chunkWC573FCIcjs.logger.debug("Brizz TypeSafe: patched TypeSafeClient.systemOne");
501
+ }
502
+ }
503
+ };
504
+ function patchInstalledTypeSafe() {
505
+ let requireFromSdk;
506
+ let version;
507
+ try {
508
+ requireFromSdk = _module.createRequire.call(void 0, __filename);
509
+ version = requireFromSdk(`${MODULE_NAME2}/package.json`).version;
510
+ } catch (error) {
511
+ _chunkWC573FCIcjs.logger.debug(`TypeSafe not resolved, not patched: ${String(error)}`);
512
+ return;
513
+ }
514
+ if (!isSupportedVersion2(version)) {
515
+ _chunkWC573FCIcjs.logger.debug(`TypeSafe ${version} is outside ${SUPPORTED_VERSIONS2.join(" ")}, not patched`);
516
+ return;
517
+ }
518
+ let instrumentation;
519
+ try {
520
+ instrumentation = new TypeSafeInstrumentation({ enabled: false });
521
+ } catch (error) {
522
+ _chunkWC573FCIcjs.logger.debug(`TypeSafe instrumentation not constructed: ${String(error)}`);
523
+ return;
524
+ }
525
+ try {
526
+ const loaded = requireFromSdk.cache[requireFromSdk.resolve(MODULE_NAME2)];
527
+ if (loaded) {
528
+ instrumentation.manuallyInstrument(loaded.exports);
529
+ }
530
+ } catch (error) {
531
+ _chunkWC573FCIcjs.logger.debug(`TypeSafe CJS build not patched: ${String(error)}`);
532
+ }
533
+ void (async () => {
534
+ try {
535
+ instrumentation.manuallyInstrument(await Promise.resolve().then(() => _interopRequireWildcard(require("@typesafe-ai/sdk"))));
536
+ } catch (error) {
537
+ _chunkWC573FCIcjs.logger.debug(`TypeSafe not patched: ${String(error)}`);
538
+ }
539
+ })();
540
+ }
541
+ function isSupportedVersion2(version) {
542
+ const [major, minor, patch] = version.split(".").map((part) => Number.parseInt(part, 10));
543
+ if ([major, minor, patch].some((part) => part === void 0 || Number.isNaN(part))) {
544
+ return false;
545
+ }
546
+ return major === 0 && (minor > 5 || minor === 5 && patch >= 7);
547
+ }
548
+ function patchSystemOne(proto, getTracer) {
549
+ const target = proto;
550
+ const original = proto.systemOne;
551
+ if (target[PATCHED_FLAG2] || typeof original !== "function") {
552
+ return false;
553
+ }
554
+ proto.systemOne = function brizzSystemOne(request, ...rest) {
555
+ const span = startSpan(getTracer, request);
556
+ if (!span) {
557
+ return original.call(this, request, ...rest);
558
+ }
559
+ let pending;
560
+ try {
561
+ pending = _api.context.with(
562
+ _api.trace.setSpan(_api.context.active(), span),
563
+ () => original.call(this, request, ...rest)
564
+ );
565
+ } catch (error) {
566
+ endSpan(span, error);
567
+ throw error;
568
+ }
569
+ return observe(pending, span);
570
+ };
571
+ target[PATCHED_FLAG2] = true;
572
+ return true;
573
+ }
574
+ function observe(pending, span) {
575
+ const onError = (error) => endSpan(span, error);
576
+ try {
577
+ if (typeof _optionalChain([pending, 'optionalAccess', _20 => _20.asResponse]) === "function") {
578
+ pending.asResponse().then((response) => {
579
+ if (typeof _optionalChain([response, 'optionalAccess', _21 => _21.clone]) !== "function") {
580
+ endSpan(span);
581
+ return;
582
+ }
583
+ response.clone().json().then((body) => {
584
+ recordResult(span, body);
585
+ endSpan(span);
586
+ }, onError);
587
+ }, onError);
588
+ return pending;
589
+ }
590
+ if (typeof _optionalChain([pending, 'optionalAccess', _22 => _22.then]) === "function") {
591
+ pending.then((result) => {
592
+ recordResult(span, result);
593
+ endSpan(span);
594
+ }, onError);
595
+ return pending;
596
+ }
597
+ } catch (error) {
598
+ _chunkWC573FCIcjs.logger.debug(`Brizz TypeSafe: could not observe the call: ${String(error)}`);
599
+ }
600
+ endSpan(span);
601
+ return pending;
602
+ }
603
+ function startSpan(getTracer, request) {
604
+ try {
605
+ const model = typeof _optionalChain([request, 'optionalAccess', _23 => _23.model]) === "string" && request.model !== "" ? request.model : void 0;
606
+ const attributes = {
607
+ [ATTR_OPERATION_NAME]: OPERATION_NAME,
608
+ [ATTR_PROVIDER_NAME]: PROVIDER_NAME,
609
+ [ATTR_INPUT_MESSAGES]: JSON.stringify([
610
+ { role: "user", parts: [{ type: "text", content: text(_optionalChain([request, 'optionalAccess', _24 => _24.state])) }] }
611
+ ])
612
+ };
613
+ if (model) {
614
+ attributes[ATTR_REQUEST_MODEL] = model;
615
+ }
616
+ if (_optionalChain([request, 'optionalAccess', _25 => _25.questions]) !== void 0) {
617
+ attributes[ATTR_QUESTIONS] = JSON.stringify(request.questions);
618
+ }
619
+ return getTracer().startSpan(SPAN_NAME, { kind: _api.SpanKind.CLIENT, attributes });
620
+ } catch (error) {
621
+ _chunkWC573FCIcjs.logger.debug(`Brizz TypeSafe: could not start span: ${String(error)}`);
622
+ return void 0;
623
+ }
624
+ }
625
+ function recordResult(span, result) {
626
+ try {
627
+ const { model, usage, answers } = _nullishCoalesce(result, () => ( {}));
628
+ if (typeof model === "string" && model) {
629
+ span.setAttribute(ATTR_RESPONSE_MODEL, model);
630
+ }
631
+ if (typeof _optionalChain([usage, 'optionalAccess', _26 => _26.input_tokens]) === "number") {
632
+ span.setAttribute(ATTR_INPUT_TOKENS, usage.input_tokens);
633
+ }
634
+ if (typeof _optionalChain([usage, 'optionalAccess', _27 => _27.output_tokens]) === "number") {
635
+ span.setAttribute(ATTR_OUTPUT_TOKENS, usage.output_tokens);
636
+ }
637
+ if (answers !== void 0) {
638
+ span.setAttribute(ATTR_ANSWERS, JSON.stringify(answers));
639
+ }
640
+ } catch (error) {
641
+ _chunkWC573FCIcjs.logger.debug(`Brizz TypeSafe: could not record the answers: ${String(error)}`);
642
+ }
643
+ }
644
+ function endSpan(span, error) {
645
+ if (!span.isRecording()) {
646
+ return;
647
+ }
648
+ if (error !== void 0) {
649
+ span.recordException(error instanceof Error ? error : new Error(String(error)));
650
+ span.setStatus({ code: _api.SpanStatusCode.ERROR, message: String(error) });
651
+ }
652
+ span.end();
653
+ }
654
+ function text(value) {
655
+ return typeof value === "string" ? value : _nullishCoalesce(JSON.stringify(value), () => ( ""));
656
+ }
657
+
429
658
  // src/internal/instrumentation/auto-init.ts
430
659
  var exceptionLogger = (error) => {
431
660
  _chunkWC573FCIcjs.logger.error(`Exception in instrumentation: ${String(error)}`);
@@ -433,7 +662,7 @@ var exceptionLogger = (error) => {
433
662
  function loadGenAIInstrumentations() {
434
663
  const instrumentations = [];
435
664
  try {
436
- instrumentations.push(new (0, _openinferenceinstrumentationopenai.OpenAIInstrumentation)());
665
+ instrumentations.push(new BrizzOpenAIInstrumentation());
437
666
  _chunkWC573FCIcjs.logger.debug("Auto-loaded OpenAI instrumentation");
438
667
  } catch (error) {
439
668
  _chunkWC573FCIcjs.logger.error(`Failed to auto-load OpenAI instrumentation: ${String(error)}`);
@@ -458,7 +687,7 @@ function loadGenAIInstrumentations() {
458
687
  }
459
688
  }
460
689
  try {
461
- _instrumentation.registerInstrumentations.call(void 0, { instrumentations });
690
+ _instrumentation.registerInstrumentations.call(void 0, { instrumentations, tracerProvider: _chunkVZJNEST4cjs.brizzTracerProvider });
462
691
  _chunkWC573FCIcjs.logger.info(`Auto-registered ${instrumentations.length} GenAI instrumentations`);
463
692
  } catch (error) {
464
693
  _chunkWC573FCIcjs.logger.error(`Failed to register GenAI instrumentations: ${String(error)}`);
@@ -468,9 +697,9 @@ function loadGenAIInstrumentations() {
468
697
  function loadMCPInstrumentation() {
469
698
  void (async () => {
470
699
  try {
471
- const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-MVZSP5NE.cjs")));
700
+ const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-4M4XL46N.cjs")));
472
701
  const mcp = new MCPInstrumentation({ exceptionLogger });
473
- _instrumentation.registerInstrumentations.call(void 0, { instrumentations: [mcp] });
702
+ _instrumentation.registerInstrumentations.call(void 0, { instrumentations: [mcp], tracerProvider: _chunkVZJNEST4cjs.brizzTracerProvider });
474
703
  _chunkWC573FCIcjs.logger.debug("Auto-loaded MCP instrumentation");
475
704
  } catch (error) {
476
705
  _chunkWC573FCIcjs.logger.debug(
@@ -481,18 +710,35 @@ function loadMCPInstrumentation() {
481
710
  }
482
711
  function loadLangGraphInstrumentation() {
483
712
  try {
484
- _instrumentation.registerInstrumentations.call(void 0, { instrumentations: [new LangGraphInstrumentation()] });
713
+ _instrumentation.registerInstrumentations.call(void 0, {
714
+ instrumentations: [new LangGraphInstrumentation()],
715
+ tracerProvider: _chunkVZJNEST4cjs.brizzTracerProvider
716
+ });
485
717
  _chunkWC573FCIcjs.logger.debug("Auto-loaded LangGraph instrumentation");
486
718
  } catch (error) {
487
719
  _chunkWC573FCIcjs.logger.debug(`LangGraph instrumentation not loaded: ${String(error)}`);
488
720
  }
489
721
  }
722
+ function loadTypeSafeInstrumentation() {
723
+ try {
724
+ _instrumentation.registerInstrumentations.call(void 0, {
725
+ instrumentations: [new TypeSafeInstrumentation()],
726
+ tracerProvider: _chunkVZJNEST4cjs.brizzTracerProvider
727
+ });
728
+ _chunkWC573FCIcjs.logger.debug("Auto-loaded TypeSafe instrumentation");
729
+ } catch (error) {
730
+ _chunkWC573FCIcjs.logger.debug(`TypeSafe instrumentation not loaded: ${String(error)}`);
731
+ }
732
+ }
490
733
  function loadVertexAIInstrumentation() {
491
734
  void (async () => {
492
735
  try {
493
736
  const { VertexAIInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("@traceloop/instrumentation-vertexai")));
494
737
  const vertexAI = new VertexAIInstrumentation({ exceptionLogger });
495
- _instrumentation.registerInstrumentations.call(void 0, { instrumentations: [vertexAI] });
738
+ _instrumentation.registerInstrumentations.call(void 0, {
739
+ instrumentations: [vertexAI],
740
+ tracerProvider: _chunkVZJNEST4cjs.brizzTracerProvider
741
+ });
496
742
  _chunkWC573FCIcjs.logger.debug("Auto-loaded Vertex AI instrumentation");
497
743
  } catch (error) {
498
744
  _chunkWC573FCIcjs.logger.debug(
@@ -504,9 +750,12 @@ function loadVertexAIInstrumentation() {
504
750
  function loadGoogleGenAIInstrumentation() {
505
751
  void (async () => {
506
752
  try {
507
- const { GoogleGenAIInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./google-genai-LMEZ62FB.cjs")));
753
+ const { GoogleGenAIInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./google-genai-44O4QORJ.cjs")));
508
754
  const googleGenAI = new GoogleGenAIInstrumentation({ exceptionLogger });
509
- _instrumentation.registerInstrumentations.call(void 0, { instrumentations: [googleGenAI] });
755
+ _instrumentation.registerInstrumentations.call(void 0, {
756
+ instrumentations: [googleGenAI],
757
+ tracerProvider: _chunkVZJNEST4cjs.brizzTracerProvider
758
+ });
510
759
  _chunkWC573FCIcjs.logger.debug("Auto-loaded Google GenAI instrumentation");
511
760
  } catch (error) {
512
761
  _chunkWC573FCIcjs.logger.debug(
@@ -538,7 +787,9 @@ function loadVercelAITelemetry() {
538
787
  try {
539
788
  const otel = await Promise.resolve().then(() => _interopRequireWildcard(require("@ai-sdk/otel")));
540
789
  if (typeof otel.LegacyOpenTelemetry === "function") {
541
- integrations.push(new otel.LegacyOpenTelemetry());
790
+ integrations.push(
791
+ new otel.LegacyOpenTelemetry({ tracer: _chunkVZJNEST4cjs.brizzTracerProvider.getTracer("ai") })
792
+ );
542
793
  otelCollectorLoaded = true;
543
794
  }
544
795
  } catch (e) {
@@ -565,6 +816,7 @@ function autoInitializeInstrumentations() {
565
816
  const genAIInstrumentations = loadGenAIInstrumentations();
566
817
  loadMCPInstrumentation();
567
818
  loadLangGraphInstrumentation();
819
+ loadTypeSafeInstrumentation();
568
820
  loadVertexAIInstrumentation();
569
821
  loadGoogleGenAIInstrumentation();
570
822
  loadVercelAITelemetry();
@@ -591,11 +843,24 @@ var autoInstrumentationsLoaded = autoInitializeInstrumentations();
591
843
 
592
844
  var _resources2 = require('@opentelemetry/resources');
593
845
  var _sdkmetrics = require('@opentelemetry/sdk-metrics');
846
+ var _sdktracebase = require('@opentelemetry/sdk-trace-base');
594
847
  var _sdktracenode = require('@opentelemetry/sdk-trace-node');
595
848
 
596
849
  // src/internal/config.ts
850
+ function parseBoolEnv(name) {
851
+ const raw = process.env[name];
852
+ if (raw === void 0) {
853
+ return void 0;
854
+ }
855
+ const value = raw.trim().toLowerCase();
856
+ if (value === "true" || value === "false") {
857
+ return value === "true";
858
+ }
859
+ _chunkWC573FCIcjs.logger.warn(`Brizz: ignoring ${name}=${raw}; expected true or false.`);
860
+ return void 0;
861
+ }
597
862
  function resolveConfig(options) {
598
- const envLogLevel = process.env["BRIZZ_LOG_LEVEL"] || _optionalChain([options, 'access', _19 => _19.logLevel, 'optionalAccess', _20 => _20.toString, 'call', _21 => _21()]) || _chunkWC573FCIcjs.DEFAULT_LOG_LEVEL.toString();
863
+ const envLogLevel = process.env["BRIZZ_LOG_LEVEL"] || _optionalChain([options, 'access', _28 => _28.logLevel, 'optionalAccess', _29 => _29.toString, 'call', _30 => _30()]) || _chunkWC573FCIcjs.DEFAULT_LOG_LEVEL.toString();
599
864
  let resolvedLogLevel;
600
865
  if (envLogLevel) {
601
866
  resolvedLogLevel = _chunkWC573FCIcjs.parseLogLevel.call(void 0, envLogLevel);
@@ -645,7 +910,8 @@ function resolveConfig(options) {
645
910
  disableSpanExporter: process.env["BRIZZ_DISABLE_SPAN_EXPORTER"] === "true" || !!options.disableSpanExporter,
646
911
  environment: process.env["BRIZZ_ENVIRONMENT"] || options.environment,
647
912
  logLevel: resolvedLogLevel,
648
- masking: resolvedMasking
913
+ masking: resolvedMasking,
914
+ setGlobalTracerProvider: _nullishCoalesce(_nullishCoalesce(parseBoolEnv("BRIZZ_SET_GLOBAL_TRACER_PROVIDER"), () => ( options.setGlobalTracerProvider)), () => ( true))
649
915
  };
650
916
  const dsnInput = process.env["BRIZZ_DSN"] || options.dsn;
651
917
  let parsedDSN = null;
@@ -715,6 +981,7 @@ function resolveConfig(options) {
715
981
  hasApiKey: !!resolvedConfig.apiKey,
716
982
  dsnProvided: !!dsnInput,
717
983
  disableBatch: resolvedConfig.disableBatch,
984
+ setGlobalTracerProvider: resolvedConfig.setGlobalTracerProvider,
718
985
  envOverrides: {
719
986
  hasEnvApiKey: !!process.env["BRIZZ_API_KEY"],
720
987
  hasEnvBaseUrl: !!process.env["BRIZZ_BASE_URL"],
@@ -741,7 +1008,6 @@ var SDK_LANGUAGE = "typescript";
741
1008
 
742
1009
 
743
1010
 
744
-
745
1011
  // src/internal/instrumentation/langchain.ts
746
1012
 
747
1013
 
@@ -770,7 +1036,7 @@ function runMetadataFromContext() {
770
1036
  return Object.keys(metadata).length > 0 ? metadata : void 0;
771
1037
  }
772
1038
  function patchCallbackManagerModule(module2) {
773
- const callbackManager = _optionalChain([module2, 'optionalAccess', _22 => _22.CallbackManager]);
1039
+ const callbackManager = _optionalChain([module2, 'optionalAccess', _31 => _31.CallbackManager]);
774
1040
  if (callbackManager === null || typeof callbackManager !== "function" && typeof callbackManager !== "object") {
775
1041
  return false;
776
1042
  }
@@ -801,7 +1067,7 @@ function patchCallbackManagerModule(module2) {
801
1067
  }
802
1068
  function patchToolStart(prototype) {
803
1069
  const proto = prototype;
804
- const original = _optionalChain([proto, 'optionalAccess', _23 => _23["handleToolStart"]]);
1070
+ const original = _optionalChain([proto, 'optionalAccess', _32 => _32["handleToolStart"]]);
805
1071
  if (!proto || typeof original !== "function") {
806
1072
  return;
807
1073
  }
@@ -839,7 +1105,7 @@ function patchInstalledCallbackManager() {
839
1105
  function restampLangChainSpan(span) {
840
1106
  try {
841
1107
  const scope = span.instrumentationScope;
842
- if (_optionalChain([scope, 'optionalAccess', _24 => _24.name]) !== SCOPE_NAME) {
1108
+ if (_optionalChain([scope, 'optionalAccess', _33 => _33.name]) !== SCOPE_NAME) {
843
1109
  return;
844
1110
  }
845
1111
  const attrs = span.attributes;
@@ -881,9 +1147,11 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
881
1147
  */
882
1148
  loadInstrumentation(InstrumentationClass, name, manualModule, exceptionLogger2) {
883
1149
  try {
884
- const inst = new InstrumentationClass({
885
- exceptionLogger: exceptionLogger2 || ((error) => _chunkWC573FCIcjs.logger.error(`Exception in instrumentation: ${String(error)}`))
886
- });
1150
+ const inst = _chunkVZJNEST4cjs.bindToBrizz.call(void 0,
1151
+ new InstrumentationClass({
1152
+ exceptionLogger: exceptionLogger2 || ((error) => _chunkWC573FCIcjs.logger.error(`Exception in instrumentation: ${String(error)}`))
1153
+ })
1154
+ );
887
1155
  if (manualModule) {
888
1156
  inst.manuallyInstrument(manualModule);
889
1157
  _chunkWC573FCIcjs.logger.debug(`Manual instrumentation enabled for ${name}`);
@@ -899,9 +1167,9 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
899
1167
  * @private
900
1168
  */
901
1169
  loadManualInstrumentations(instrumentations, exceptionLogger2) {
902
- if (_optionalChain([this, 'access', _25 => _25.manualModules, 'optionalAccess', _26 => _26.openAI])) {
1170
+ if (_optionalChain([this, 'access', _34 => _34.manualModules, 'optionalAccess', _35 => _35.openAI])) {
903
1171
  try {
904
- const openAIInst = new (0, _openinferenceinstrumentationopenai.OpenAIInstrumentation)();
1172
+ const openAIInst = new BrizzOpenAIInstrumentation();
905
1173
  openAIInst.manuallyInstrument(this.manualModules.openAI);
906
1174
  instrumentations.push(openAIInst);
907
1175
  _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for OpenAI");
@@ -910,18 +1178,18 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
910
1178
  }
911
1179
  }
912
1180
  const instrumentationConfigs = [
913
- { class: _instrumentationanthropic.AnthropicInstrumentation, name: "Anthropic", module: _optionalChain([this, 'access', _27 => _27.manualModules, 'optionalAccess', _28 => _28.anthropic]) },
914
- { class: _instrumentationcohere.CohereInstrumentation, name: "Cohere", module: _optionalChain([this, 'access', _29 => _29.manualModules, 'optionalAccess', _30 => _30.cohere]) },
915
- { class: _instrumentationbedrock.BedrockInstrumentation, name: "Bedrock", module: _optionalChain([this, 'access', _31 => _31.manualModules, 'optionalAccess', _32 => _32.bedrock]) },
916
- { class: _instrumentationpinecone.PineconeInstrumentation, name: "Pinecone", module: _optionalChain([this, 'access', _33 => _33.manualModules, 'optionalAccess', _34 => _34.pinecone]) },
1181
+ { class: _instrumentationanthropic.AnthropicInstrumentation, name: "Anthropic", module: _optionalChain([this, 'access', _36 => _36.manualModules, 'optionalAccess', _37 => _37.anthropic]) },
1182
+ { class: _instrumentationcohere.CohereInstrumentation, name: "Cohere", module: _optionalChain([this, 'access', _38 => _38.manualModules, 'optionalAccess', _39 => _39.cohere]) },
1183
+ { class: _instrumentationbedrock.BedrockInstrumentation, name: "Bedrock", module: _optionalChain([this, 'access', _40 => _40.manualModules, 'optionalAccess', _41 => _41.bedrock]) },
1184
+ { class: _instrumentationpinecone.PineconeInstrumentation, name: "Pinecone", module: _optionalChain([this, 'access', _42 => _42.manualModules, 'optionalAccess', _43 => _43.pinecone]) },
917
1185
  {
918
1186
  class: _instrumentationllamaindex.LlamaIndexInstrumentation,
919
1187
  name: "LlamaIndex",
920
- module: _optionalChain([this, 'access', _35 => _35.manualModules, 'optionalAccess', _36 => _36.llamaindex])
1188
+ module: _optionalChain([this, 'access', _44 => _44.manualModules, 'optionalAccess', _45 => _45.llamaindex])
921
1189
  },
922
- { class: _instrumentationchromadb.ChromaDBInstrumentation, name: "ChromaDB", module: _optionalChain([this, 'access', _37 => _37.manualModules, 'optionalAccess', _38 => _38.chromadb]) },
923
- { class: _instrumentationqdrant.QdrantInstrumentation, name: "Qdrant", module: _optionalChain([this, 'access', _39 => _39.manualModules, 'optionalAccess', _40 => _40.qdrant]) },
924
- { class: _instrumentationtogether.TogetherInstrumentation, name: "Together", module: _optionalChain([this, 'access', _41 => _41.manualModules, 'optionalAccess', _42 => _42.together]) }
1190
+ { class: _instrumentationchromadb.ChromaDBInstrumentation, name: "ChromaDB", module: _optionalChain([this, 'access', _46 => _46.manualModules, 'optionalAccess', _47 => _47.chromadb]) },
1191
+ { class: _instrumentationqdrant.QdrantInstrumentation, name: "Qdrant", module: _optionalChain([this, 'access', _48 => _48.manualModules, 'optionalAccess', _49 => _49.qdrant]) },
1192
+ { class: _instrumentationtogether.TogetherInstrumentation, name: "Together", module: _optionalChain([this, 'access', _50 => _50.manualModules, 'optionalAccess', _51 => _51.together]) }
925
1193
  ];
926
1194
  for (const config of instrumentationConfigs) {
927
1195
  if (!config.module) {
@@ -937,12 +1205,12 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
937
1205
  instrumentations.push(instrumentation);
938
1206
  }
939
1207
  }
940
- if (_optionalChain([this, 'access', _43 => _43.manualModules, 'optionalAccess', _44 => _44.langchain, 'optionalAccess', _45 => _45.callbackManagerModule])) {
1208
+ if (_optionalChain([this, 'access', _52 => _52.manualModules, 'optionalAccess', _53 => _53.langchain, 'optionalAccess', _54 => _54.callbackManagerModule])) {
941
1209
  const callbackManagerModule = this.manualModules.langchain.callbackManagerModule;
942
1210
  void (async () => {
943
1211
  try {
944
1212
  const { LangChainInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("@arizeai/openinference-instrumentation-langchain")));
945
- const lcInst = new LangChainInstrumentation();
1213
+ const lcInst = new LangChainInstrumentation({ tracerProvider: _chunkVZJNEST4cjs.brizzTracerProvider });
946
1214
  lcInst.manuallyInstrument(callbackManagerModule);
947
1215
  patchCallbackManagerModule(callbackManagerModule);
948
1216
  _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for LangChain");
@@ -953,7 +1221,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
953
1221
  }
954
1222
  })();
955
1223
  }
956
- if (_optionalChain([this, 'access', _46 => _46.manualModules, 'optionalAccess', _47 => _47.langgraph])) {
1224
+ if (_optionalChain([this, 'access', _55 => _55.manualModules, 'optionalAccess', _56 => _56.langgraph])) {
957
1225
  try {
958
1226
  new LangGraphInstrumentation().manuallyInstrument(this.manualModules.langgraph);
959
1227
  _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for LangGraph");
@@ -961,12 +1229,20 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
961
1229
  _chunkWC573FCIcjs.logger.error(`Failed to apply LangGraph instrumentation: ${String(error)}`);
962
1230
  }
963
1231
  }
964
- if (_optionalChain([this, 'access', _48 => _48.manualModules, 'optionalAccess', _49 => _49.google_vertexai])) {
1232
+ if (_optionalChain([this, 'access', _57 => _57.manualModules, 'optionalAccess', _58 => _58.typesafe])) {
1233
+ try {
1234
+ new TypeSafeInstrumentation().manuallyInstrument(this.manualModules.typesafe);
1235
+ _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for TypeSafe");
1236
+ } catch (error) {
1237
+ _chunkWC573FCIcjs.logger.error(`Failed to apply TypeSafe instrumentation: ${String(error)}`);
1238
+ }
1239
+ }
1240
+ if (_optionalChain([this, 'access', _59 => _59.manualModules, 'optionalAccess', _60 => _60.google_vertexai])) {
965
1241
  const vertexModule = this.manualModules.google_vertexai;
966
1242
  void (async () => {
967
1243
  try {
968
1244
  const { VertexAIInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("@traceloop/instrumentation-vertexai")));
969
- const vertexInst = new VertexAIInstrumentation({ exceptionLogger: exceptionLogger2 });
1245
+ const vertexInst = _chunkVZJNEST4cjs.bindToBrizz.call(void 0, new VertexAIInstrumentation({ exceptionLogger: exceptionLogger2 }));
970
1246
  vertexInst.manuallyInstrument(vertexModule);
971
1247
  _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for Vertex AI");
972
1248
  } catch (error) {
@@ -976,11 +1252,11 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
976
1252
  }
977
1253
  })();
978
1254
  }
979
- if (_optionalChain([this, 'access', _50 => _50.manualModules, 'optionalAccess', _51 => _51.google_genai])) {
1255
+ if (_optionalChain([this, 'access', _61 => _61.manualModules, 'optionalAccess', _62 => _62.google_genai])) {
980
1256
  const genaiModule = this.manualModules.google_genai;
981
1257
  void (async () => {
982
1258
  try {
983
- const { GoogleGenAIInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./google-genai-LMEZ62FB.cjs")));
1259
+ const { GoogleGenAIInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./google-genai-44O4QORJ.cjs")));
984
1260
  const genaiInst = new GoogleGenAIInstrumentation({ exceptionLogger: exceptionLogger2 });
985
1261
  genaiInst.manuallyInstrument(genaiModule);
986
1262
  _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for Google GenAI");
@@ -991,11 +1267,11 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
991
1267
  }
992
1268
  })();
993
1269
  }
994
- if (_optionalChain([this, 'access', _52 => _52.manualModules, 'optionalAccess', _53 => _53.mcp])) {
1270
+ if (_optionalChain([this, 'access', _63 => _63.manualModules, 'optionalAccess', _64 => _64.mcp])) {
995
1271
  const mcpModules = this.manualModules.mcp;
996
1272
  void (async () => {
997
1273
  try {
998
- const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-MVZSP5NE.cjs")));
1274
+ const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-4M4XL46N.cjs")));
999
1275
  const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
1000
1276
  instrumentation.manuallyInstrument(mcpModules);
1001
1277
  _chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for MCP");
@@ -1039,6 +1315,7 @@ var _sdklogs = require('@opentelemetry/sdk-logs');
1039
1315
 
1040
1316
  // src/internal/trace/session.ts
1041
1317
 
1318
+ var sessionTracer = _chunkVZJNEST4cjs.brizzTracerProvider.getTracer("@brizz/sdk");
1042
1319
  function setCurrentSpanCustomProperties(properties) {
1043
1320
  const current = _api.trace.getActiveSpan();
1044
1321
  if (!current || !current.isRecording()) {
@@ -1071,8 +1348,8 @@ function withProperties(properties, fn, thisArg) {
1071
1348
  function propagatePropertiesImperatively(properties, base = _api.context.active()) {
1072
1349
  try {
1073
1350
  const manager = _api.context;
1074
- const mgr = _optionalChain([manager, 'access', _54 => _54._getContextManager, 'optionalCall', _55 => _55()]);
1075
- const store = _optionalChain([mgr, 'optionalAccess', _56 => _56._asyncLocalStorage]);
1351
+ const mgr = _optionalChain([manager, 'access', _65 => _65._getContextManager, 'optionalCall', _66 => _66()]);
1352
+ const store = _optionalChain([mgr, 'optionalAccess', _67 => _67._asyncLocalStorage]);
1076
1353
  if (!store || typeof store.enterWith !== "function") {
1077
1354
  return;
1078
1355
  }
@@ -1174,7 +1451,7 @@ function withServiceName(name, fn, thisArg) {
1174
1451
  }
1175
1452
  function resolveServiceNameFromContext() {
1176
1453
  const props = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1177
- return _optionalChain([props, 'optionalAccess', _57 => _57[_chunkRV7JIIDGcjs.SERVICE_NAME]]);
1454
+ return _optionalChain([props, 'optionalAccess', _68 => _68[_chunkRV7JIIDGcjs.SERVICE_NAME]]);
1178
1455
  }
1179
1456
  function userProperties(user) {
1180
1457
  const properties = { [_chunkRV7JIIDGcjs.USER_ID]: user.id };
@@ -1241,7 +1518,7 @@ function withMessageId(id, fn, thisArg) {
1241
1518
  }
1242
1519
  function inheritedMuteTools() {
1243
1520
  const properties = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1244
- return _optionalChain([properties, 'optionalAccess', _58 => _58[_chunkRV7JIIDGcjs.MUTE_TOOLS]]);
1521
+ return _optionalChain([properties, 'optionalAccess', _69 => _69[_chunkRV7JIIDGcjs.MUTE_TOOLS]]);
1245
1522
  }
1246
1523
  function muteProperties(options) {
1247
1524
  const { input = true, output = true, tools = output } = options;
@@ -1300,9 +1577,9 @@ var Session = (_class2 = class {
1300
1577
  * @param text - Text to append (null becomes a null/"hide marker")
1301
1578
  * @param context - Optional per-turn context bag to attach to this turn
1302
1579
  */
1303
- setInput(text, context7) {
1304
- this.inputs.push(text);
1305
- this.inputContexts.push(_nullishCoalesce(context7, () => ( {})));
1580
+ setInput(text2, context8) {
1581
+ this.inputs.push(text2);
1582
+ this.inputContexts.push(_nullishCoalesce(context8, () => ( {})));
1306
1583
  this.span.setAttribute(_chunkRV7JIIDGcjs.SESSION_INPUT, JSON.stringify(this.inputs));
1307
1584
  this.span.setAttribute(_chunkRV7JIIDGcjs.SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
1308
1585
  }
@@ -1316,9 +1593,9 @@ var Session = (_class2 = class {
1316
1593
  * @param text - Text to append (null becomes a null/"hide marker")
1317
1594
  * @param context - Optional per-turn context bag to attach to this turn
1318
1595
  */
1319
- setOutput(text, context7) {
1320
- this.outputs.push(text);
1321
- this.outputContexts.push(_nullishCoalesce(context7, () => ( {})));
1596
+ setOutput(text2, context8) {
1597
+ this.outputs.push(text2);
1598
+ this.outputContexts.push(_nullishCoalesce(context8, () => ( {})));
1322
1599
  this.span.setAttribute(_chunkRV7JIIDGcjs.SESSION_OUTPUT, JSON.stringify(this.outputs));
1323
1600
  this.span.setAttribute(_chunkRV7JIIDGcjs.SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
1324
1601
  }
@@ -1403,7 +1680,7 @@ var Session = (_class2 = class {
1403
1680
  * (free-form category, defaults to `'generic'`)
1404
1681
  */
1405
1682
  addExternalLink(url, options) {
1406
- emitExternalLink(this.sessionId, url, _optionalChain([options, 'optionalAccess', _59 => _59.title]), _optionalChain([options, 'optionalAccess', _60 => _60.linkType]));
1683
+ emitExternalLink(this.sessionId, url, _optionalChain([options, 'optionalAccess', _70 => _70.title]), _optionalChain([options, 'optionalAccess', _71 => _71.linkType]));
1407
1684
  }
1408
1685
  }, _class2);
1409
1686
  var SessionTitle = class {
@@ -1429,11 +1706,11 @@ function resolveSessionIdFromContext() {
1429
1706
  return active.sessionId;
1430
1707
  }
1431
1708
  const props = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1432
- return _optionalChain([props, 'optionalAccess', _61 => _61[_chunkRV7JIIDGcjs.SESSION_ID]]);
1709
+ return _optionalChain([props, 'optionalAccess', _72 => _72[_chunkRV7JIIDGcjs.SESSION_ID]]);
1433
1710
  }
1434
1711
  function resolveMessageIdFromContext() {
1435
1712
  const props = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
1436
- return _optionalChain([props, 'optionalAccess', _62 => _62[_chunkRV7JIIDGcjs.MESSAGE_ID]]);
1713
+ return _optionalChain([props, 'optionalAccess', _73 => _73[_chunkRV7JIIDGcjs.MESSAGE_ID]]);
1437
1714
  }
1438
1715
  function emitExternalLink(sessionId, url, title, linkType) {
1439
1716
  try {
@@ -1447,30 +1724,30 @@ function emitExternalLink(sessionId, url, title, linkType) {
1447
1724
  }
1448
1725
  }
1449
1726
  function addExternalLink(url, options) {
1450
- const sessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _63 => _63.sessionId]), () => ( resolveSessionIdFromContext()));
1727
+ const sessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _74 => _74.sessionId]), () => ( resolveSessionIdFromContext()));
1451
1728
  if (!sessionId) {
1452
1729
  _chunkWC573FCIcjs.logger.warn(
1453
1730
  "addExternalLink called without a resolvable session id; link dropped. Pass options.sessionId or call inside a startSession/callWithSessionId scope."
1454
1731
  );
1455
1732
  return;
1456
1733
  }
1457
- emitExternalLink(sessionId, url, _optionalChain([options, 'optionalAccess', _64 => _64.title]), _optionalChain([options, 'optionalAccess', _65 => _65.linkType]));
1734
+ emitExternalLink(sessionId, url, _optionalChain([options, 'optionalAccess', _75 => _75.title]), _optionalChain([options, 'optionalAccess', _76 => _76.linkType]));
1458
1735
  }
1459
1736
  function recordFeedback(type, options) {
1460
1737
  const eventAttributes = { [_chunkRV7JIIDGcjs.FEEDBACK_TYPE]: type };
1461
- if (_optionalChain([options, 'optionalAccess', _66 => _66.score]) !== void 0) {
1738
+ if (_optionalChain([options, 'optionalAccess', _77 => _77.score]) !== void 0) {
1462
1739
  eventAttributes[_chunkRV7JIIDGcjs.FEEDBACK_SCORE] = options.score;
1463
1740
  }
1464
- if (_optionalChain([options, 'optionalAccess', _67 => _67.reason]) !== void 0) {
1741
+ if (_optionalChain([options, 'optionalAccess', _78 => _78.reason]) !== void 0) {
1465
1742
  eventAttributes[_chunkRV7JIIDGcjs.FEEDBACK_REASON] = options.reason;
1466
1743
  }
1467
- if (_optionalChain([options, 'optionalAccess', _68 => _68.comment]) !== void 0) {
1744
+ if (_optionalChain([options, 'optionalAccess', _79 => _79.comment]) !== void 0) {
1468
1745
  eventAttributes[_chunkRV7JIIDGcjs.FEEDBACK_COMMENT] = options.comment;
1469
1746
  }
1470
- if (_optionalChain([options, 'optionalAccess', _69 => _69.source]) !== void 0) {
1747
+ if (_optionalChain([options, 'optionalAccess', _80 => _80.source]) !== void 0) {
1471
1748
  eventAttributes[_chunkRV7JIIDGcjs.FEEDBACK_SOURCE] = options.source;
1472
1749
  }
1473
- if (_optionalChain([options, 'optionalAccess', _70 => _70.attributes])) {
1750
+ if (_optionalChain([options, 'optionalAccess', _81 => _81.attributes])) {
1474
1751
  for (const [key, value] of Object.entries(options.attributes)) {
1475
1752
  const k = `${_chunkRV7JIIDGcjs.FEEDBACK_ATTR_PREFIX}${key}`;
1476
1753
  if (eventAttributes[k] === void 0) {
@@ -1478,8 +1755,8 @@ function recordFeedback(type, options) {
1478
1755
  }
1479
1756
  }
1480
1757
  }
1481
- const messageId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _71 => _71.messageId]), () => ( resolveMessageIdFromContext()));
1482
- const sessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _72 => _72.sessionId]), () => ( resolveSessionIdFromContext()));
1758
+ const messageId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _82 => _82.messageId]), () => ( resolveMessageIdFromContext()));
1759
+ const sessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _83 => _83.sessionId]), () => ( resolveSessionIdFromContext()));
1483
1760
  if (messageId === void 0 && sessionId === void 0) {
1484
1761
  _chunkWC573FCIcjs.logger.warn(
1485
1762
  "recordFeedback called with no resolvable message id or session id; the feedback cannot be attributed to a message or conversation. Pass options.messageId / options.sessionId or call inside a startSession/callWithMessageId scope."
@@ -1510,7 +1787,7 @@ function recordMetric(options) {
1510
1787
  try {
1511
1788
  recordMetricImpl(options);
1512
1789
  } catch (error) {
1513
- _chunkWC573FCIcjs.logger.warn(`recordMetric(${JSON.stringify(_optionalChain([options, 'optionalAccess', _73 => _73.name]))}) failed; metric dropped.`, error);
1790
+ _chunkWC573FCIcjs.logger.warn(`recordMetric(${JSON.stringify(_optionalChain([options, 'optionalAccess', _84 => _84.name]))}) failed; metric dropped.`, error);
1514
1791
  }
1515
1792
  }
1516
1793
  function recordMetricImpl(options) {
@@ -1614,14 +1891,14 @@ function recordMetricImpl(options) {
1614
1891
  );
1615
1892
  continue;
1616
1893
  }
1617
- let text = typeof attrValue === "string" ? attrValue : String(attrValue);
1618
- if (text.length > METRIC_ATTRIBUTE_VALUE_MAX_LEN) {
1894
+ let text2 = typeof attrValue === "string" ? attrValue : String(attrValue);
1895
+ if (text2.length > METRIC_ATTRIBUTE_VALUE_MAX_LEN) {
1619
1896
  _chunkWC573FCIcjs.logger.warn(
1620
1897
  `recordMetric(${name}) attribute ${JSON.stringify(normalizedKey)} exceeds ${METRIC_ATTRIBUTE_VALUE_MAX_LEN} characters; truncated.`
1621
1898
  );
1622
- text = text.slice(0, METRIC_ATTRIBUTE_VALUE_MAX_LEN);
1899
+ text2 = text2.slice(0, METRIC_ATTRIBUTE_VALUE_MAX_LEN);
1623
1900
  }
1624
- eventAttributes[`${_chunkRV7JIIDGcjs.METRIC_ATTRIBUTE_PREFIX}${normalizedKey}`] = text;
1901
+ eventAttributes[`${_chunkRV7JIIDGcjs.METRIC_ATTRIBUTE_PREFIX}${normalizedKey}`] = text2;
1625
1902
  accepted += 1;
1626
1903
  }
1627
1904
  }
@@ -1630,7 +1907,7 @@ function recordMetricImpl(options) {
1630
1907
  eventAttributes[_chunkRV7JIIDGcjs.METRIC_TRACE_ID] = traceId;
1631
1908
  }
1632
1909
  if (scope === _chunkRV7JIIDGcjs.METRIC_SCOPE_TRACE && traceId === void 0) {
1633
- const spanContext = _optionalChain([_api.trace, 'access', _74 => _74.getActiveSpan, 'call', _75 => _75(), 'optionalAccess', _76 => _76.spanContext, 'call', _77 => _77()]);
1910
+ const spanContext = _optionalChain([_api.trace, 'access', _85 => _85.getActiveSpan, 'call', _86 => _86(), 'optionalAccess', _87 => _87.spanContext, 'call', _88 => _88()]);
1634
1911
  if (!spanContext || !_api.isSpanContextValid.call(void 0, spanContext)) {
1635
1912
  _chunkWC573FCIcjs.logger.warn(
1636
1913
  `recordMetric(${name}) called with scope 'trace' but no trace; metric dropped. Pass options.traceId, or call inside the span of the trace being scored.`
@@ -1668,10 +1945,9 @@ function recordMetricImpl(options) {
1668
1945
  }
1669
1946
  }
1670
1947
  function startSession(sessionId, callback, extraProperties, options) {
1671
- const isTitle = _optionalChain([options, 'optionalAccess', _78 => _78.mode]) === "title";
1948
+ const isTitle = _optionalChain([options, 'optionalAccess', _89 => _89.mode]) === "title";
1672
1949
  const spanName = isTitle ? _chunkRV7JIIDGcjs.SESSION_TITLE_SPAN_NAME : _chunkRV7JIIDGcjs.SESSION_SPAN_NAME;
1673
- const tracer = _api.trace.getTracer("@brizz/sdk");
1674
- return tracer.startActiveSpan(spanName, (span) => {
1950
+ return sessionTracer.startActiveSpan(spanName, (span) => {
1675
1951
  span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.SESSION_ID}`, sessionId);
1676
1952
  if (extraProperties) {
1677
1953
  for (const [key, value] of Object.entries(extraProperties)) {
@@ -1717,9 +1993,8 @@ function startSession(sessionId, callback, extraProperties, options) {
1717
1993
  });
1718
1994
  }
1719
1995
  function startSessionTitle(callback, options) {
1720
- const resolvedSessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _79 => _79.sessionId]), () => ( _optionalChain([getActiveSession, 'call', _80 => _80(), 'optionalAccess', _81 => _81.sessionId])));
1721
- const tracer = _api.trace.getTracer("@brizz/sdk");
1722
- return tracer.startActiveSpan(_chunkRV7JIIDGcjs.SESSION_TITLE_SPAN_NAME, (span) => {
1996
+ const resolvedSessionId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _90 => _90.sessionId]), () => ( _optionalChain([getActiveSession, 'call', _91 => _91(), 'optionalAccess', _92 => _92.sessionId])));
1997
+ return sessionTracer.startActiveSpan(_chunkRV7JIIDGcjs.SESSION_TITLE_SPAN_NAME, (span) => {
1723
1998
  if (resolvedSessionId) {
1724
1999
  span.setAttribute(`${_chunkRV7JIIDGcjs.BRIZZ}.${_chunkRV7JIIDGcjs.SESSION_ID}`, resolvedSessionId);
1725
2000
  }
@@ -2139,10 +2414,12 @@ function maskValue(value, rule) {
2139
2414
  return maskStringByPatternBasedRule(value, rule);
2140
2415
  }
2141
2416
  if (typeof value === "boolean" || typeof value === "number") {
2142
- return maskStringByPatternBasedRule(String(value), rule);
2417
+ const masked = maskStringByPatternBasedRule(String(value), rule);
2418
+ return masked === String(value) ? value : masked;
2143
2419
  }
2144
2420
  if (Array.isArray(value)) {
2145
- return value.map((v) => maskStringByPatternBasedRule(String(v), rule));
2421
+ const masked = value.map((v) => maskStringByPatternBasedRule(String(v), rule));
2422
+ return masked.every((m, i) => m === String(value[i])) ? value : masked;
2146
2423
  }
2147
2424
  if (value !== null && typeof value === "object") {
2148
2425
  const result = {};
@@ -2189,7 +2466,7 @@ var BrizzSimpleLogRecordProcessor = class extends _sdklogs.SimpleLogRecordProces
2189
2466
  this.config = config;
2190
2467
  }
2191
2468
  onEmit(logRecord) {
2192
- const maskingConfig = _optionalChain([this, 'access', _82 => _82.config, 'access', _83 => _83.masking, 'optionalAccess', _84 => _84.eventMasking]);
2469
+ const maskingConfig = _optionalChain([this, 'access', _93 => _93.config, 'access', _94 => _94.masking, 'optionalAccess', _95 => _95.eventMasking]);
2193
2470
  if (maskingConfig) {
2194
2471
  maskLog(logRecord, maskingConfig);
2195
2472
  }
@@ -2209,7 +2486,7 @@ var BrizzBatchLogRecordProcessor = class extends _sdklogs.BatchLogRecordProcesso
2209
2486
  this.config = config;
2210
2487
  }
2211
2488
  onEmit(logRecord) {
2212
- const maskingConfig = _optionalChain([this, 'access', _85 => _85.config, 'access', _86 => _86.masking, 'optionalAccess', _87 => _87.eventMasking]);
2489
+ const maskingConfig = _optionalChain([this, 'access', _96 => _96.config, 'access', _97 => _97.masking, 'optionalAccess', _98 => _98.eventMasking]);
2213
2490
  if (maskingConfig) {
2214
2491
  maskLog(logRecord, maskingConfig);
2215
2492
  }
@@ -2310,14 +2587,14 @@ var LoggingModule = (_class3 = class _LoggingModule {constructor() { _class3.pro
2310
2587
  _chunkWC573FCIcjs.logger.debug("Creating logger provider", {
2311
2588
  serviceName,
2312
2589
  disableBatch: config.disableBatch,
2313
- hasMasking: !!_optionalChain([config, 'access', _88 => _88.masking, 'optionalAccess', _89 => _89.eventMasking])
2590
+ hasMasking: !!_optionalChain([config, 'access', _99 => _99.masking, 'optionalAccess', _100 => _100.eventMasking])
2314
2591
  });
2315
2592
  const exporter = this.createLogExporter(config, serviceName);
2316
2593
  const processor = config.disableBatch ? new BrizzSimpleLogRecordProcessor(exporter, config) : new BrizzBatchLogRecordProcessor(exporter, config);
2317
2594
  const resourceAttributes = {
2318
2595
  ...config.resourceAttributes,
2319
2596
  "service.name": serviceName,
2320
- [BRIZZ_SDK_VERSION]: _chunk2T7OEV33cjs.getSDKVersion.call(void 0, ),
2597
+ [BRIZZ_SDK_VERSION]: _chunkKGNFUQ6Zcjs.getSDKVersion.call(void 0, ),
2321
2598
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
2322
2599
  };
2323
2600
  if (config.environment) {
@@ -2416,6 +2693,11 @@ var LoggingModule = (_class3 = class _LoggingModule {constructor() { _class3.pro
2416
2693
  getLoggerProvider() {
2417
2694
  return this.loggerProvider;
2418
2695
  }
2696
+ async forceFlush() {
2697
+ await Promise.all(
2698
+ [...this.scopedProviders.values(), this.loggerProvider].map(async (p) => _optionalChain([p, 'optionalAccess', _101 => _101.forceFlush, 'call', _102 => _102()]))
2699
+ );
2700
+ }
2419
2701
  /**
2420
2702
  * Shutdown the logging module
2421
2703
  */
@@ -2525,6 +2807,9 @@ var MetricsModule = (_class4 = class _MetricsModule {constructor() { _class4.pro
2525
2807
  }
2526
2808
  return this.metricsReader;
2527
2809
  }
2810
+ async forceFlush() {
2811
+ await _optionalChain([this, 'access', _103 => _103.metricsReader, 'optionalAccess', _104 => _104.forceFlush, 'call', _105 => _105()]);
2812
+ }
2528
2813
  /**
2529
2814
  * Shutdown the metrics module
2530
2815
  */
@@ -2566,7 +2851,7 @@ var BrizzSpanExporter = (_class5 = class {
2566
2851
  const resourceAttrs = {
2567
2852
  ...config.resourceAttributes,
2568
2853
  "service.name": config.appName,
2569
- [BRIZZ_SDK_VERSION]: _chunk2T7OEV33cjs.getSDKVersion.call(void 0, ),
2854
+ [BRIZZ_SDK_VERSION]: _chunkKGNFUQ6Zcjs.getSDKVersion.call(void 0, ),
2570
2855
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
2571
2856
  };
2572
2857
  if (config.environment) {
@@ -2693,8 +2978,8 @@ var BrizzSpanExporter = (_class5 = class {
2693
2978
  }
2694
2979
  async forceFlush() {
2695
2980
  await Promise.all([
2696
- _optionalChain([this, 'access', _90 => _90._delegate, 'access', _91 => _91.forceFlush, 'optionalCall', _92 => _92()]),
2697
- ...[...this._delegates.values()].map(async (delegate) => _optionalChain([delegate, 'access', _93 => _93.forceFlush, 'optionalCall', _94 => _94()]))
2981
+ _optionalChain([this, 'access', _106 => _106._delegate, 'access', _107 => _107.forceFlush, 'optionalCall', _108 => _108()]),
2982
+ ...[...this._delegates.values()].map(async (delegate) => _optionalChain([delegate, 'access', _109 => _109.forceFlush, 'optionalCall', _110 => _110()]))
2698
2983
  ]);
2699
2984
  }
2700
2985
  }, _class5);
@@ -2704,7 +2989,7 @@ var BrizzSpanExporter = (_class5 = class {
2704
2989
 
2705
2990
 
2706
2991
 
2707
- var _sdktracebase = require('@opentelemetry/sdk-trace-base');
2992
+
2708
2993
  function applyContextAttributes(span) {
2709
2994
  const sessionProperties = _api.context.active().getValue(_chunkRV7JIIDGcjs.PROPERTIES_CONTEXT_KEY);
2710
2995
  if (sessionProperties) {
@@ -2726,7 +3011,10 @@ var LIBRARY_ID_ATTRIBUTES = [
2726
3011
  "langsmith.metadata.thread_id",
2727
3012
  "langsmith.metadata.session_id",
2728
3013
  "langsmith.metadata.conversation_id",
2729
- "langsmith.trace.session_id"
3014
+ "langsmith.trace.session_id",
3015
+ // User-id aliases the streamer copies into brizz.user.id (userIDAliases).
3016
+ "user.id",
3017
+ "langfuse.user.id"
2730
3018
  ];
2731
3019
  var DEFAULT_RULE_ATTRIBUTES = String.raw`^(?!brizz\.(?!session\.(?:input|output)(?:\.context)?$|session\.title$|internal\.intent$)` + `|(?:${LIBRARY_ID_ATTRIBUTES.map((key) => key.replaceAll(".", String.raw`\.`)).join("|")})$)`;
2732
3020
  var isText = (value) => typeof value === "string" || Array.isArray(value) && value.some((item) => typeof item === "string");
@@ -2749,7 +3037,7 @@ var BrizzSimpleSpanProcessor = class extends _sdktracebase.SimpleSpanProcessor {
2749
3037
  }
2750
3038
  onEnd(span) {
2751
3039
  restampLangChainSpan(span);
2752
- const maskingConfig = _optionalChain([this, 'access', _95 => _95.config, 'access', _96 => _96.masking, 'optionalAccess', _97 => _97.spanMasking]);
3040
+ const maskingConfig = _optionalChain([this, 'access', _111 => _111.config, 'access', _112 => _112.masking, 'optionalAccess', _113 => _113.spanMasking]);
2753
3041
  if (maskingConfig) {
2754
3042
  maskReadableSpan(span, maskingConfig);
2755
3043
  }
@@ -2768,7 +3056,7 @@ var BrizzBatchSpanProcessor = class extends _sdktracebase.BatchSpanProcessor {
2768
3056
  }
2769
3057
  onEnd(span) {
2770
3058
  restampLangChainSpan(span);
2771
- const maskingConfig = _optionalChain([this, 'access', _98 => _98.config, 'access', _99 => _99.masking, 'optionalAccess', _100 => _100.spanMasking]);
3059
+ const maskingConfig = _optionalChain([this, 'access', _114 => _114.config, 'access', _115 => _115.masking, 'optionalAccess', _116 => _116.spanMasking]);
2772
3060
  if (maskingConfig) {
2773
3061
  maskReadableSpan(span, maskingConfig);
2774
3062
  }
@@ -2785,12 +3073,12 @@ function maskReadableSpan(span, config) {
2785
3073
  for (const [k, v] of Object.entries(attrs)) {
2786
3074
  masked[k] = v;
2787
3075
  }
2788
- if (_optionalChain([config, 'access', _101 => _101.rules, 'optionalAccess', _102 => _102.length])) {
3076
+ if (_optionalChain([config, 'access', _117 => _117.rules, 'optionalAccess', _118 => _118.length])) {
2789
3077
  masked = maskAttributes(masked, config.rules);
2790
3078
  }
2791
3079
  if (!config.disableDefaultRules) {
2792
- const text = Object.fromEntries(Object.entries(masked).filter(([k]) => isText(attrs[k])));
2793
- Object.assign(masked, maskAttributes(text, DEFAULT_MASKING_RULES));
3080
+ const text2 = Object.fromEntries(Object.entries(masked).filter(([k]) => isText(attrs[k])));
3081
+ Object.assign(masked, maskAttributes(text2, DEFAULT_MASKING_RULES));
2794
3082
  }
2795
3083
  const maskedEntries = Object.entries(masked);
2796
3084
  for (const [k, v] of maskedEntries) {
@@ -2857,7 +3145,7 @@ var TracingModule = (_class6 = class _TracingModule {constructor() { _class6.pro
2857
3145
  }
2858
3146
  _chunkWC573FCIcjs.logger.debug("Initializing span processor", {
2859
3147
  disableBatch: config.disableBatch,
2860
- hasMasking: !!_optionalChain([config, 'access', _103 => _103.masking, 'optionalAccess', _104 => _104.spanMasking])
3148
+ hasMasking: !!_optionalChain([config, 'access', _119 => _119.masking, 'optionalAccess', _120 => _120.spanMasking])
2861
3149
  });
2862
3150
  const spanProcessor = config.disableBatch ? new BrizzSimpleSpanProcessor(this.spanExporter, config) : new BrizzBatchSpanProcessor(this.spanExporter, config);
2863
3151
  _chunkWC573FCIcjs.logger.debug("Span processor initialized successfully");
@@ -2900,6 +3188,9 @@ var TracingModule = (_class6 = class _TracingModule {constructor() { _class6.pro
2900
3188
  }
2901
3189
  return this.spanProcessor;
2902
3190
  }
3191
+ async forceFlush() {
3192
+ await _optionalChain([this, 'access', _121 => _121.spanProcessor, 'optionalAccess', _122 => _122.forceFlush, 'call', _123 => _123()]);
3193
+ }
2903
3194
  async shutdown() {
2904
3195
  _chunkWC573FCIcjs.logger.debug("Shutting down tracing module");
2905
3196
  if (this.spanProcessor) {
@@ -2943,7 +3234,7 @@ function encodeToken(agent) {
2943
3234
  function currentTraceparent() {
2944
3235
  const carrier = {};
2945
3236
  try {
2946
- _api.propagation.inject(_api.context.active(), carrier);
3237
+ _chunkVZJNEST4cjs.injectTraceContext.call(void 0, _api.context.active(), carrier);
2947
3238
  } catch (e6) {
2948
3239
  }
2949
3240
  return _nullishCoalesce(carrier["traceparent"], () => ( ""));
@@ -3004,7 +3295,7 @@ function resolveAgent(agent) {
3004
3295
  sessionId = decoded.sessionId;
3005
3296
  if (decoded.traceparent) {
3006
3297
  try {
3007
- parentContext = _api.propagation.extract(parentContext, { traceparent: decoded.traceparent });
3298
+ parentContext = _chunkVZJNEST4cjs.extractTraceContext.call(void 0, parentContext, { traceparent: decoded.traceparent });
3008
3299
  } catch (e8) {
3009
3300
  }
3010
3301
  }
@@ -3057,6 +3348,11 @@ function resolveMcpSessionTracking(configured) {
3057
3348
  const enabled = fromEnv === "true";
3058
3349
  return typeof configured === "object" ? { ...configured, enabled } : enabled;
3059
3350
  }
3351
+ var BRIZZ_OWNED = /* @__PURE__ */ Symbol.for("brizz.sdk.ownedTracerProvider");
3352
+ function globalTracerDelegate() {
3353
+ const global = _api.trace.getTracerProvider();
3354
+ return typeof global.getDelegate === "function" ? global.getDelegate() : global;
3355
+ }
3060
3356
  var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init15.call(this);_class7.prototype.__init16.call(this);_class7.prototype.__init17.call(this); }
3061
3357
  static __initStatic4() {this.instance = null}
3062
3358
  static getInstance() {
@@ -3077,9 +3373,10 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3077
3373
  */
3078
3374
  setupInstrumentation(options) {
3079
3375
  const registry = InstrumentationRegistry.getInstance();
3080
- _chunk2T7OEV33cjs.configure.call(void 0, resolveMcpSessionTracking(options.mcpSessionTracking));
3376
+ _chunkKGNFUQ6Zcjs.configure.call(void 0, resolveMcpSessionTracking(options.mcpSessionTracking));
3081
3377
  patchInstalledCallbackManager();
3082
3378
  patchInstalledLangGraph();
3379
+ patchInstalledTypeSafe();
3083
3380
  if (options.instrumentModules && Object.keys(options.instrumentModules).length > 0) {
3084
3381
  registry.setManualModules(options.instrumentModules);
3085
3382
  }
@@ -3093,8 +3390,17 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3093
3390
  const registry = InstrumentationRegistry.getInstance();
3094
3391
  const manualInstrumentations = registry.getManualInstrumentations();
3095
3392
  if (options.disableNodeSdk) {
3393
+ _chunkVZJNEST4cjs.setPrivateTracerProvider.call(void 0, null);
3394
+ if (!resolvedConfig.setGlobalTracerProvider) {
3395
+ _chunkWC573FCIcjs.logger.warn(
3396
+ "Brizz: setGlobalTracerProvider: false has no effect with disableNodeSdk: true. Brizz creates no TracerProvider, so spans follow the provider you register with getSpanProcessor()."
3397
+ );
3398
+ }
3096
3399
  if (manualInstrumentations.length > 0) {
3097
- _instrumentation.registerInstrumentations.call(void 0, { instrumentations: manualInstrumentations });
3400
+ _instrumentation.registerInstrumentations.call(void 0, {
3401
+ instrumentations: manualInstrumentations,
3402
+ tracerProvider: _chunkVZJNEST4cjs.brizzTracerProvider
3403
+ });
3098
3404
  }
3099
3405
  _chunkWC573FCIcjs.logger.info("NodeSDK disabled - only telemetry modules initialized");
3100
3406
  return;
@@ -3102,7 +3408,7 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3102
3408
  const resourceAttributes = {
3103
3409
  ...resolvedConfig.resourceAttributes,
3104
3410
  "service.name": resolvedConfig.appName,
3105
- [BRIZZ_SDK_VERSION]: _chunk2T7OEV33cjs.getSDKVersion.call(void 0, ),
3411
+ [BRIZZ_SDK_VERSION]: _chunkKGNFUQ6Zcjs.getSDKVersion.call(void 0, ),
3106
3412
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
3107
3413
  };
3108
3414
  if (resolvedConfig.environment) {
@@ -3112,15 +3418,34 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3112
3418
  resourceAttributes["service.version"] = resolvedConfig.appVersion;
3113
3419
  }
3114
3420
  const resource = _resources2.defaultResource.call(void 0, ).merge(_resources2.detectResources.call(void 0, { detectors: [_resources2.envDetector, _resources2.hostDetector, _resources2.processDetector] })).merge(_resources2.resourceFromAttributes.call(void 0, resourceAttributes));
3115
- this._tracerProvider = new (0, _sdktracenode.NodeTracerProvider)({
3116
- resource,
3117
- spanProcessors: resolvedConfig.disableSpanExporter ? [] : [new (0, _chunkO2IBZJOJcjs.InterruptPropagator)(), getSpanProcessor()]
3118
- });
3119
- this._tracerProvider.register();
3421
+ const spanProcessors = resolvedConfig.disableSpanExporter ? [] : [new (0, _chunkO2IBZJOJcjs.InterruptPropagator)(), getSpanProcessor()];
3422
+ if (resolvedConfig.setGlobalTracerProvider) {
3423
+ this._tracerProvider = new (0, _sdktracenode.NodeTracerProvider)({ resource, spanProcessors });
3424
+ this.registerGlobalTracerProvider(this._tracerProvider);
3425
+ } else {
3426
+ this._tracerProvider = new (0, _sdktracenode.NodeTracerProvider)({
3427
+ resource,
3428
+ spanProcessors,
3429
+ sampler: new (0, _sdktracebase.AlwaysOnSampler)()
3430
+ });
3431
+ if (_chunkVZJNEST4cjs.ensureContextManager.call(void 0, ) === "failed") {
3432
+ _chunkWC573FCIcjs.logger.warn(
3433
+ "Brizz: no OpenTelemetry context manager is active and Brizz could not install one; span parenting and session/user propagation will not work."
3434
+ );
3435
+ }
3436
+ _chunkVZJNEST4cjs.setPrivateTracerProvider.call(void 0, this._tracerProvider);
3437
+ _chunkWC573FCIcjs.logger.info(
3438
+ "Brizz: using a private TracerProvider; Brizz spans are exported to Brizz only and the global TracerProvider is left untouched."
3439
+ );
3440
+ }
3441
+ Reflect.set(this._tracerProvider, BRIZZ_OWNED, true);
3120
3442
  this._meterProvider = new (0, _sdkmetrics.MeterProvider)({ resource, readers: [getMetricsReader()] });
3121
3443
  _api.metrics.setGlobalMeterProvider(this._meterProvider);
3122
3444
  if (manualInstrumentations.length > 0) {
3123
- _instrumentation.registerInstrumentations.call(void 0, { instrumentations: manualInstrumentations });
3445
+ _instrumentation.registerInstrumentations.call(void 0, {
3446
+ instrumentations: manualInstrumentations,
3447
+ tracerProvider: _chunkVZJNEST4cjs.brizzTracerProvider
3448
+ });
3124
3449
  _chunkWC573FCIcjs.logger.info(
3125
3450
  `Telemetry providers started with ${manualInstrumentations.length} manual instrumentations`
3126
3451
  );
@@ -3130,6 +3455,27 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3130
3455
  );
3131
3456
  }
3132
3457
  }
3458
+ /**
3459
+ * Register `provider` globally and say so when another provider already
3460
+ * holds the slot: OpenTelemetry refuses the second registration without a
3461
+ * word, and every Brizz span then goes to the other provider.
3462
+ * @private
3463
+ */
3464
+ registerGlobalTracerProvider(provider) {
3465
+ _chunkVZJNEST4cjs.setPrivateTracerProvider.call(void 0, null);
3466
+ provider.register();
3467
+ const registered = globalTracerDelegate();
3468
+ if (registered === provider) {
3469
+ return;
3470
+ }
3471
+ if (Reflect.get(registered, BRIZZ_OWNED) === true) {
3472
+ _chunkWC573FCIcjs.logger.debug("A TracerProvider from an earlier Brizz.initialize() is still registered");
3473
+ return;
3474
+ }
3475
+ _chunkWC573FCIcjs.logger.warn(
3476
+ "Brizz: another OpenTelemetry TracerProvider is already registered globally, so Brizz could not register its own. Spans from Brizz instrumentations will go to that provider, not to Brizz. Pass setGlobalTracerProvider: false to Brizz.initialize() (or set BRIZZ_SET_GLOBAL_TRACER_PROVIDER=false) to send them to Brizz on a separate provider."
3477
+ );
3478
+ }
3133
3479
  /**
3134
3480
  * Initialize telemetry modules.
3135
3481
  *
@@ -3228,6 +3574,62 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3228
3574
  throw new Error(`Failed to initialize SDK: ${String(error)}`, { cause: error });
3229
3575
  }
3230
3576
  }
3577
+ /**
3578
+ * Send the telemetry Brizz has queued, without shutting down.
3579
+ *
3580
+ * On serverless platforms that throttle CPU once a response is sent (Cloud
3581
+ * Run, Lambda), await it before responding: the batch timer may not fire
3582
+ * again before the instance is frozen or recycled. Never throws.
3583
+ *
3584
+ * @param timeoutMillis - How long to wait. Defaults to 5000.
3585
+ * @returns `true` when everything was sent within the budget; `false` on a
3586
+ * timeout, an export error, or before `initialize()`.
3587
+ *
3588
+ * @example
3589
+ * ```typescript
3590
+ * await Brizz.flush();
3591
+ * res.send(reply);
3592
+ * ```
3593
+ */
3594
+ async flush(timeoutMillis = 5e3) {
3595
+ if (!this._initialized) {
3596
+ _chunkWC573FCIcjs.logger.debug("Brizz.flush called before Brizz.initialize; nothing to flush");
3597
+ return false;
3598
+ }
3599
+ const settle = async (name, flush) => {
3600
+ try {
3601
+ await flush();
3602
+ return true;
3603
+ } catch (error) {
3604
+ _chunkWC573FCIcjs.logger.debug(`Brizz.flush: flushing ${name} failed: ${String(error)}`);
3605
+ return false;
3606
+ }
3607
+ };
3608
+ const work = Promise.all([
3609
+ settle("spans", () => TracingModule.getInstance().forceFlush()),
3610
+ settle("logs", () => LoggingModule.getInstance().forceFlush()),
3611
+ // Under disableNodeSdk the reader belongs to whatever MeterProvider the
3612
+ // app registered, if any; an unbound reader cannot flush.
3613
+ ...this._meterProvider ? [settle("metrics", () => MetricsModule.getInstance().forceFlush())] : []
3614
+ ]).then((results) => results.every(Boolean));
3615
+ let timer;
3616
+ const timedOut = new Promise((resolve) => {
3617
+ timer = setTimeout(() => resolve("timeout"), timeoutMillis);
3618
+ timer.unref();
3619
+ });
3620
+ try {
3621
+ const result = await Promise.race([work, timedOut]);
3622
+ if (result === "timeout") {
3623
+ _chunkWC573FCIcjs.logger.warn(
3624
+ `Brizz.flush did not finish within ${timeoutMillis}ms; telemetry still queued will be sent with the next batch.`
3625
+ );
3626
+ return false;
3627
+ }
3628
+ return result;
3629
+ } finally {
3630
+ clearTimeout(timer);
3631
+ }
3632
+ }
3231
3633
  /**
3232
3634
  * Gracefully shutdown the Brizz SDK.
3233
3635
  *
@@ -3250,10 +3652,10 @@ var _Brizz = (_class7 = class __Brizz {constructor() { _class7.prototype.__init1
3250
3652
  }
3251
3653
  try {
3252
3654
  await this.shutdownModules();
3253
- await _optionalChain([this, 'access', _105 => _105._tracerProvider, 'optionalAccess', _106 => _106.forceFlush, 'call', _107 => _107()]);
3254
- await _optionalChain([this, 'access', _108 => _108._tracerProvider, 'optionalAccess', _109 => _109.shutdown, 'call', _110 => _110()]);
3255
- await _optionalChain([this, 'access', _111 => _111._meterProvider, 'optionalAccess', _112 => _112.forceFlush, 'call', _113 => _113()]);
3256
- await _optionalChain([this, 'access', _114 => _114._meterProvider, 'optionalAccess', _115 => _115.shutdown, 'call', _116 => _116()]);
3655
+ await _optionalChain([this, 'access', _124 => _124._tracerProvider, 'optionalAccess', _125 => _125.forceFlush, 'call', _126 => _126()]);
3656
+ await _optionalChain([this, 'access', _127 => _127._tracerProvider, 'optionalAccess', _128 => _128.shutdown, 'call', _129 => _129()]);
3657
+ await _optionalChain([this, 'access', _130 => _130._meterProvider, 'optionalAccess', _131 => _131.forceFlush, 'call', _132 => _132()]);
3658
+ await _optionalChain([this, 'access', _133 => _133._meterProvider, 'optionalAccess', _134 => _134.shutdown, 'call', _135 => _135()]);
3257
3659
  this._initialized = false;
3258
3660
  this._tracerProvider = null;
3259
3661
  this._meterProvider = null;
@@ -3320,4 +3722,5 @@ var Brizz = new _Brizz();
3320
3722
 
3321
3723
 
3322
3724
 
3323
- exports.Brizz = Brizz; exports.DEFAULT_PII_PATTERNS = DEFAULT_PII_PATTERNS; exports.LogLevel = _chunkWC573FCIcjs.LogLevel; exports.Session = Session; exports.SessionTitle = SessionTitle; exports.SeverityNumber = _apilogs.SeverityNumber; exports.addExternalLink = addExternalLink; exports.callWithMessageId = callWithMessageId; exports.callWithMute = callWithMute; exports.callWithOrganization = callWithOrganization; exports.callWithProperties = callWithProperties; exports.callWithServiceName = callWithServiceName; exports.callWithSessionId = callWithSessionId; exports.callWithUser = callWithUser; exports.emitEvent = emitEvent; exports.emitEventWithSessionId = emitEventWithSessionId; exports.getActiveSession = getActiveSession; exports.getLogLevel = _chunkWC573FCIcjs.getLogLevel; exports.getMetricsExporter = getMetricsExporter; exports.getMetricsReader = getMetricsReader; exports.getSpanExporter = getSpanExporter; exports.getSpanProcessor = getSpanProcessor; exports.logger = _chunkWC573FCIcjs.logger; exports.maskAttributes = maskAttributes; exports.maskValue = maskValue; exports.recordFeedback = recordFeedback; exports.recordMetric = recordMetric; exports.setAgent = setAgent; exports.setCurrentSpanCustomProperties = setCurrentSpanCustomProperties; exports.setLogLevel = _chunkWC573FCIcjs.setLogLevel; exports.setMessageId = setMessageId; exports.setOrganization = setOrganization; exports.setServiceName = setServiceName; exports.setSessionId = setSessionId; exports.setUser = setUser; exports.startAgent = startAgent; exports.startSession = startSession; exports.startSessionTitle = startSessionTitle; exports.withAgent = withAgent; exports.withMessageId = withMessageId; exports.withMute = withMute; exports.withOrganization = withOrganization; exports.withProperties = withProperties; exports.withServiceName = withServiceName; exports.withSessionId = withSessionId; exports.withUser = withUser;
3725
+
3726
+ exports.Brizz = Brizz; exports.DEFAULT_PII_PATTERNS = DEFAULT_PII_PATTERNS; exports.LogLevel = _chunkWC573FCIcjs.LogLevel; exports.Session = Session; exports.SessionTitle = SessionTitle; exports.SeverityNumber = _apilogs.SeverityNumber; exports.addExternalLink = addExternalLink; exports.callWithMessageId = callWithMessageId; exports.callWithMute = callWithMute; exports.callWithOrganization = callWithOrganization; exports.callWithProperties = callWithProperties; exports.callWithServiceName = callWithServiceName; exports.callWithSessionId = callWithSessionId; exports.callWithUser = callWithUser; exports.emitEvent = emitEvent; exports.emitEventWithSessionId = emitEventWithSessionId; exports.getActiveSession = getActiveSession; exports.getLogLevel = _chunkWC573FCIcjs.getLogLevel; exports.getMetricsExporter = getMetricsExporter; exports.getMetricsReader = getMetricsReader; exports.getSpanExporter = getSpanExporter; exports.getSpanProcessor = getSpanProcessor; exports.getTracerProvider = _chunkVZJNEST4cjs.getTracerProvider; exports.logger = _chunkWC573FCIcjs.logger; exports.maskAttributes = maskAttributes; exports.maskValue = maskValue; exports.recordFeedback = recordFeedback; exports.recordMetric = recordMetric; exports.setAgent = setAgent; exports.setCurrentSpanCustomProperties = setCurrentSpanCustomProperties; exports.setLogLevel = _chunkWC573FCIcjs.setLogLevel; exports.setMessageId = setMessageId; exports.setOrganization = setOrganization; exports.setServiceName = setServiceName; exports.setSessionId = setSessionId; exports.setUser = setUser; exports.startAgent = startAgent; exports.startSession = startSession; exports.startSessionTitle = startSessionTitle; exports.withAgent = withAgent; exports.withMessageId = withMessageId; exports.withMute = withMute; exports.withOrganization = withOrganization; exports.withProperties = withProperties; exports.withServiceName = withServiceName; exports.withSessionId = withSessionId; exports.withUser = withUser;