@brizz/sdk 0.1.53 → 0.1.55

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 (49) hide show
  1. package/README.md +39 -1
  2. package/dist/{chunk-TEY6FAVZ.js → chunk-B5IY6O4N.js} +7 -0
  3. package/dist/{chunk-STTOBCTP.cjs → chunk-CF4CXFQP.cjs} +1 -1
  4. package/dist/chunk-DC2MFO65.cjs +121 -0
  5. package/dist/{chunk-KFETJN5M.cjs → chunk-RD4XCYKT.cjs} +7 -0
  6. package/dist/chunk-TDPQDITP.js +121 -0
  7. package/dist/{chunk-XV3ZJO5K.js → chunk-WJZSFRB4.js} +1 -1
  8. package/dist/{google-genai-T7I4FFIP.js → google-genai-3ERJNC7Q.js} +2 -1
  9. package/dist/google-genai-GVCKSJMR.cjs +11 -0
  10. package/dist/google-genai.cjs +3 -2
  11. package/dist/google-genai.js +2 -1
  12. package/dist/index.cjs +236 -63
  13. package/dist/index.js +217 -44
  14. package/dist/{mcp-KH5LOG5H.cjs → mcp-CYQ3TGCK.cjs} +39 -16
  15. package/dist/{mcp-DBLN5ZBE.js → mcp-LLYYMR5M.js} +29 -6
  16. package/dist/types/cjs/index.d.ts +3 -3
  17. package/dist/types/cjs/internal/config.d.ts +2 -1
  18. package/dist/types/cjs/internal/instrumentation/langchain.d.ts +1 -1
  19. package/dist/types/cjs/internal/instrumentation/openai.d.ts +5 -0
  20. package/dist/types/cjs/internal/instrumentation/vercel-ai/interrupt.d.ts +1 -1
  21. package/dist/types/cjs/internal/log/logging.d.ts +6 -5
  22. package/dist/types/cjs/internal/log/processors/log-processor.d.ts +4 -4
  23. package/dist/types/cjs/internal/metric/metrics.d.ts +1 -0
  24. package/dist/types/cjs/internal/sdk.d.ts +4 -1
  25. package/dist/types/cjs/internal/trace/exporters/eve-trace-exporter.d.ts +1 -1
  26. package/dist/types/cjs/internal/trace/exporters/span-exporter.d.ts +1 -1
  27. package/dist/types/cjs/internal/trace/index.d.ts +1 -0
  28. package/dist/types/cjs/internal/trace/processors/eve-session-processor.d.ts +1 -1
  29. package/dist/types/cjs/internal/trace/processors/span-processor.d.ts +1 -1
  30. package/dist/types/cjs/internal/trace/provider.d.ts +16 -0
  31. package/dist/types/cjs/internal/trace/tracing.d.ts +3 -2
  32. package/dist/types/esm/index.d.ts +3 -3
  33. package/dist/types/esm/internal/config.d.ts +2 -1
  34. package/dist/types/esm/internal/instrumentation/langchain.d.ts +1 -1
  35. package/dist/types/esm/internal/instrumentation/openai.d.ts +5 -0
  36. package/dist/types/esm/internal/instrumentation/vercel-ai/interrupt.d.ts +1 -1
  37. package/dist/types/esm/internal/log/logging.d.ts +6 -5
  38. package/dist/types/esm/internal/log/processors/log-processor.d.ts +4 -4
  39. package/dist/types/esm/internal/metric/metrics.d.ts +1 -0
  40. package/dist/types/esm/internal/sdk.d.ts +4 -1
  41. package/dist/types/esm/internal/trace/exporters/eve-trace-exporter.d.ts +1 -1
  42. package/dist/types/esm/internal/trace/exporters/span-exporter.d.ts +1 -1
  43. package/dist/types/esm/internal/trace/index.d.ts +1 -0
  44. package/dist/types/esm/internal/trace/processors/eve-session-processor.d.ts +1 -1
  45. package/dist/types/esm/internal/trace/processors/span-processor.d.ts +1 -1
  46. package/dist/types/esm/internal/trace/provider.d.ts +16 -0
  47. package/dist/types/esm/internal/trace/tracing.d.ts +3 -2
  48. package/package.json +29 -30
  49. package/dist/google-genai-LMEZ62FB.cjs +0 -10
