@brizz/sdk 0.1.53 → 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.
- package/README.md +38 -0
- package/dist/chunk-DBN4NKIG.js +107 -0
- package/dist/{chunk-KFETJN5M.cjs → chunk-FQBVTIBR.cjs} +7 -0
- package/dist/{chunk-STTOBCTP.cjs → chunk-KGNFUQ6Z.cjs} +1 -1
- package/dist/{chunk-XV3ZJO5K.js → chunk-MLMF2O5P.js} +1 -1
- package/dist/chunk-VZJNEST4.cjs +107 -0
- package/dist/{chunk-TEY6FAVZ.js → chunk-YGLDHCWC.js} +7 -0
- package/dist/google-genai-44O4QORJ.cjs +11 -0
- package/dist/{google-genai-T7I4FFIP.js → google-genai-PERR37LR.js} +2 -1
- package/dist/google-genai.cjs +3 -2
- package/dist/google-genai.js +2 -1
- package/dist/index.cjs +226 -54
- package/dist/index.js +210 -38
- package/dist/{mcp-KH5LOG5H.cjs → mcp-4M4XL46N.cjs} +39 -16
- package/dist/{mcp-DBLN5ZBE.js → mcp-KU7MFTOB.js} +29 -6
- package/dist/types/cjs/index.d.ts +1 -1
- package/dist/types/cjs/internal/config.d.ts +1 -0
- package/dist/types/cjs/internal/instrumentation/openai.d.ts +5 -0
- package/dist/types/cjs/internal/log/logging.d.ts +1 -0
- package/dist/types/cjs/internal/metric/metrics.d.ts +1 -0
- package/dist/types/cjs/internal/sdk.d.ts +3 -0
- package/dist/types/cjs/internal/trace/index.d.ts +1 -0
- package/dist/types/cjs/internal/trace/provider.d.ts +15 -0
- package/dist/types/cjs/internal/trace/tracing.d.ts +1 -0
- package/dist/types/esm/index.d.ts +1 -1
- package/dist/types/esm/internal/config.d.ts +1 -0
- package/dist/types/esm/internal/instrumentation/openai.d.ts +5 -0
- package/dist/types/esm/internal/log/logging.d.ts +1 -0
- package/dist/types/esm/internal/metric/metrics.d.ts +1 -0
- package/dist/types/esm/internal/sdk.d.ts +3 -0
- package/dist/types/esm/internal/trace/index.d.ts +1 -0
- package/dist/types/esm/internal/trace/provider.d.ts +15 -0
- package/dist/types/esm/internal/trace/tracing.d.ts +1 -0
- package/package.json +16 -15
- package/dist/google-genai-LMEZ62FB.cjs +0 -10
package/dist/index.js
CHANGED
|
@@ -5,7 +5,16 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
configure,
|
|
7
7
|
getSDKVersion
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-MLMF2O5P.js";
|
|
9
|
+
import {
|
|
10
|
+
bindToBrizz,
|
|
11
|
+
brizzTracerProvider,
|
|
12
|
+
ensureContextManager,
|
|
13
|
+
extractTraceContext,
|
|
14
|
+
getTracerProvider,
|
|
15
|
+
injectTraceContext,
|
|
16
|
+
setPrivateTracerProvider
|
|
17
|
+
} from "./chunk-DBN4NKIG.js";
|
|
9
18
|
import {
|
|
10
19
|
DEFAULT_LOG_LEVEL,
|
|
11
20
|
LogLevel,
|
|
@@ -83,7 +92,6 @@ import {
|
|
|
83
92
|
} from "./chunk-3RG5ZIWI.js";
|
|
84
93
|
|
|
85
94
|
// src/internal/instrumentation/auto-init.ts
|
|
86
|
-
import { OpenAIInstrumentation } from "@arizeai/openinference-instrumentation-openai";
|
|
87
95
|
import { registerInstrumentations } from "@opentelemetry/instrumentation";
|
|
88
96
|
import { AnthropicInstrumentation } from "@traceloop/instrumentation-anthropic";
|
|
89
97
|
import { BedrockInstrumentation } from "@traceloop/instrumentation-bedrock";
|
|
@@ -174,6 +182,7 @@ var parentRecorded = /* @__PURE__ */ new WeakSet();
|
|
|
174
182
|
var LangGraphInstrumentation = class extends InstrumentationBase {
|
|
175
183
|
constructor(config = {}) {
|
|
176
184
|
super(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION, config);
|
|
185
|
+
this.setTracerProvider(brizzTracerProvider);
|
|
177
186
|
}
|
|
178
187
|
init() {
|
|
179
188
|
return [
|
|
@@ -426,6 +435,14 @@ function attachRunToIteration(stream, run) {
|
|
|
426
435
|
return iterable;
|
|
427
436
|
}
|
|
428
437
|
|
|
438
|
+
// src/internal/instrumentation/openai.ts
|
|
439
|
+
import { OpenAIInstrumentation } from "@arizeai/openinference-instrumentation-openai";
|
|
440
|
+
var BrizzOpenAIInstrumentation = class extends OpenAIInstrumentation {
|
|
441
|
+
get tracer() {
|
|
442
|
+
return brizzTracerProvider.getTracer(this.instrumentationName, this.instrumentationVersion);
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
|
|
429
446
|
// src/internal/instrumentation/typesafe.ts
|
|
430
447
|
import { createRequire as createRequire2 } from "module";
|
|
431
448
|
import { SpanKind, SpanStatusCode as SpanStatusCode2, context as context2, trace as trace2 } from "@opentelemetry/api";
|
|
@@ -452,6 +469,7 @@ var PATCHED_FLAG2 = /* @__PURE__ */ Symbol.for("brizz.typesafe.patched");
|
|
|
452
469
|
var TypeSafeInstrumentation = class extends InstrumentationBase2 {
|
|
453
470
|
constructor(config = {}) {
|
|
454
471
|
super(INSTRUMENTATION_NAME2, getSDKVersion(), config);
|
|
472
|
+
this.setTracerProvider(brizzTracerProvider);
|
|
455
473
|
}
|
|
456
474
|
init() {
|
|
457
475
|
return [
|
|
@@ -644,7 +662,7 @@ var exceptionLogger = (error) => {
|
|
|
644
662
|
function loadGenAIInstrumentations() {
|
|
645
663
|
const instrumentations = [];
|
|
646
664
|
try {
|
|
647
|
-
instrumentations.push(new
|
|
665
|
+
instrumentations.push(new BrizzOpenAIInstrumentation());
|
|
648
666
|
logger.debug("Auto-loaded OpenAI instrumentation");
|
|
649
667
|
} catch (error) {
|
|
650
668
|
logger.error(`Failed to auto-load OpenAI instrumentation: ${String(error)}`);
|
|
@@ -669,7 +687,7 @@ function loadGenAIInstrumentations() {
|
|
|
669
687
|
}
|
|
670
688
|
}
|
|
671
689
|
try {
|
|
672
|
-
registerInstrumentations({ instrumentations });
|
|
690
|
+
registerInstrumentations({ instrumentations, tracerProvider: brizzTracerProvider });
|
|
673
691
|
logger.info(`Auto-registered ${instrumentations.length} GenAI instrumentations`);
|
|
674
692
|
} catch (error) {
|
|
675
693
|
logger.error(`Failed to register GenAI instrumentations: ${String(error)}`);
|
|
@@ -679,9 +697,9 @@ function loadGenAIInstrumentations() {
|
|
|
679
697
|
function loadMCPInstrumentation() {
|
|
680
698
|
void (async () => {
|
|
681
699
|
try {
|
|
682
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
700
|
+
const { MCPInstrumentation } = await import("./mcp-KU7MFTOB.js");
|
|
683
701
|
const mcp = new MCPInstrumentation({ exceptionLogger });
|
|
684
|
-
registerInstrumentations({ instrumentations: [mcp] });
|
|
702
|
+
registerInstrumentations({ instrumentations: [mcp], tracerProvider: brizzTracerProvider });
|
|
685
703
|
logger.debug("Auto-loaded MCP instrumentation");
|
|
686
704
|
} catch (error) {
|
|
687
705
|
logger.debug(
|
|
@@ -692,7 +710,10 @@ function loadMCPInstrumentation() {
|
|
|
692
710
|
}
|
|
693
711
|
function loadLangGraphInstrumentation() {
|
|
694
712
|
try {
|
|
695
|
-
registerInstrumentations({
|
|
713
|
+
registerInstrumentations({
|
|
714
|
+
instrumentations: [new LangGraphInstrumentation()],
|
|
715
|
+
tracerProvider: brizzTracerProvider
|
|
716
|
+
});
|
|
696
717
|
logger.debug("Auto-loaded LangGraph instrumentation");
|
|
697
718
|
} catch (error) {
|
|
698
719
|
logger.debug(`LangGraph instrumentation not loaded: ${String(error)}`);
|
|
@@ -700,7 +721,10 @@ function loadLangGraphInstrumentation() {
|
|
|
700
721
|
}
|
|
701
722
|
function loadTypeSafeInstrumentation() {
|
|
702
723
|
try {
|
|
703
|
-
registerInstrumentations({
|
|
724
|
+
registerInstrumentations({
|
|
725
|
+
instrumentations: [new TypeSafeInstrumentation()],
|
|
726
|
+
tracerProvider: brizzTracerProvider
|
|
727
|
+
});
|
|
704
728
|
logger.debug("Auto-loaded TypeSafe instrumentation");
|
|
705
729
|
} catch (error) {
|
|
706
730
|
logger.debug(`TypeSafe instrumentation not loaded: ${String(error)}`);
|
|
@@ -711,7 +735,10 @@ function loadVertexAIInstrumentation() {
|
|
|
711
735
|
try {
|
|
712
736
|
const { VertexAIInstrumentation } = await import("@traceloop/instrumentation-vertexai");
|
|
713
737
|
const vertexAI = new VertexAIInstrumentation({ exceptionLogger });
|
|
714
|
-
registerInstrumentations({
|
|
738
|
+
registerInstrumentations({
|
|
739
|
+
instrumentations: [vertexAI],
|
|
740
|
+
tracerProvider: brizzTracerProvider
|
|
741
|
+
});
|
|
715
742
|
logger.debug("Auto-loaded Vertex AI instrumentation");
|
|
716
743
|
} catch (error) {
|
|
717
744
|
logger.debug(
|
|
@@ -723,9 +750,12 @@ function loadVertexAIInstrumentation() {
|
|
|
723
750
|
function loadGoogleGenAIInstrumentation() {
|
|
724
751
|
void (async () => {
|
|
725
752
|
try {
|
|
726
|
-
const { GoogleGenAIInstrumentation } = await import("./google-genai-
|
|
753
|
+
const { GoogleGenAIInstrumentation } = await import("./google-genai-PERR37LR.js");
|
|
727
754
|
const googleGenAI = new GoogleGenAIInstrumentation({ exceptionLogger });
|
|
728
|
-
registerInstrumentations({
|
|
755
|
+
registerInstrumentations({
|
|
756
|
+
instrumentations: [googleGenAI],
|
|
757
|
+
tracerProvider: brizzTracerProvider
|
|
758
|
+
});
|
|
729
759
|
logger.debug("Auto-loaded Google GenAI instrumentation");
|
|
730
760
|
} catch (error) {
|
|
731
761
|
logger.debug(
|
|
@@ -757,7 +787,9 @@ function loadVercelAITelemetry() {
|
|
|
757
787
|
try {
|
|
758
788
|
const otel = await import("@ai-sdk/otel");
|
|
759
789
|
if (typeof otel.LegacyOpenTelemetry === "function") {
|
|
760
|
-
integrations.push(
|
|
790
|
+
integrations.push(
|
|
791
|
+
new otel.LegacyOpenTelemetry({ tracer: brizzTracerProvider.getTracer("ai") })
|
|
792
|
+
);
|
|
761
793
|
otelCollectorLoaded = true;
|
|
762
794
|
}
|
|
763
795
|
} catch {
|
|
@@ -800,7 +832,7 @@ function autoInitializeInstrumentations() {
|
|
|
800
832
|
var autoInstrumentationsLoaded = autoInitializeInstrumentations();
|
|
801
833
|
|
|
802
834
|
// src/internal/sdk.ts
|
|
803
|
-
import { metrics } from "@opentelemetry/api";
|
|
835
|
+
import { metrics, trace as trace4 } from "@opentelemetry/api";
|
|
804
836
|
import { registerInstrumentations as registerInstrumentations2 } from "@opentelemetry/instrumentation";
|
|
805
837
|
import {
|
|
806
838
|
defaultResource,
|
|
@@ -811,9 +843,22 @@ import {
|
|
|
811
843
|
resourceFromAttributes as resourceFromAttributes3
|
|
812
844
|
} from "@opentelemetry/resources";
|
|
813
845
|
import { MeterProvider } from "@opentelemetry/sdk-metrics";
|
|
846
|
+
import { AlwaysOnSampler } from "@opentelemetry/sdk-trace-base";
|
|
814
847
|
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
815
848
|
|
|
816
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
|
+
logger.warn(`Brizz: ignoring ${name}=${raw}; expected true or false.`);
|
|
860
|
+
return void 0;
|
|
861
|
+
}
|
|
817
862
|
function resolveConfig(options) {
|
|
818
863
|
const envLogLevel = process.env["BRIZZ_LOG_LEVEL"] || options.logLevel?.toString() || DEFAULT_LOG_LEVEL.toString();
|
|
819
864
|
let resolvedLogLevel;
|
|
@@ -865,7 +910,8 @@ function resolveConfig(options) {
|
|
|
865
910
|
disableSpanExporter: process.env["BRIZZ_DISABLE_SPAN_EXPORTER"] === "true" || !!options.disableSpanExporter,
|
|
866
911
|
environment: process.env["BRIZZ_ENVIRONMENT"] || options.environment,
|
|
867
912
|
logLevel: resolvedLogLevel,
|
|
868
|
-
masking: resolvedMasking
|
|
913
|
+
masking: resolvedMasking,
|
|
914
|
+
setGlobalTracerProvider: parseBoolEnv("BRIZZ_SET_GLOBAL_TRACER_PROVIDER") ?? options.setGlobalTracerProvider ?? true
|
|
869
915
|
};
|
|
870
916
|
const dsnInput = process.env["BRIZZ_DSN"] || options.dsn;
|
|
871
917
|
let parsedDSN = null;
|
|
@@ -935,6 +981,7 @@ function resolveConfig(options) {
|
|
|
935
981
|
hasApiKey: !!resolvedConfig.apiKey,
|
|
936
982
|
dsnProvided: !!dsnInput,
|
|
937
983
|
disableBatch: resolvedConfig.disableBatch,
|
|
984
|
+
setGlobalTracerProvider: resolvedConfig.setGlobalTracerProvider,
|
|
938
985
|
envOverrides: {
|
|
939
986
|
hasEnvApiKey: !!process.env["BRIZZ_API_KEY"],
|
|
940
987
|
hasEnvBaseUrl: !!process.env["BRIZZ_BASE_URL"],
|
|
@@ -952,7 +999,6 @@ var BRIZZ_SDK_LANGUAGE = "brizz.sdk.language";
|
|
|
952
999
|
var SDK_LANGUAGE = "typescript";
|
|
953
1000
|
|
|
954
1001
|
// src/internal/instrumentation/registry.ts
|
|
955
|
-
import { OpenAIInstrumentation as OpenAIInstrumentation2 } from "@arizeai/openinference-instrumentation-openai";
|
|
956
1002
|
import { AnthropicInstrumentation as AnthropicInstrumentation2 } from "@traceloop/instrumentation-anthropic";
|
|
957
1003
|
import { BedrockInstrumentation as BedrockInstrumentation2 } from "@traceloop/instrumentation-bedrock";
|
|
958
1004
|
import { ChromaDBInstrumentation as ChromaDBInstrumentation2 } from "@traceloop/instrumentation-chromadb";
|
|
@@ -1101,9 +1147,11 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
1101
1147
|
*/
|
|
1102
1148
|
loadInstrumentation(InstrumentationClass, name, manualModule, exceptionLogger2) {
|
|
1103
1149
|
try {
|
|
1104
|
-
const inst =
|
|
1105
|
-
|
|
1106
|
-
|
|
1150
|
+
const inst = bindToBrizz(
|
|
1151
|
+
new InstrumentationClass({
|
|
1152
|
+
exceptionLogger: exceptionLogger2 || ((error) => logger.error(`Exception in instrumentation: ${String(error)}`))
|
|
1153
|
+
})
|
|
1154
|
+
);
|
|
1107
1155
|
if (manualModule) {
|
|
1108
1156
|
inst.manuallyInstrument(manualModule);
|
|
1109
1157
|
logger.debug(`Manual instrumentation enabled for ${name}`);
|
|
@@ -1121,7 +1169,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
1121
1169
|
loadManualInstrumentations(instrumentations, exceptionLogger2) {
|
|
1122
1170
|
if (this.manualModules?.openAI) {
|
|
1123
1171
|
try {
|
|
1124
|
-
const openAIInst = new
|
|
1172
|
+
const openAIInst = new BrizzOpenAIInstrumentation();
|
|
1125
1173
|
openAIInst.manuallyInstrument(this.manualModules.openAI);
|
|
1126
1174
|
instrumentations.push(openAIInst);
|
|
1127
1175
|
logger.debug("Manual instrumentation enabled for OpenAI");
|
|
@@ -1162,7 +1210,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
1162
1210
|
void (async () => {
|
|
1163
1211
|
try {
|
|
1164
1212
|
const { LangChainInstrumentation } = await import("@arizeai/openinference-instrumentation-langchain");
|
|
1165
|
-
const lcInst = new LangChainInstrumentation();
|
|
1213
|
+
const lcInst = new LangChainInstrumentation({ tracerProvider: brizzTracerProvider });
|
|
1166
1214
|
lcInst.manuallyInstrument(callbackManagerModule);
|
|
1167
1215
|
patchCallbackManagerModule(callbackManagerModule);
|
|
1168
1216
|
logger.debug("Manual instrumentation enabled for LangChain");
|
|
@@ -1194,7 +1242,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
1194
1242
|
void (async () => {
|
|
1195
1243
|
try {
|
|
1196
1244
|
const { VertexAIInstrumentation } = await import("@traceloop/instrumentation-vertexai");
|
|
1197
|
-
const vertexInst = new VertexAIInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
1245
|
+
const vertexInst = bindToBrizz(new VertexAIInstrumentation({ exceptionLogger: exceptionLogger2 }));
|
|
1198
1246
|
vertexInst.manuallyInstrument(vertexModule);
|
|
1199
1247
|
logger.debug("Manual instrumentation enabled for Vertex AI");
|
|
1200
1248
|
} catch (error) {
|
|
@@ -1208,7 +1256,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
1208
1256
|
const genaiModule = this.manualModules.google_genai;
|
|
1209
1257
|
void (async () => {
|
|
1210
1258
|
try {
|
|
1211
|
-
const { GoogleGenAIInstrumentation } = await import("./google-genai-
|
|
1259
|
+
const { GoogleGenAIInstrumentation } = await import("./google-genai-PERR37LR.js");
|
|
1212
1260
|
const genaiInst = new GoogleGenAIInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
1213
1261
|
genaiInst.manuallyInstrument(genaiModule);
|
|
1214
1262
|
logger.debug("Manual instrumentation enabled for Google GenAI");
|
|
@@ -1223,7 +1271,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
1223
1271
|
const mcpModules = this.manualModules.mcp;
|
|
1224
1272
|
void (async () => {
|
|
1225
1273
|
try {
|
|
1226
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
1274
|
+
const { MCPInstrumentation } = await import("./mcp-KU7MFTOB.js");
|
|
1227
1275
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
1228
1276
|
instrumentation.manuallyInstrument(mcpModules);
|
|
1229
1277
|
logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -1267,6 +1315,7 @@ import { LoggerProvider } from "@opentelemetry/sdk-logs";
|
|
|
1267
1315
|
|
|
1268
1316
|
// src/internal/trace/session.ts
|
|
1269
1317
|
import { context as context4, isSpanContextValid, trace as trace3, SpanStatusCode as SpanStatusCode3 } from "@opentelemetry/api";
|
|
1318
|
+
var sessionTracer = brizzTracerProvider.getTracer("@brizz/sdk");
|
|
1270
1319
|
function setCurrentSpanCustomProperties(properties) {
|
|
1271
1320
|
const current = trace3.getActiveSpan();
|
|
1272
1321
|
if (!current || !current.isRecording()) {
|
|
@@ -1898,8 +1947,7 @@ function recordMetricImpl(options) {
|
|
|
1898
1947
|
function startSession(sessionId, callback, extraProperties, options) {
|
|
1899
1948
|
const isTitle = options?.mode === "title";
|
|
1900
1949
|
const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
|
|
1901
|
-
|
|
1902
|
-
return tracer.startActiveSpan(spanName, (span) => {
|
|
1950
|
+
return sessionTracer.startActiveSpan(spanName, (span) => {
|
|
1903
1951
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
1904
1952
|
if (extraProperties) {
|
|
1905
1953
|
for (const [key, value] of Object.entries(extraProperties)) {
|
|
@@ -1946,8 +1994,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1946
1994
|
}
|
|
1947
1995
|
function startSessionTitle(callback, options) {
|
|
1948
1996
|
const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
|
|
1949
|
-
|
|
1950
|
-
return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
|
|
1997
|
+
return sessionTracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
|
|
1951
1998
|
if (resolvedSessionId) {
|
|
1952
1999
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
|
|
1953
2000
|
}
|
|
@@ -2646,6 +2693,11 @@ var LoggingModule = class _LoggingModule {
|
|
|
2646
2693
|
getLoggerProvider() {
|
|
2647
2694
|
return this.loggerProvider;
|
|
2648
2695
|
}
|
|
2696
|
+
async forceFlush() {
|
|
2697
|
+
await Promise.all(
|
|
2698
|
+
[...this.scopedProviders.values(), this.loggerProvider].map(async (p) => p?.forceFlush())
|
|
2699
|
+
);
|
|
2700
|
+
}
|
|
2649
2701
|
/**
|
|
2650
2702
|
* Shutdown the logging module
|
|
2651
2703
|
*/
|
|
@@ -2755,6 +2807,9 @@ var MetricsModule = class _MetricsModule {
|
|
|
2755
2807
|
}
|
|
2756
2808
|
return this.metricsReader;
|
|
2757
2809
|
}
|
|
2810
|
+
async forceFlush() {
|
|
2811
|
+
await this.metricsReader?.forceFlush();
|
|
2812
|
+
}
|
|
2758
2813
|
/**
|
|
2759
2814
|
* Shutdown the metrics module
|
|
2760
2815
|
*/
|
|
@@ -2956,7 +3011,10 @@ var LIBRARY_ID_ATTRIBUTES = [
|
|
|
2956
3011
|
"langsmith.metadata.thread_id",
|
|
2957
3012
|
"langsmith.metadata.session_id",
|
|
2958
3013
|
"langsmith.metadata.conversation_id",
|
|
2959
|
-
"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"
|
|
2960
3018
|
];
|
|
2961
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("|")})$)`;
|
|
2962
3020
|
var isText = (value) => typeof value === "string" || Array.isArray(value) && value.some((item) => typeof item === "string");
|
|
@@ -3130,6 +3188,9 @@ var TracingModule = class _TracingModule {
|
|
|
3130
3188
|
}
|
|
3131
3189
|
return this.spanProcessor;
|
|
3132
3190
|
}
|
|
3191
|
+
async forceFlush() {
|
|
3192
|
+
await this.spanProcessor?.forceFlush();
|
|
3193
|
+
}
|
|
3133
3194
|
async shutdown() {
|
|
3134
3195
|
logger.debug("Shutting down tracing module");
|
|
3135
3196
|
if (this.spanProcessor) {
|
|
@@ -3153,7 +3214,7 @@ function getSpanProcessor() {
|
|
|
3153
3214
|
|
|
3154
3215
|
// src/internal/trace/agent.ts
|
|
3155
3216
|
import { randomUUID } from "crypto";
|
|
3156
|
-
import { context as context7
|
|
3217
|
+
import { context as context7 } from "@opentelemetry/api";
|
|
3157
3218
|
function newInstanceId() {
|
|
3158
3219
|
return randomUUID().replaceAll("-", "").slice(0, 8);
|
|
3159
3220
|
}
|
|
@@ -3173,7 +3234,7 @@ function encodeToken(agent) {
|
|
|
3173
3234
|
function currentTraceparent() {
|
|
3174
3235
|
const carrier = {};
|
|
3175
3236
|
try {
|
|
3176
|
-
|
|
3237
|
+
injectTraceContext(context7.active(), carrier);
|
|
3177
3238
|
} catch {
|
|
3178
3239
|
}
|
|
3179
3240
|
return carrier["traceparent"] ?? "";
|
|
@@ -3234,7 +3295,7 @@ function resolveAgent(agent) {
|
|
|
3234
3295
|
sessionId = decoded.sessionId;
|
|
3235
3296
|
if (decoded.traceparent) {
|
|
3236
3297
|
try {
|
|
3237
|
-
parentContext =
|
|
3298
|
+
parentContext = extractTraceContext(parentContext, { traceparent: decoded.traceparent });
|
|
3238
3299
|
} catch {
|
|
3239
3300
|
}
|
|
3240
3301
|
}
|
|
@@ -3287,6 +3348,11 @@ function resolveMcpSessionTracking(configured) {
|
|
|
3287
3348
|
const enabled = fromEnv === "true";
|
|
3288
3349
|
return typeof configured === "object" ? { ...configured, enabled } : enabled;
|
|
3289
3350
|
}
|
|
3351
|
+
var BRIZZ_OWNED = /* @__PURE__ */ Symbol.for("brizz.sdk.ownedTracerProvider");
|
|
3352
|
+
function globalTracerDelegate() {
|
|
3353
|
+
const global = trace4.getTracerProvider();
|
|
3354
|
+
return typeof global.getDelegate === "function" ? global.getDelegate() : global;
|
|
3355
|
+
}
|
|
3290
3356
|
var _Brizz = class __Brizz {
|
|
3291
3357
|
static instance = null;
|
|
3292
3358
|
static getInstance() {
|
|
@@ -3324,8 +3390,17 @@ var _Brizz = class __Brizz {
|
|
|
3324
3390
|
const registry = InstrumentationRegistry.getInstance();
|
|
3325
3391
|
const manualInstrumentations = registry.getManualInstrumentations();
|
|
3326
3392
|
if (options.disableNodeSdk) {
|
|
3393
|
+
setPrivateTracerProvider(null);
|
|
3394
|
+
if (!resolvedConfig.setGlobalTracerProvider) {
|
|
3395
|
+
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
|
+
}
|
|
3327
3399
|
if (manualInstrumentations.length > 0) {
|
|
3328
|
-
registerInstrumentations2({
|
|
3400
|
+
registerInstrumentations2({
|
|
3401
|
+
instrumentations: manualInstrumentations,
|
|
3402
|
+
tracerProvider: brizzTracerProvider
|
|
3403
|
+
});
|
|
3329
3404
|
}
|
|
3330
3405
|
logger.info("NodeSDK disabled - only telemetry modules initialized");
|
|
3331
3406
|
return;
|
|
@@ -3343,15 +3418,34 @@ var _Brizz = class __Brizz {
|
|
|
3343
3418
|
resourceAttributes["service.version"] = resolvedConfig.appVersion;
|
|
3344
3419
|
}
|
|
3345
3420
|
const resource = defaultResource().merge(detectResources({ detectors: [envDetector, hostDetector, processDetector] })).merge(resourceFromAttributes3(resourceAttributes));
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3421
|
+
const spanProcessors = resolvedConfig.disableSpanExporter ? [] : [new InterruptPropagator(), getSpanProcessor()];
|
|
3422
|
+
if (resolvedConfig.setGlobalTracerProvider) {
|
|
3423
|
+
this._tracerProvider = new NodeTracerProvider({ resource, spanProcessors });
|
|
3424
|
+
this.registerGlobalTracerProvider(this._tracerProvider);
|
|
3425
|
+
} else {
|
|
3426
|
+
this._tracerProvider = new NodeTracerProvider({
|
|
3427
|
+
resource,
|
|
3428
|
+
spanProcessors,
|
|
3429
|
+
sampler: new AlwaysOnSampler()
|
|
3430
|
+
});
|
|
3431
|
+
if (ensureContextManager() === "failed") {
|
|
3432
|
+
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
|
+
setPrivateTracerProvider(this._tracerProvider);
|
|
3437
|
+
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);
|
|
3351
3442
|
this._meterProvider = new MeterProvider({ resource, readers: [getMetricsReader()] });
|
|
3352
3443
|
metrics.setGlobalMeterProvider(this._meterProvider);
|
|
3353
3444
|
if (manualInstrumentations.length > 0) {
|
|
3354
|
-
registerInstrumentations2({
|
|
3445
|
+
registerInstrumentations2({
|
|
3446
|
+
instrumentations: manualInstrumentations,
|
|
3447
|
+
tracerProvider: brizzTracerProvider
|
|
3448
|
+
});
|
|
3355
3449
|
logger.info(
|
|
3356
3450
|
`Telemetry providers started with ${manualInstrumentations.length} manual instrumentations`
|
|
3357
3451
|
);
|
|
@@ -3361,6 +3455,27 @@ var _Brizz = class __Brizz {
|
|
|
3361
3455
|
);
|
|
3362
3456
|
}
|
|
3363
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
|
+
setPrivateTracerProvider(null);
|
|
3466
|
+
provider.register();
|
|
3467
|
+
const registered = globalTracerDelegate();
|
|
3468
|
+
if (registered === provider) {
|
|
3469
|
+
return;
|
|
3470
|
+
}
|
|
3471
|
+
if (Reflect.get(registered, BRIZZ_OWNED) === true) {
|
|
3472
|
+
logger.debug("A TracerProvider from an earlier Brizz.initialize() is still registered");
|
|
3473
|
+
return;
|
|
3474
|
+
}
|
|
3475
|
+
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
|
+
}
|
|
3364
3479
|
/**
|
|
3365
3480
|
* Initialize telemetry modules.
|
|
3366
3481
|
*
|
|
@@ -3459,6 +3574,62 @@ var _Brizz = class __Brizz {
|
|
|
3459
3574
|
throw new Error(`Failed to initialize SDK: ${String(error)}`, { cause: error });
|
|
3460
3575
|
}
|
|
3461
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
|
+
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
|
+
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
|
+
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
|
+
}
|
|
3462
3633
|
/**
|
|
3463
3634
|
* Gracefully shutdown the Brizz SDK.
|
|
3464
3635
|
*
|
|
@@ -3527,6 +3698,7 @@ export {
|
|
|
3527
3698
|
getMetricsReader,
|
|
3528
3699
|
getSpanExporter,
|
|
3529
3700
|
getSpanProcessor,
|
|
3701
|
+
getTracerProvider,
|
|
3530
3702
|
logger,
|
|
3531
3703
|
maskAttributes,
|
|
3532
3704
|
maskValue,
|
|
@@ -8,7 +8,13 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkKGNFUQ6Zcjs = require('./chunk-KGNFUQ6Z.cjs');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunkVZJNEST4cjs = require('./chunk-VZJNEST4.cjs');
|
|
12
18
|
|
|
13
19
|
|
|
14
20
|
var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
|
|
@@ -17,11 +23,10 @@ require('./chunk-OBGZSXTJ.cjs');
|
|
|
17
23
|
|
|
18
24
|
// src/internal/instrumentation/mcp/instrumentation.ts
|
|
19
25
|
var _openinferenceinstrumentationmcp = require('@arizeai/openinference-instrumentation-mcp');
|
|
20
|
-
var _api = require('@opentelemetry/api');
|
|
21
26
|
var _instrumentation = require('@opentelemetry/instrumentation');
|
|
22
27
|
|
|
23
28
|
// src/internal/instrumentation/mcp/patches/protocol.ts
|
|
24
|
-
|
|
29
|
+
var _api = require('@opentelemetry/api');
|
|
25
30
|
|
|
26
31
|
// src/internal/instrumentation/mcp/schemas.ts
|
|
27
32
|
|
|
@@ -372,10 +377,27 @@ function wrapRequest(original, tracer) {
|
|
|
372
377
|
}
|
|
373
378
|
return executeAroundSpan(span, request.method, () => {
|
|
374
379
|
const ctx = _api.trace.setSpan(_api.context.active(), span);
|
|
375
|
-
return _api.context.with(ctx, () =>
|
|
380
|
+
return _api.context.with(ctx, () => {
|
|
381
|
+
injectMetaTraceContext(request, ctx);
|
|
382
|
+
return original.apply(this, args);
|
|
383
|
+
});
|
|
376
384
|
});
|
|
377
385
|
};
|
|
378
386
|
}
|
|
387
|
+
function injectMetaTraceContext(request, ctx) {
|
|
388
|
+
if (!_chunkVZJNEST4cjs.isPrivateTracerProvider.call(void 0, )) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
try {
|
|
392
|
+
request.params ??= {};
|
|
393
|
+
request.params._meta ??= {};
|
|
394
|
+
if (request.params._meta["traceparent"] === void 0) {
|
|
395
|
+
_chunkVZJNEST4cjs.injectTraceContext.call(void 0, ctx, request.params._meta);
|
|
396
|
+
}
|
|
397
|
+
} catch (error) {
|
|
398
|
+
_chunkWC573FCIcjs.logger.debug(`Brizz MCP: failed to inject trace context into _meta: ${String(error)}`);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
379
401
|
function wrapOnRequest(original, tracer) {
|
|
380
402
|
return function wrappedOnRequest(...args) {
|
|
381
403
|
const request = args[0];
|
|
@@ -387,14 +409,14 @@ function wrapOnRequest(original, tracer) {
|
|
|
387
409
|
return original.apply(this, args);
|
|
388
410
|
}
|
|
389
411
|
const method = request.method;
|
|
390
|
-
if (method === METHOD_TOOLS_CALL &&
|
|
412
|
+
if (method === METHOD_TOOLS_CALL && _chunkKGNFUQ6Zcjs.isSessionToolCall.call(void 0, request)) {
|
|
391
413
|
return answerSessionToolCall(this, request, tracer, args, original);
|
|
392
414
|
}
|
|
393
415
|
const handler = _nullishCoalesce(handlers.get(method), () => ( this.fallbackRequestHandler));
|
|
394
416
|
if (!handler) {
|
|
395
417
|
return original.apply(this, args);
|
|
396
418
|
}
|
|
397
|
-
const tracking =
|
|
419
|
+
const tracking = _chunkKGNFUQ6Zcjs.isEnabled.call(void 0, ) && method === METHOD_TOOLS_CALL ? _chunkKGNFUQ6Zcjs.popTrackingArguments.call(void 0, request) : {};
|
|
398
420
|
const started = safeStartServerSpan(tracer, request, this, tracking);
|
|
399
421
|
if (!started) {
|
|
400
422
|
return original.apply(this, args);
|
|
@@ -404,9 +426,9 @@ function wrapOnRequest(original, tracer) {
|
|
|
404
426
|
if (method === METHOD_TOOLS_LIST) {
|
|
405
427
|
hooks.onResult = (result) => {
|
|
406
428
|
let advertised = result;
|
|
407
|
-
if (
|
|
429
|
+
if (_chunkKGNFUQ6Zcjs.isEnabled.call(void 0, )) {
|
|
408
430
|
try {
|
|
409
|
-
advertised =
|
|
431
|
+
advertised = _chunkKGNFUQ6Zcjs.patchListToolsResult.call(void 0, result);
|
|
410
432
|
} catch (error) {
|
|
411
433
|
_chunkWC573FCIcjs.logger.warn(
|
|
412
434
|
`Brizz MCP: failed to patch tools/list schemas: ${String(error)}`
|
|
@@ -417,7 +439,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
417
439
|
try {
|
|
418
440
|
emitSchemaSpansFromListResponse(
|
|
419
441
|
advertised,
|
|
420
|
-
|
|
442
|
+
_chunkKGNFUQ6Zcjs.resolveTransportSessionId.call(void 0, this),
|
|
421
443
|
tracer
|
|
422
444
|
);
|
|
423
445
|
} catch (error) {
|
|
@@ -430,7 +452,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
430
452
|
}
|
|
431
453
|
if (method !== METHOD_TOOLS_CALL) {
|
|
432
454
|
hooks.onError = () => {
|
|
433
|
-
|
|
455
|
+
_chunkKGNFUQ6Zcjs.stampAndPropagateSession.call(void 0, span, _chunkKGNFUQ6Zcjs.resolveSessionId.call(void 0, this, spanCtx), spanCtx);
|
|
434
456
|
};
|
|
435
457
|
}
|
|
436
458
|
const wrappedHandler = (req, extra) => _api.context.with(
|
|
@@ -464,7 +486,7 @@ function answerSessionToolCall(protocol, request, tracer, args, original) {
|
|
|
464
486
|
if (!handlers) {
|
|
465
487
|
return original.apply(protocol, args);
|
|
466
488
|
}
|
|
467
|
-
const { id, result } =
|
|
489
|
+
const { id, result } = _chunkKGNFUQ6Zcjs.sessionToolResult.call(void 0, );
|
|
468
490
|
const started = safeStartServerSpan(tracer, request, protocol, { sessionId: id });
|
|
469
491
|
const handler = () => started ? _api.context.with(started.spanCtx, () => result) : result;
|
|
470
492
|
const hadEntry = handlers.has(METHOD_TOOLS_CALL);
|
|
@@ -554,8 +576,8 @@ function safeStartServerSpan(tracer, request, protocol, tracking = {}) {
|
|
|
554
576
|
parentCtx
|
|
555
577
|
);
|
|
556
578
|
applyServerRequestAttributes(span, request, protocol);
|
|
557
|
-
const resolved = request.method === METHOD_TOOLS_CALL ? _nullishCoalesce(tracking.sessionId, () => (
|
|
558
|
-
const { context: sessCtx } =
|
|
579
|
+
const resolved = request.method === METHOD_TOOLS_CALL ? _nullishCoalesce(tracking.sessionId, () => ( _chunkKGNFUQ6Zcjs.resolveSessionId.call(void 0, protocol, parentCtx))) : void 0;
|
|
580
|
+
const { context: sessCtx } = _chunkKGNFUQ6Zcjs.stampAndPropagateSession.call(void 0,
|
|
559
581
|
span,
|
|
560
582
|
resolved,
|
|
561
583
|
parentCtx,
|
|
@@ -571,7 +593,7 @@ function extractParentContext(request) {
|
|
|
571
593
|
try {
|
|
572
594
|
const meta = _optionalChain([request, 'access', _24 => _24.params, 'optionalAccess', _25 => _25._meta]);
|
|
573
595
|
if (meta && typeof meta === "object") {
|
|
574
|
-
return
|
|
596
|
+
return _chunkVZJNEST4cjs.extractTraceContext.call(void 0, _api.context.active(), meta);
|
|
575
597
|
}
|
|
576
598
|
} catch (error) {
|
|
577
599
|
_chunkWC573FCIcjs.logger.debug(
|
|
@@ -611,7 +633,7 @@ function safeEnd(span) {
|
|
|
611
633
|
|
|
612
634
|
// src/internal/instrumentation/mcp/version.ts
|
|
613
635
|
var INSTRUMENTATION_NAME = "@brizz/sdk/mcp";
|
|
614
|
-
var INSTRUMENTATION_VERSION =
|
|
636
|
+
var INSTRUMENTATION_VERSION = _chunkKGNFUQ6Zcjs.getSDKVersion.call(void 0, );
|
|
615
637
|
|
|
616
638
|
// src/internal/instrumentation/mcp/instrumentation.ts
|
|
617
639
|
var PROTOCOL_MODULE_NAME = "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
@@ -630,7 +652,8 @@ var MCPInstrumentation = class extends _openinferenceinstrumentationmcp.MCPInstr
|
|
|
630
652
|
|
|
631
653
|
constructor(_config) {
|
|
632
654
|
super({ instrumentationConfig: _optionalChain([_config, 'optionalAccess', _26 => _26.instrumentationConfig]) });
|
|
633
|
-
this.
|
|
655
|
+
this.setTracerProvider(_chunkVZJNEST4cjs.brizzTracerProvider);
|
|
656
|
+
this.brizzTracer = _chunkVZJNEST4cjs.brizzTracerProvider.getTracer(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION);
|
|
634
657
|
}
|
|
635
658
|
/**
|
|
636
659
|
* Apply the SERVER + CLIENT patch to a loaded `protocol.js` module. Shared
|