package/dist/index.js CHANGED
@@ -5,7 +5,17 @@ import {
5
5
  import {
6
6
  configure,
7
7
  getSDKVersion
8
- } from "./chunk-XV3ZJO5K.js";
8
+ } from "./chunk-WJZSFRB4.js";
9
+ import {
10
+ bindToBrizz,
11
+ brizzTracerProvider,
12
+ ensureContextManager,
13
+ extractTraceContext,
14
+ getTracerProvider,
15
+ injectTraceContext,
16
+ registerTracerProvider,
17
+ setPrivateTracerProvider
18
+ } from "./chunk-TDPQDITP.js";
9
19
  import {
10
20
  DEFAULT_LOG_LEVEL,
11
21
  LogLevel,
@@ -83,7 +93,6 @@ import {
83
93
  } from "./chunk-3RG5ZIWI.js";
84
94
 
85
95
  // src/internal/instrumentation/auto-init.ts
86
- import { OpenAIInstrumentation } from "@arizeai/openinference-instrumentation-openai";
87
96
  import { registerInstrumentations } from "@opentelemetry/instrumentation";
88
97
  import { AnthropicInstrumentation } from "@traceloop/instrumentation-anthropic";
89
98
  import { BedrockInstrumentation } from "@traceloop/instrumentation-bedrock";
@@ -174,6 +183,7 @@ var parentRecorded = /* @__PURE__ */ new WeakSet();
174
183
  var LangGraphInstrumentation = class extends InstrumentationBase {
175
184
  constructor(config = {}) {
176
185
  super(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION, config);
186
+ this.setTracerProvider(brizzTracerProvider);
177
187
  }
178
188
  init() {
179
189
  return [
@@ -426,6 +436,14 @@ function attachRunToIteration(stream, run) {
426
436
  return iterable;
427
437
  }
428
438
 
439
+ // src/internal/instrumentation/openai.ts
440
+ import { OpenAIInstrumentation } from "@arizeai/openinference-instrumentation-openai";
441
+ var BrizzOpenAIInstrumentation = class extends OpenAIInstrumentation {
442
+ get tracer() {
443
+ return brizzTracerProvider.getTracer(this.instrumentationName, this.instrumentationVersion);
444
+ }
445
+ };
446
+
429
447
  // src/internal/instrumentation/typesafe.ts
430
448
  import { createRequire as createRequire2 } from "module";
431
449
  import { SpanKind, SpanStatusCode as SpanStatusCode2, context as context2, trace as trace2 } from "@opentelemetry/api";
@@ -452,6 +470,7 @@ var PATCHED_FLAG2 = /* @__PURE__ */ Symbol.for("brizz.typesafe.patched");
452
470
  var TypeSafeInstrumentation = class extends InstrumentationBase2 {
453
471
  constructor(config = {}) {
454
472
  super(INSTRUMENTATION_NAME2, getSDKVersion(), config);
473
+ this.setTracerProvider(brizzTracerProvider);
455
474
  }
456
475
  init() {
457
476
  return [
@@ -644,7 +663,7 @@ var exceptionLogger = (error) => {
644
663
  function loadGenAIInstrumentations() {
645
664
  const instrumentations = [];
646
665
  try {
647
- instrumentations.push(new OpenAIInstrumentation());
666
+ instrumentations.push(new BrizzOpenAIInstrumentation());
648
667
  logger.debug("Auto-loaded OpenAI instrumentation");
649
668
  } catch (error) {
650
669
  logger.error(`Failed to auto-load OpenAI instrumentation: ${String(error)}`);
@@ -669,7 +688,7 @@ function loadGenAIInstrumentations() {
669
688
  }
670
689
  }
671
690
  try {
672
- registerInstrumentations({ instrumentations });
691
+ registerInstrumentations({ instrumentations, tracerProvider: brizzTracerProvider });
673
692
  logger.info(`Auto-registered ${instrumentations.length} GenAI instrumentations`);
674
693
  } catch (error) {
675
694
  logger.error(`Failed to register GenAI instrumentations: ${String(error)}`);
@@ -679,9 +698,9 @@ function loadGenAIInstrumentations() {
679
698
  function loadMCPInstrumentation() {
680
699
  void (async () => {
681
700
  try {
682
- const { MCPInstrumentation } = await import("./mcp-DBLN5ZBE.js");
701
+ const { MCPInstrumentation } = await import("./mcp-LLYYMR5M.js");
683
702
  const mcp = new MCPInstrumentation({ exceptionLogger });
684
- registerInstrumentations({ instrumentations: [mcp] });
703
+ registerInstrumentations({ instrumentations: [mcp], tracerProvider: brizzTracerProvider });
685
704
  logger.debug("Auto-loaded MCP instrumentation");
686
705
  } catch (error) {
687
706
  logger.debug(
@@ -692,7 +711,10 @@ function loadMCPInstrumentation() {
692
711
  }
693
712
  function loadLangGraphInstrumentation() {
694
713
  try {
695
- registerInstrumentations({ instrumentations: [new LangGraphInstrumentation()] });
714
+ registerInstrumentations({
715
+ instrumentations: [new LangGraphInstrumentation()],
716
+ tracerProvider: brizzTracerProvider
717
+ });
696
718
  logger.debug("Auto-loaded LangGraph instrumentation");
697
719
  } catch (error) {
698
720
  logger.debug(`LangGraph instrumentation not loaded: ${String(error)}`);
@@ -700,7 +722,10 @@ function loadLangGraphInstrumentation() {
700
722
  }
701
723
  function loadTypeSafeInstrumentation() {
702
724
  try {
703
- registerInstrumentations({ instrumentations: [new TypeSafeInstrumentation()] });
725
+ registerInstrumentations({
726
+ instrumentations: [new TypeSafeInstrumentation()],
727
+ tracerProvider: brizzTracerProvider
728
+ });
704
729
  logger.debug("Auto-loaded TypeSafe instrumentation");
705
730
  } catch (error) {
706
731
  logger.debug(`TypeSafe instrumentation not loaded: ${String(error)}`);
@@ -711,7 +736,10 @@ function loadVertexAIInstrumentation() {
711
736
  try {
712
737
  const { VertexAIInstrumentation } = await import("@traceloop/instrumentation-vertexai");
713
738
  const vertexAI = new VertexAIInstrumentation({ exceptionLogger });
714
- registerInstrumentations({ instrumentations: [vertexAI] });
739
+ registerInstrumentations({
740
+ instrumentations: [vertexAI],
741
+ tracerProvider: brizzTracerProvider
742
+ });
715
743
  logger.debug("Auto-loaded Vertex AI instrumentation");
716
744
  } catch (error) {
717
745
  logger.debug(
@@ -723,9 +751,12 @@ function loadVertexAIInstrumentation() {
723
751
  function loadGoogleGenAIInstrumentation() {
724
752
  void (async () => {
725
753
  try {
726
- const { GoogleGenAIInstrumentation } = await import("./google-genai-T7I4FFIP.js");
754
+ const { GoogleGenAIInstrumentation } = await import("./google-genai-3ERJNC7Q.js");
727
755
  const googleGenAI = new GoogleGenAIInstrumentation({ exceptionLogger });
728
- registerInstrumentations({ instrumentations: [googleGenAI] });
756
+ registerInstrumentations({
757
+ instrumentations: [googleGenAI],
758
+ tracerProvider: brizzTracerProvider
759
+ });
729
760
  logger.debug("Auto-loaded Google GenAI instrumentation");
730
761
  } catch (error) {
731
762
  logger.debug(
@@ -757,7 +788,9 @@ function loadVercelAITelemetry() {
757
788
  try {
758
789
  const otel = await import("@ai-sdk/otel");
759
790
  if (typeof otel.LegacyOpenTelemetry === "function") {
760
- integrations.push(new otel.LegacyOpenTelemetry());
791
+ integrations.push(
792
+ new otel.LegacyOpenTelemetry({ tracer: brizzTracerProvider.getTracer("ai") })
793
+ );
761
794
  otelCollectorLoaded = true;
762
795
  }
763
796
  } catch {
@@ -800,7 +833,7 @@ function autoInitializeInstrumentations() {
800
833
  var autoInstrumentationsLoaded = autoInitializeInstrumentations();
801
834
 
802
835
  // src/internal/sdk.ts
803
- import { metrics } from "@opentelemetry/api";
836
+ import { metrics, trace as trace4 } from "@opentelemetry/api";
804
837
  import { registerInstrumentations as registerInstrumentations2 } from "@opentelemetry/instrumentation";
805
838
  import {
806
839
  defaultResource,
@@ -811,9 +844,22 @@ import {
811
844
  resourceFromAttributes as resourceFromAttributes3
812
845
  } from "@opentelemetry/resources";
813
846
  import { MeterProvider } from "@opentelemetry/sdk-metrics";
814
- import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
847
+ import { AlwaysOnSampler } from "@opentelemetry/sdk-trace";
848
+ import { TracerProvider as SdkTracerProvider } from "@opentelemetry/sdk-trace";
815
849
 
816
850
  // src/internal/config.ts
851
+ function parseBoolEnv(name) {
852
+ const raw = process.env[name];
853
+ if (raw === void 0) {
854
+ return void 0;
855
+ }
856
+ const value = raw.trim().toLowerCase();
857
+ if (value === "true" || value === "false") {
858
+ return value === "true";
859
+ }
860
+ logger.warn(`Brizz: ignoring ${name}=${raw}; expected true or false.`);
861
+ return void 0;
862
+ }
817
863
  function resolveConfig(options) {
818
864
  const envLogLevel = process.env["BRIZZ_LOG_LEVEL"] || options.logLevel?.toString() || DEFAULT_LOG_LEVEL.toString();
819
865
  let resolvedLogLevel;
@@ -865,7 +911,8 @@ function resolveConfig(options) {
865
911
  disableSpanExporter: process.env["BRIZZ_DISABLE_SPAN_EXPORTER"] === "true" || !!options.disableSpanExporter,
866
912
  environment: process.env["BRIZZ_ENVIRONMENT"] || options.environment,
867
913
  logLevel: resolvedLogLevel,
868
- masking: resolvedMasking
914
+ masking: resolvedMasking,
915
+ setGlobalTracerProvider: parseBoolEnv("BRIZZ_SET_GLOBAL_TRACER_PROVIDER") ?? options.setGlobalTracerProvider ?? true
869
916
  };
870
917
  const dsnInput = process.env["BRIZZ_DSN"] || options.dsn;
871
918
  let parsedDSN = null;
@@ -935,6 +982,7 @@ function resolveConfig(options) {
935
982
  hasApiKey: !!resolvedConfig.apiKey,
936
983
  dsnProvided: !!dsnInput,
937
984
  disableBatch: resolvedConfig.disableBatch,
985
+ setGlobalTracerProvider: resolvedConfig.setGlobalTracerProvider,
938
986
  envOverrides: {
939
987
  hasEnvApiKey: !!process.env["BRIZZ_API_KEY"],
940
988
  hasEnvBaseUrl: !!process.env["BRIZZ_BASE_URL"],
@@ -952,7 +1000,6 @@ var BRIZZ_SDK_LANGUAGE = "brizz.sdk.language";
952
1000
  var SDK_LANGUAGE = "typescript";
953
1001
 
954
1002
  // src/internal/instrumentation/registry.ts
955
- import { OpenAIInstrumentation as OpenAIInstrumentation2 } from "@arizeai/openinference-instrumentation-openai";
956
1003
  import { AnthropicInstrumentation as AnthropicInstrumentation2 } from "@traceloop/instrumentation-anthropic";
957
1004
  import { BedrockInstrumentation as BedrockInstrumentation2 } from "@traceloop/instrumentation-bedrock";
958
1005
  import { ChromaDBInstrumentation as ChromaDBInstrumentation2 } from "@traceloop/instrumentation-chromadb";
@@ -1101,9 +1148,11 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
1101
1148
  */
1102
1149
  loadInstrumentation(InstrumentationClass, name, manualModule, exceptionLogger2) {
1103
1150
  try {
1104
- const inst = new InstrumentationClass({
1105
- exceptionLogger: exceptionLogger2 || ((error) => logger.error(`Exception in instrumentation: ${String(error)}`))
1106
- });
1151
+ const inst = bindToBrizz(
1152
+ new InstrumentationClass({
1153
+ exceptionLogger: exceptionLogger2 || ((error) => logger.error(`Exception in instrumentation: ${String(error)}`))
1154
+ })
1155
+ );
1107
1156
  if (manualModule) {
1108
1157
  inst.manuallyInstrument(manualModule);
1109
1158
  logger.debug(`Manual instrumentation enabled for ${name}`);
@@ -1121,7 +1170,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
1121
1170
  loadManualInstrumentations(instrumentations, exceptionLogger2) {
1122
1171
  if (this.manualModules?.openAI) {
1123
1172
  try {
1124
- const openAIInst = new OpenAIInstrumentation2();
1173
+ const openAIInst = new BrizzOpenAIInstrumentation();
1125
1174
  openAIInst.manuallyInstrument(this.manualModules.openAI);
1126
1175
  instrumentations.push(openAIInst);
1127
1176
  logger.debug("Manual instrumentation enabled for OpenAI");
@@ -1162,7 +1211,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
1162
1211
  void (async () => {
1163
1212
  try {
1164
1213
  const { LangChainInstrumentation } = await import("@arizeai/openinference-instrumentation-langchain");
1165
- const lcInst = new LangChainInstrumentation();
1214
+ const lcInst = new LangChainInstrumentation({ tracerProvider: brizzTracerProvider });
1166
1215
  lcInst.manuallyInstrument(callbackManagerModule);
1167
1216
  patchCallbackManagerModule(callbackManagerModule);
1168
1217
  logger.debug("Manual instrumentation enabled for LangChain");
@@ -1194,7 +1243,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
1194
1243
  void (async () => {
1195
1244
  try {
1196
1245
  const { VertexAIInstrumentation } = await import("@traceloop/instrumentation-vertexai");
1197
- const vertexInst = new VertexAIInstrumentation({ exceptionLogger: exceptionLogger2 });
1246
+ const vertexInst = bindToBrizz(new VertexAIInstrumentation({ exceptionLogger: exceptionLogger2 }));
1198
1247
  vertexInst.manuallyInstrument(vertexModule);
1199
1248
  logger.debug("Manual instrumentation enabled for Vertex AI");
1200
1249
  } catch (error) {
@@ -1208,7 +1257,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
1208
1257
  const genaiModule = this.manualModules.google_genai;
1209
1258
  void (async () => {
1210
1259
  try {
1211
- const { GoogleGenAIInstrumentation } = await import("./google-genai-T7I4FFIP.js");
1260
+ const { GoogleGenAIInstrumentation } = await import("./google-genai-3ERJNC7Q.js");
1212
1261
  const genaiInst = new GoogleGenAIInstrumentation({ exceptionLogger: exceptionLogger2 });
1213
1262
  genaiInst.manuallyInstrument(genaiModule);
1214
1263
  logger.debug("Manual instrumentation enabled for Google GenAI");
@@ -1223,7 +1272,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
1223
1272
  const mcpModules = this.manualModules.mcp;
1224
1273
  void (async () => {
1225
1274
  try {
1226
- const { MCPInstrumentation } = await import("./mcp-DBLN5ZBE.js");
1275
+ const { MCPInstrumentation } = await import("./mcp-LLYYMR5M.js");
1227
1276
  const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
1228
1277
  instrumentation.manuallyInstrument(mcpModules);
1229
1278
  logger.debug("Manual instrumentation enabled for MCP");
@@ -1260,13 +1309,14 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
1260
1309
  };
1261
1310
 
1262
1311
  // src/internal/log/logging.ts
1263
- import { SeverityNumber } from "@opentelemetry/api-logs";
1312
+ import { SeverityNumber } from "@opentelemetry/api";
1264
1313
  import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
1265
1314
  import { resourceFromAttributes } from "@opentelemetry/resources";
1266
1315
  import { LoggerProvider } from "@opentelemetry/sdk-logs";
1267
1316
 
1268
1317
  // src/internal/trace/session.ts
1269
1318
  import { context as context4, isSpanContextValid, trace as trace3, SpanStatusCode as SpanStatusCode3 } from "@opentelemetry/api";
1319
+ var sessionTracer = brizzTracerProvider.getTracer("@brizz/sdk");
1270
1320
  function setCurrentSpanCustomProperties(properties) {
1271
1321
  const current = trace3.getActiveSpan();
1272
1322
  if (!current || !current.isRecording()) {
@@ -1898,8 +1948,7 @@ function recordMetricImpl(options) {
1898
1948
  function startSession(sessionId, callback, extraProperties, options) {
1899
1949
  const isTitle = options?.mode === "title";
1900
1950
  const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
1901
- const tracer = trace3.getTracer("@brizz/sdk");
1902
- return tracer.startActiveSpan(spanName, (span) => {
1951
+ return sessionTracer.startActiveSpan(spanName, (span) => {
1903
1952
  span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
1904
1953
  if (extraProperties) {
1905
1954
  for (const [key, value] of Object.entries(extraProperties)) {
@@ -1946,8 +1995,7 @@ function startSession(sessionId, callback, extraProperties, options) {
1946
1995
  }
1947
1996
  function startSessionTitle(callback, options) {
1948
1997
  const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
1949
- const tracer = trace3.getTracer("@brizz/sdk");
1950
- return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
1998
+ return sessionTracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
1951
1999
  if (resolvedSessionId) {
1952
2000
  span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
1953
2001
  }
@@ -2646,6 +2694,11 @@ var LoggingModule = class _LoggingModule {
2646
2694
  getLoggerProvider() {
2647
2695
  return this.loggerProvider;
2648
2696
  }
2697
+ async forceFlush() {
2698
+ await Promise.all(
2699
+ [...this.scopedProviders.values(), this.loggerProvider].map(async (p) => p?.forceFlush())
2700
+ );
2701
+ }
2649
2702
  /**
2650
2703
  * Shutdown the logging module
2651
2704
  */
@@ -2755,6 +2808,9 @@ var MetricsModule = class _MetricsModule {
2755
2808
  }
2756
2809
  return this.metricsReader;
2757
2810
  }
2811
+ async forceFlush() {
2812
+ await this.metricsReader?.forceFlush();
2813
+ }
2758
2814
  /**
2759
2815
  * Shutdown the metrics module
2760
2816
  */
@@ -2934,7 +2990,7 @@ import { context as context6 } from "@opentelemetry/api";
2934
2990
  import {
2935
2991
  BatchSpanProcessor,
2936
2992
  SimpleSpanProcessor
2937
- } from "@opentelemetry/sdk-trace-base";
2993
+ } from "@opentelemetry/sdk-trace";
2938
2994
  function applyContextAttributes(span) {
2939
2995
  const sessionProperties = context6.active().getValue(PROPERTIES_CONTEXT_KEY);
2940
2996
  if (sessionProperties) {
@@ -2956,7 +3012,10 @@ var LIBRARY_ID_ATTRIBUTES = [
2956
3012
  "langsmith.metadata.thread_id",
2957
3013
  "langsmith.metadata.session_id",
2958
3014
  "langsmith.metadata.conversation_id",
2959
- "langsmith.trace.session_id"
3015
+ "langsmith.trace.session_id",
3016
+ // User-id aliases the streamer copies into brizz.user.id (userIDAliases).
3017
+ "user.id",
3018
+ "langfuse.user.id"
2960
3019
  ];
2961
3020
  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("|")})$)`;
2962
3021
  var isText = (value) => typeof value === "string" || Array.isArray(value) && value.some((item) => typeof item === "string");
@@ -2970,7 +3029,7 @@ var DEFAULT_MASKING_RULES = [
2970
3029
  var BrizzSimpleSpanProcessor = class extends SimpleSpanProcessor {
2971
3030
  config;
2972
3031
  constructor(spanExporter, config) {
2973
- super(spanExporter);
3032
+ super({ exporter: spanExporter });
2974
3033
  this.config = config;
2975
3034
  }
2976
3035
  onStart(span, parentContext) {
@@ -2989,7 +3048,7 @@ var BrizzSimpleSpanProcessor = class extends SimpleSpanProcessor {
2989
3048
  var BrizzBatchSpanProcessor = class extends BatchSpanProcessor {
2990
3049
  config;
2991
3050
  constructor(spanExporter, config) {
2992
- super(spanExporter);
3051
+ super({ exporter: spanExporter });
2993
3052
  this.config = config;
2994
3053
  }
2995
3054
  onStart(span, parentContext) {
@@ -3130,6 +3189,9 @@ var TracingModule = class _TracingModule {
3130
3189
  }
3131
3190
  return this.spanProcessor;
3132
3191
  }
3192
+ async forceFlush() {
3193
+ await this.spanProcessor?.forceFlush();
3194
+ }
3133
3195
  async shutdown() {
3134
3196
  logger.debug("Shutting down tracing module");
3135
3197
  if (this.spanProcessor) {
@@ -3153,7 +3215,7 @@ function getSpanProcessor() {
3153
3215
 
3154
3216
  // src/internal/trace/agent.ts
3155
3217
  import { randomUUID } from "crypto";
3156
- import { context as context7, propagation } from "@opentelemetry/api";
3218
+ import { context as context7 } from "@opentelemetry/api";
3157
3219
  function newInstanceId() {
3158
3220
  return randomUUID().replaceAll("-", "").slice(0, 8);
3159
3221
  }
@@ -3173,7 +3235,7 @@ function encodeToken(agent) {
3173
3235
  function currentTraceparent() {
3174
3236
  const carrier = {};
3175
3237
  try {
3176
- propagation.inject(context7.active(), carrier);
3238
+ injectTraceContext(context7.active(), carrier);
3177
3239
  } catch {
3178
3240
  }
3179
3241
  return carrier["traceparent"] ?? "";
@@ -3234,7 +3296,7 @@ function resolveAgent(agent) {
3234
3296
  sessionId = decoded.sessionId;
3235
3297
  if (decoded.traceparent) {
3236
3298
  try {
3237
- parentContext = propagation.extract(parentContext, { traceparent: decoded.traceparent });
3299
+ parentContext = extractTraceContext(parentContext, { traceparent: decoded.traceparent });
3238
3300
  } catch {
3239
3301
  }
3240
3302
  }
@@ -3287,6 +3349,11 @@ function resolveMcpSessionTracking(configured) {
3287
3349
  const enabled = fromEnv === "true";
3288
3350
  return typeof configured === "object" ? { ...configured, enabled } : enabled;
3289
3351
  }
3352
+ var BRIZZ_OWNED = /* @__PURE__ */ Symbol.for("brizz.sdk.ownedTracerProvider");
3353
+ function globalTracerDelegate() {
3354
+ const global = trace4.getTracerProvider();
3355
+ return typeof global.getDelegate === "function" ? global.getDelegate() : global;
3356
+ }
3290
3357
  var _Brizz = class __Brizz {
3291
3358
  static instance = null;
3292
3359
  static getInstance() {
@@ -3324,8 +3391,17 @@ var _Brizz = class __Brizz {
3324
3391
  const registry = InstrumentationRegistry.getInstance();
3325
3392
  const manualInstrumentations = registry.getManualInstrumentations();
3326
3393
  if (options.disableNodeSdk) {
3394
+ setPrivateTracerProvider(null);
3395
+ if (!resolvedConfig.setGlobalTracerProvider) {
3396
+ logger.warn(
3397
+ "Brizz: setGlobalTracerProvider: false has no effect with disableNodeSdk: true. Brizz creates no TracerProvider, so spans follow the provider you register with getSpanProcessor()."
3398
+ );
3399
+ }
3327
3400
  if (manualInstrumentations.length > 0) {
3328
- registerInstrumentations2({ instrumentations: manualInstrumentations });
3401
+ registerInstrumentations2({
3402
+ instrumentations: manualInstrumentations,
3403
+ tracerProvider: brizzTracerProvider
3404
+ });
3329
3405
  }
3330
3406
  logger.info("NodeSDK disabled - only telemetry modules initialized");
3331
3407
  return;
@@ -3343,15 +3419,34 @@ var _Brizz = class __Brizz {
3343
3419
  resourceAttributes["service.version"] = resolvedConfig.appVersion;
3344
3420
  }
3345
3421
  const resource = defaultResource().merge(detectResources({ detectors: [envDetector, hostDetector, processDetector] })).merge(resourceFromAttributes3(resourceAttributes));
3346
- this._tracerProvider = new NodeTracerProvider({
3347
- resource,
3348
- spanProcessors: resolvedConfig.disableSpanExporter ? [] : [new InterruptPropagator(), getSpanProcessor()]
3349
- });
3350
- this._tracerProvider.register();
3422
+ const spanProcessors = resolvedConfig.disableSpanExporter ? [] : [new InterruptPropagator(), getSpanProcessor()];
3423
+ if (resolvedConfig.setGlobalTracerProvider) {
3424
+ this._tracerProvider = new SdkTracerProvider({ resource, spanProcessors });
3425
+ this.registerGlobalTracerProvider(this._tracerProvider);
3426
+ } else {
3427
+ this._tracerProvider = new SdkTracerProvider({
3428
+ resource,
3429
+ spanProcessors,
3430
+ sampler: new AlwaysOnSampler()
3431
+ });
3432
+ if (ensureContextManager() === "failed") {
3433
+ logger.warn(
3434
+ "Brizz: no OpenTelemetry context manager is active and Brizz could not install one; span parenting and session/user propagation will not work."
3435
+ );
3436
+ }
3437
+ setPrivateTracerProvider(this._tracerProvider);
3438
+ logger.info(
3439
+ "Brizz: using a private TracerProvider; Brizz spans are exported to Brizz only and the global TracerProvider is left untouched."
3440
+ );
3441
+ }
3442
+ Reflect.set(this._tracerProvider, BRIZZ_OWNED, true);
3351
3443
  this._meterProvider = new MeterProvider({ resource, readers: [getMetricsReader()] });
3352
3444
  metrics.setGlobalMeterProvider(this._meterProvider);
3353
3445
  if (manualInstrumentations.length > 0) {
3354
- registerInstrumentations2({ instrumentations: manualInstrumentations });
3446
+ registerInstrumentations2({
3447
+ instrumentations: manualInstrumentations,
3448
+ tracerProvider: brizzTracerProvider
3449
+ });
3355
3450
  logger.info(
3356
3451
  `Telemetry providers started with ${manualInstrumentations.length} manual instrumentations`
3357
3452
  );
@@ -3361,6 +3456,27 @@ var _Brizz = class __Brizz {
3361
3456
  );
3362
3457
  }
3363
3458
  }
3459
+ /**
3460
+ * Register `provider` globally and say so when another provider already
3461
+ * holds the slot: OpenTelemetry refuses the second registration without a
3462
+ * word, and every Brizz span then goes to the other provider.
3463
+ * @private
3464
+ */
3465
+ registerGlobalTracerProvider(provider) {
3466
+ setPrivateTracerProvider(null);
3467
+ registerTracerProvider(provider);
3468
+ const registered = globalTracerDelegate();
3469
+ if (registered === provider) {
3470
+ return;
3471
+ }
3472
+ if (Reflect.get(registered, BRIZZ_OWNED) === true) {
3473
+ logger.debug("A TracerProvider from an earlier Brizz.initialize() is still registered");
3474
+ return;
3475
+ }
3476
+ logger.warn(
3477
+ "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."
3478
+ );
3479
+ }
3364
3480
  /**
3365
3481
  * Initialize telemetry modules.
3366
3482
  *
@@ -3459,6 +3575,62 @@ var _Brizz = class __Brizz {
3459
3575
  throw new Error(`Failed to initialize SDK: ${String(error)}`, { cause: error });
3460
3576
  }
3461
3577
  }
3578
+ /**
3579
+ * Send the telemetry Brizz has queued, without shutting down.
3580
+ *
3581
+ * On serverless platforms that throttle CPU once a response is sent (Cloud
3582
+ * Run, Lambda), await it before responding: the batch timer may not fire
3583
+ * again before the instance is frozen or recycled. Never throws.
3584
+ *
3585
+ * @param timeoutMillis - How long to wait. Defaults to 5000.
3586
+ * @returns `true` when everything was sent within the budget; `false` on a
3587
+ * timeout, an export error, or before `initialize()`.
3588
+ *
3589
+ * @example
3590
+ * ```typescript
3591
+ * await Brizz.flush();
3592
+ * res.send(reply);
3593
+ * ```
3594
+ */
3595
+ async flush(timeoutMillis = 5e3) {
3596
+ if (!this._initialized) {
3597
+ logger.debug("Brizz.flush called before Brizz.initialize; nothing to flush");
3598
+ return false;
3599
+ }
3600
+ const settle = async (name, flush) => {
3601
+ try {
3602
+ await flush();
3603
+ return true;
3604
+ } catch (error) {
3605
+ logger.debug(`Brizz.flush: flushing ${name} failed: ${String(error)}`);
3606
+ return false;
3607
+ }
3608
+ };
3609
+ const work = Promise.all([
3610
+ settle("spans", () => TracingModule.getInstance().forceFlush()),
3611
+ settle("logs", () => LoggingModule.getInstance().forceFlush()),
3612
+ // Under disableNodeSdk the reader belongs to whatever MeterProvider the
3613
+ // app registered, if any; an unbound reader cannot flush.
3614
+ ...this._meterProvider ? [settle("metrics", () => MetricsModule.getInstance().forceFlush())] : []
3615
+ ]).then((results) => results.every(Boolean));
3616
+ let timer;
3617
+ const timedOut = new Promise((resolve) => {
3618
+ timer = setTimeout(() => resolve("timeout"), timeoutMillis);
3619
+ timer.unref();
3620
+ });
3621
+ try {
3622
+ const result = await Promise.race([work, timedOut]);
3623
+ if (result === "timeout") {
3624
+ logger.warn(
3625
+ `Brizz.flush did not finish within ${timeoutMillis}ms; telemetry still queued will be sent with the next batch.`
3626
+ );
3627
+ return false;
3628
+ }
3629
+ return result;
3630
+ } finally {
3631
+ clearTimeout(timer);
3632
+ }
3633
+ }
3462
3634
  /**
3463
3635
  * Gracefully shutdown the Brizz SDK.
3464
3636
  *
@@ -3503,7 +3675,7 @@ var _Brizz = class __Brizz {
3503
3675
  var Brizz = new _Brizz();
3504
3676
 
3505
3677
  // src/index.ts
3506
- import { SeverityNumber as SeverityNumber2 } from "@opentelemetry/api-logs";
3678
+ import { SeverityNumber as SeverityNumber2 } from "@opentelemetry/api";
3507
3679
  export {
3508
3680
  Brizz,
3509
3681
  DEFAULT_PII_PATTERNS,
@@ -3527,6 +3699,7 @@ export {
3527
3699
  getMetricsReader,
3528
3700
  getSpanExporter,
3529
3701
  getSpanProcessor,
3702
+ getTracerProvider,
3530
3703
  logger,
3531
3704
  maskAttributes,
3532
3705
  maskValue,