@brizz/sdk 0.1.43 → 0.1.45
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 +44 -0
- package/dist/{chunk-QUV5HYJ2.cjs → chunk-3IGBYXLR.cjs} +4 -4
- package/dist/{chunk-FORVS4QW.cjs → chunk-5WBPX342.cjs} +7 -1
- package/dist/{chunk-Y7NMZAQT.js → chunk-AOT5NJDV.js} +6 -0
- package/dist/{chunk-7FQQHF5U.js → chunk-APOYOP7D.js} +1 -1
- package/dist/{chunk-5SWAZUC5.js → chunk-BAQTZKGI.js} +2 -2
- package/dist/{chunk-WTQTF57J.cjs → chunk-CBEDIRVK.cjs} +8 -8
- package/dist/index.cjs +395 -171
- package/dist/index.js +252 -28
- package/dist/{interrupt-ERCX5RXR.js → interrupt-A6O7N72X.js} +2 -2
- package/dist/interrupt-IKOUBQGN.cjs +12 -0
- package/dist/{mcp-UJD6KF7G.cjs → mcp-CCFYA5CI.cjs} +12 -12
- package/dist/{mcp-6R6KZ5U3.js → mcp-FTYCIWL4.js} +2 -2
- package/dist/types/cjs/index.d.ts +2 -2
- package/dist/types/cjs/internal/instrumentation/langchain.d.ts +4 -0
- package/dist/types/cjs/internal/semantic-conventions.d.ts +3 -0
- package/dist/types/cjs/internal/trace/agent.d.ts +18 -0
- package/dist/types/cjs/internal/trace/index.d.ts +2 -0
- package/dist/types/cjs/internal/trace/session.d.ts +2 -1
- package/dist/types/esm/index.d.ts +2 -2
- package/dist/types/esm/internal/instrumentation/langchain.d.ts +4 -0
- package/dist/types/esm/internal/semantic-conventions.d.ts +3 -0
- package/dist/types/esm/internal/trace/agent.d.ts +18 -0
- package/dist/types/esm/internal/trace/index.d.ts +2 -0
- package/dist/types/esm/internal/trace/session.d.ts +2 -1
- package/package.json +33 -31
- package/dist/interrupt-3NXOTY4N.cjs +0 -12
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
configure,
|
|
7
7
|
getSDKVersion
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-BAQTZKGI.js";
|
|
9
9
|
import {
|
|
10
10
|
DEFAULT_LOG_LEVEL,
|
|
11
11
|
LogLevel,
|
|
@@ -16,8 +16,11 @@ import {
|
|
|
16
16
|
} from "./chunk-Y4HNUX3Q.js";
|
|
17
17
|
import {
|
|
18
18
|
InterruptPropagator
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-APOYOP7D.js";
|
|
20
20
|
import {
|
|
21
|
+
AGENT_ID,
|
|
22
|
+
AGENT_NAME,
|
|
23
|
+
AGENT_PARENT_ID,
|
|
21
24
|
BRIZZ,
|
|
22
25
|
EXTERNAL_LINK_EVENT_NAME,
|
|
23
26
|
EXTERNAL_LINK_TITLE,
|
|
@@ -70,7 +73,7 @@ import {
|
|
|
70
73
|
USER_NAME,
|
|
71
74
|
USER_PLAN,
|
|
72
75
|
USER_ROLE
|
|
73
|
-
} from "./chunk-
|
|
76
|
+
} from "./chunk-AOT5NJDV.js";
|
|
74
77
|
import {
|
|
75
78
|
__require
|
|
76
79
|
} from "./chunk-3RG5ZIWI.js";
|
|
@@ -127,7 +130,7 @@ function loadGenAIInstrumentations() {
|
|
|
127
130
|
function loadMCPInstrumentation() {
|
|
128
131
|
void (async () => {
|
|
129
132
|
try {
|
|
130
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
133
|
+
const { MCPInstrumentation } = await import("./mcp-FTYCIWL4.js");
|
|
131
134
|
const mcp = new MCPInstrumentation({ exceptionLogger });
|
|
132
135
|
registerInstrumentations({ instrumentations: [mcp] });
|
|
133
136
|
logger.debug("Auto-loaded MCP instrumentation");
|
|
@@ -183,7 +186,7 @@ function loadVercelAITelemetry() {
|
|
|
183
186
|
}
|
|
184
187
|
const isV7 = typeof ai.registerTelemetry === "function";
|
|
185
188
|
const integrations = [];
|
|
186
|
-
const { createInterruptIntegration } = await import("./interrupt-
|
|
189
|
+
const { createInterruptIntegration } = await import("./interrupt-A6O7N72X.js");
|
|
187
190
|
integrations.push(createInterruptIntegration());
|
|
188
191
|
let otelCollectorLoaded = false;
|
|
189
192
|
try {
|
|
@@ -391,6 +394,94 @@ import { LlamaIndexInstrumentation as LlamaIndexInstrumentation2 } from "@tracel
|
|
|
391
394
|
import { PineconeInstrumentation as PineconeInstrumentation2 } from "@traceloop/instrumentation-pinecone";
|
|
392
395
|
import { QdrantInstrumentation as QdrantInstrumentation2 } from "@traceloop/instrumentation-qdrant";
|
|
393
396
|
import { TogetherInstrumentation as TogetherInstrumentation2 } from "@traceloop/instrumentation-together";
|
|
397
|
+
|
|
398
|
+
// src/internal/instrumentation/langchain.ts
|
|
399
|
+
import { context } from "@opentelemetry/api";
|
|
400
|
+
var SCOPE_NAME = "@arizeai/openinference-instrumentation-langchain";
|
|
401
|
+
var PATCHED_MARKER = /* @__PURE__ */ Symbol.for("brizz.langchain.callbackManagerPatched");
|
|
402
|
+
var OMITTED_KEYS = /* @__PURE__ */ new Set([
|
|
403
|
+
USER_EMAIL,
|
|
404
|
+
USER_NAME,
|
|
405
|
+
ORGANIZATION_NAME,
|
|
406
|
+
ORGANIZATION_DOMAIN
|
|
407
|
+
]);
|
|
408
|
+
function runMetadataFromContext() {
|
|
409
|
+
const bag = context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
410
|
+
if (!bag) {
|
|
411
|
+
return void 0;
|
|
412
|
+
}
|
|
413
|
+
const metadata = {};
|
|
414
|
+
for (const [name, value] of Object.entries(bag)) {
|
|
415
|
+
if (!OMITTED_KEYS.has(name)) {
|
|
416
|
+
metadata[`${BRIZZ}.${name}`] = String(value);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return Object.keys(metadata).length > 0 ? metadata : void 0;
|
|
420
|
+
}
|
|
421
|
+
function patchCallbackManagerModule(module2) {
|
|
422
|
+
const callbackManager = module2?.CallbackManager;
|
|
423
|
+
if (callbackManager === null || typeof callbackManager !== "function" && typeof callbackManager !== "object") {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
const statics = callbackManager;
|
|
427
|
+
if (statics[PATCHED_MARKER] === true) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
const key = "_configureSync" in statics ? "_configureSync" : "configure";
|
|
431
|
+
const original = statics[key];
|
|
432
|
+
if (typeof original !== "function") {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
const configure2 = original;
|
|
436
|
+
statics[key] = function(...args) {
|
|
437
|
+
const manager = configure2.apply(this, args);
|
|
438
|
+
try {
|
|
439
|
+
const metadata = runMetadataFromContext();
|
|
440
|
+
if (manager && metadata) {
|
|
441
|
+
manager.addMetadata(metadata);
|
|
442
|
+
}
|
|
443
|
+
} catch {
|
|
444
|
+
}
|
|
445
|
+
return manager;
|
|
446
|
+
};
|
|
447
|
+
statics[PATCHED_MARKER] = true;
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
function patchInstalledCallbackManager() {
|
|
451
|
+
void (async () => {
|
|
452
|
+
try {
|
|
453
|
+
patchCallbackManagerModule(await import("@langchain/core/callbacks/manager"));
|
|
454
|
+
} catch (error) {
|
|
455
|
+
logger.debug(`LangChain callback manager not patched: ${String(error)}`);
|
|
456
|
+
}
|
|
457
|
+
})();
|
|
458
|
+
}
|
|
459
|
+
function restampLangChainSpan(span) {
|
|
460
|
+
try {
|
|
461
|
+
const scope = span.instrumentationScope;
|
|
462
|
+
if (scope?.name !== SCOPE_NAME) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const attrs = span.attributes;
|
|
466
|
+
const metadata = attrs["metadata"];
|
|
467
|
+
if (typeof metadata !== "string" || !metadata.includes(`"${BRIZZ}.`)) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
const parsed = JSON.parse(metadata);
|
|
471
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
475
|
+
if (key.startsWith(`${BRIZZ}.`) && value !== null && value !== void 0) {
|
|
476
|
+
attrs[key] = String(value);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
} catch (error) {
|
|
480
|
+
logger.debug("Skipped LangChain span re-stamp", { err: error });
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// src/internal/instrumentation/registry.ts
|
|
394
485
|
var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
395
486
|
static instance;
|
|
396
487
|
static getInstance() {
|
|
@@ -468,6 +559,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
468
559
|
const { LangChainInstrumentation } = await import("@arizeai/openinference-instrumentation-langchain");
|
|
469
560
|
const lcInst = new LangChainInstrumentation();
|
|
470
561
|
lcInst.manuallyInstrument(callbackManagerModule);
|
|
562
|
+
patchCallbackManagerModule(callbackManagerModule);
|
|
471
563
|
logger.debug("Manual instrumentation enabled for LangChain");
|
|
472
564
|
} catch (error) {
|
|
473
565
|
logger.error(
|
|
@@ -510,7 +602,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
510
602
|
const mcpModules = this.manualModules.mcp;
|
|
511
603
|
void (async () => {
|
|
512
604
|
try {
|
|
513
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
605
|
+
const { MCPInstrumentation } = await import("./mcp-FTYCIWL4.js");
|
|
514
606
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
515
607
|
instrumentation.manuallyInstrument(mcpModules);
|
|
516
608
|
logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -553,7 +645,7 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
|
553
645
|
import { LoggerProvider } from "@opentelemetry/sdk-logs";
|
|
554
646
|
|
|
555
647
|
// src/internal/trace/session.ts
|
|
556
|
-
import { context, trace, SpanStatusCode } from "@opentelemetry/api";
|
|
648
|
+
import { context as context2, trace, SpanStatusCode } from "@opentelemetry/api";
|
|
557
649
|
function setCurrentSpanCustomProperties(properties) {
|
|
558
650
|
const current = trace.getActiveSpan();
|
|
559
651
|
if (!current || !current.isRecording()) {
|
|
@@ -567,11 +659,11 @@ function setCurrentSpanCustomProperties(properties) {
|
|
|
567
659
|
}
|
|
568
660
|
}
|
|
569
661
|
function callWithProperties(properties, fn, thisArg, ...args) {
|
|
570
|
-
const base =
|
|
662
|
+
const base = context2.active();
|
|
571
663
|
const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
|
|
572
664
|
const merged = prev ? { ...prev, ...properties } : properties;
|
|
573
665
|
const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
|
|
574
|
-
return
|
|
666
|
+
return context2.with(next, fn, thisArg, ...args);
|
|
575
667
|
}
|
|
576
668
|
function withProperties(properties, fn, thisArg) {
|
|
577
669
|
return function wrapped(...args) {
|
|
@@ -583,15 +675,14 @@ function withProperties(properties, fn, thisArg) {
|
|
|
583
675
|
);
|
|
584
676
|
};
|
|
585
677
|
}
|
|
586
|
-
function propagatePropertiesImperatively(properties) {
|
|
678
|
+
function propagatePropertiesImperatively(properties, base = context2.active()) {
|
|
587
679
|
try {
|
|
588
|
-
const manager =
|
|
680
|
+
const manager = context2;
|
|
589
681
|
const mgr = manager._getContextManager?.();
|
|
590
682
|
const store = mgr?._asyncLocalStorage;
|
|
591
683
|
if (!store || typeof store.enterWith !== "function") {
|
|
592
684
|
return;
|
|
593
685
|
}
|
|
594
|
-
const base = context.active();
|
|
595
686
|
const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
|
|
596
687
|
const merged = prev ? { ...prev, ...properties } : properties;
|
|
597
688
|
store.enterWith(base.setValue(PROPERTIES_CONTEXT_KEY, merged));
|
|
@@ -688,7 +779,7 @@ function withServiceName(name, fn, thisArg) {
|
|
|
688
779
|
return withProperties(serviceNameProperties(name), fn, thisArg);
|
|
689
780
|
}
|
|
690
781
|
function resolveServiceNameFromContext() {
|
|
691
|
-
const props =
|
|
782
|
+
const props = context2.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
692
783
|
return props?.[SERVICE_NAME];
|
|
693
784
|
}
|
|
694
785
|
function userProperties(user) {
|
|
@@ -755,7 +846,7 @@ function withMessageId(id, fn, thisArg) {
|
|
|
755
846
|
return withProperties({ [MESSAGE_ID]: id }, fn, thisArg);
|
|
756
847
|
}
|
|
757
848
|
function inheritedMuteTools() {
|
|
758
|
-
const properties =
|
|
849
|
+
const properties = context2.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
759
850
|
return properties?.[MUTE_TOOLS];
|
|
760
851
|
}
|
|
761
852
|
function muteProperties(options) {
|
|
@@ -815,9 +906,9 @@ var Session = class {
|
|
|
815
906
|
* @param text - Text to append (null becomes a null/"hide marker")
|
|
816
907
|
* @param context - Optional per-turn context bag to attach to this turn
|
|
817
908
|
*/
|
|
818
|
-
setInput(text,
|
|
909
|
+
setInput(text, context6) {
|
|
819
910
|
this.inputs.push(text);
|
|
820
|
-
this.inputContexts.push(
|
|
911
|
+
this.inputContexts.push(context6 ?? {});
|
|
821
912
|
this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
|
|
822
913
|
this.span.setAttribute(SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
|
|
823
914
|
}
|
|
@@ -831,9 +922,9 @@ var Session = class {
|
|
|
831
922
|
* @param text - Text to append (null becomes a null/"hide marker")
|
|
832
923
|
* @param context - Optional per-turn context bag to attach to this turn
|
|
833
924
|
*/
|
|
834
|
-
setOutput(text,
|
|
925
|
+
setOutput(text, context6) {
|
|
835
926
|
this.outputs.push(text);
|
|
836
|
-
this.outputContexts.push(
|
|
927
|
+
this.outputContexts.push(context6 ?? {});
|
|
837
928
|
this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
|
|
838
929
|
this.span.setAttribute(SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
|
|
839
930
|
}
|
|
@@ -936,18 +1027,18 @@ var SessionTitle = class {
|
|
|
936
1027
|
}
|
|
937
1028
|
};
|
|
938
1029
|
function getActiveSession() {
|
|
939
|
-
return
|
|
1030
|
+
return context2.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
|
|
940
1031
|
}
|
|
941
1032
|
function resolveSessionIdFromContext() {
|
|
942
1033
|
const active = getActiveSession();
|
|
943
1034
|
if (active) {
|
|
944
1035
|
return active.sessionId;
|
|
945
1036
|
}
|
|
946
|
-
const props =
|
|
1037
|
+
const props = context2.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
947
1038
|
return props?.[SESSION_ID];
|
|
948
1039
|
}
|
|
949
1040
|
function resolveMessageIdFromContext() {
|
|
950
|
-
const props =
|
|
1041
|
+
const props = context2.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
951
1042
|
return props?.[MESSAGE_ID];
|
|
952
1043
|
}
|
|
953
1044
|
function emitExternalLink(sessionId, url, title, linkType) {
|
|
@@ -1161,8 +1252,8 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1161
1252
|
}
|
|
1162
1253
|
}
|
|
1163
1254
|
return callWithProperties(contextProperties, () => {
|
|
1164
|
-
const sessionCtx =
|
|
1165
|
-
return
|
|
1255
|
+
const sessionCtx = context2.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
|
|
1256
|
+
return context2.with(sessionCtx, () => {
|
|
1166
1257
|
try {
|
|
1167
1258
|
const result = callback(session);
|
|
1168
1259
|
if (result && typeof result.then === "function") {
|
|
@@ -1227,7 +1318,7 @@ function startSessionTitle(callback, options) {
|
|
|
1227
1318
|
}
|
|
1228
1319
|
|
|
1229
1320
|
// src/internal/log/processors/log-processor.ts
|
|
1230
|
-
import { context as
|
|
1321
|
+
import { context as context3 } from "@opentelemetry/api";
|
|
1231
1322
|
import { BatchLogRecordProcessor, SimpleLogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
1232
1323
|
|
|
1233
1324
|
// src/internal/masking/patterns.ts
|
|
@@ -1665,7 +1756,7 @@ var BrizzSimpleLogRecordProcessor = class extends SimpleLogRecordProcessor {
|
|
|
1665
1756
|
if (maskingConfig) {
|
|
1666
1757
|
maskLog(logRecord, maskingConfig);
|
|
1667
1758
|
}
|
|
1668
|
-
const associationProperties =
|
|
1759
|
+
const associationProperties = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1669
1760
|
if (associationProperties) {
|
|
1670
1761
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1671
1762
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -1685,7 +1776,7 @@ var BrizzBatchLogRecordProcessor = class extends BatchLogRecordProcessor {
|
|
|
1685
1776
|
if (maskingConfig) {
|
|
1686
1777
|
maskLog(logRecord, maskingConfig);
|
|
1687
1778
|
}
|
|
1688
|
-
const associationProperties =
|
|
1779
|
+
const associationProperties = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1689
1780
|
if (associationProperties) {
|
|
1690
1781
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1691
1782
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2163,13 +2254,13 @@ var BrizzSpanExporter = class {
|
|
|
2163
2254
|
};
|
|
2164
2255
|
|
|
2165
2256
|
// src/internal/trace/processors/span-processor.ts
|
|
2166
|
-
import { context as
|
|
2257
|
+
import { context as context4 } from "@opentelemetry/api";
|
|
2167
2258
|
import {
|
|
2168
2259
|
BatchSpanProcessor,
|
|
2169
2260
|
SimpleSpanProcessor
|
|
2170
2261
|
} from "@opentelemetry/sdk-trace-base";
|
|
2171
2262
|
function applyContextAttributes(span) {
|
|
2172
|
-
const sessionProperties =
|
|
2263
|
+
const sessionProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
2173
2264
|
if (sessionProperties) {
|
|
2174
2265
|
for (const [key, value] of Object.entries(sessionProperties)) {
|
|
2175
2266
|
span.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2193,6 +2284,7 @@ var BrizzSimpleSpanProcessor = class extends SimpleSpanProcessor {
|
|
|
2193
2284
|
super.onStart(span, parentContext);
|
|
2194
2285
|
}
|
|
2195
2286
|
onEnd(span) {
|
|
2287
|
+
restampLangChainSpan(span);
|
|
2196
2288
|
const maskingConfig = this.config.masking?.spanMasking;
|
|
2197
2289
|
if (maskingConfig) {
|
|
2198
2290
|
maskReadableSpan(span, maskingConfig);
|
|
@@ -2211,6 +2303,7 @@ var BrizzBatchSpanProcessor = class extends BatchSpanProcessor {
|
|
|
2211
2303
|
super.onStart(span, parentContext);
|
|
2212
2304
|
}
|
|
2213
2305
|
onEnd(span) {
|
|
2306
|
+
restampLangChainSpan(span);
|
|
2214
2307
|
const maskingConfig = this.config.masking?.spanMasking;
|
|
2215
2308
|
if (maskingConfig) {
|
|
2216
2309
|
maskReadableSpan(span, maskingConfig);
|
|
@@ -2362,6 +2455,133 @@ function getSpanProcessor() {
|
|
|
2362
2455
|
return TracingModule.getInstance().getSpanProcessor();
|
|
2363
2456
|
}
|
|
2364
2457
|
|
|
2458
|
+
// src/internal/trace/agent.ts
|
|
2459
|
+
import { randomUUID } from "crypto";
|
|
2460
|
+
import { context as context5, propagation } from "@opentelemetry/api";
|
|
2461
|
+
function newInstanceId() {
|
|
2462
|
+
return randomUUID().replaceAll("-", "").slice(0, 8);
|
|
2463
|
+
}
|
|
2464
|
+
function activeProperties() {
|
|
2465
|
+
return context5.active().getValue(PROPERTIES_CONTEXT_KEY) ?? {};
|
|
2466
|
+
}
|
|
2467
|
+
function encodeToken(agent) {
|
|
2468
|
+
const payload = {
|
|
2469
|
+
id: agent.id,
|
|
2470
|
+
parentId: agent.parentId,
|
|
2471
|
+
name: agent.name,
|
|
2472
|
+
traceparent: agent.traceparent,
|
|
2473
|
+
sessionId: agent.sessionId
|
|
2474
|
+
};
|
|
2475
|
+
return Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
|
|
2476
|
+
}
|
|
2477
|
+
function currentTraceparent() {
|
|
2478
|
+
const carrier = {};
|
|
2479
|
+
try {
|
|
2480
|
+
propagation.inject(context5.active(), carrier);
|
|
2481
|
+
} catch {
|
|
2482
|
+
}
|
|
2483
|
+
return carrier["traceparent"] ?? "";
|
|
2484
|
+
}
|
|
2485
|
+
function agentHandle(id, parentId, name) {
|
|
2486
|
+
const opened = {
|
|
2487
|
+
id,
|
|
2488
|
+
parentId,
|
|
2489
|
+
name,
|
|
2490
|
+
traceparent: currentTraceparent(),
|
|
2491
|
+
sessionId: activeProperties()[SESSION_ID] ?? ""
|
|
2492
|
+
};
|
|
2493
|
+
return {
|
|
2494
|
+
...opened,
|
|
2495
|
+
get token() {
|
|
2496
|
+
return encodeToken(opened);
|
|
2497
|
+
}
|
|
2498
|
+
};
|
|
2499
|
+
}
|
|
2500
|
+
function decodeToken(token) {
|
|
2501
|
+
try {
|
|
2502
|
+
const payload = JSON.parse(Buffer.from(token, "base64url").toString("utf8"));
|
|
2503
|
+
return payload.id ? payload : void 0;
|
|
2504
|
+
} catch {
|
|
2505
|
+
return void 0;
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
function unreadableAgent(agent) {
|
|
2509
|
+
return {
|
|
2510
|
+
id: "",
|
|
2511
|
+
parentId: "",
|
|
2512
|
+
name: "",
|
|
2513
|
+
traceparent: "",
|
|
2514
|
+
sessionId: "",
|
|
2515
|
+
token: typeof agent === "string" ? "" : agent.token ?? ""
|
|
2516
|
+
};
|
|
2517
|
+
}
|
|
2518
|
+
function resolveAgent(agent) {
|
|
2519
|
+
const options = typeof agent === "string" ? { name: agent } : agent;
|
|
2520
|
+
let id;
|
|
2521
|
+
let parentId;
|
|
2522
|
+
let name;
|
|
2523
|
+
let sessionId = "";
|
|
2524
|
+
let parentContext = context5.active();
|
|
2525
|
+
if (options.token === void 0) {
|
|
2526
|
+
id = options.id || newInstanceId();
|
|
2527
|
+
parentId = options.parentId || activeProperties()[AGENT_ID] || "";
|
|
2528
|
+
name = options.name ?? "";
|
|
2529
|
+
} else {
|
|
2530
|
+
const decoded = decodeToken(options.token);
|
|
2531
|
+
if (!decoded) {
|
|
2532
|
+
logger.warn("Brizz: ignoring an unreadable agent token");
|
|
2533
|
+
return void 0;
|
|
2534
|
+
}
|
|
2535
|
+
id = decoded.id;
|
|
2536
|
+
parentId = decoded.parentId;
|
|
2537
|
+
name = decoded.name;
|
|
2538
|
+
sessionId = decoded.sessionId;
|
|
2539
|
+
if (decoded.traceparent) {
|
|
2540
|
+
try {
|
|
2541
|
+
parentContext = propagation.extract(parentContext, { traceparent: decoded.traceparent });
|
|
2542
|
+
} catch {
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
const properties = { [AGENT_ID]: id, [AGENT_NAME]: name };
|
|
2547
|
+
if (parentId) {
|
|
2548
|
+
properties[AGENT_PARENT_ID] = parentId;
|
|
2549
|
+
}
|
|
2550
|
+
if (sessionId) {
|
|
2551
|
+
properties[SESSION_ID] = sessionId;
|
|
2552
|
+
}
|
|
2553
|
+
return { id, parentId, name, properties, parentContext };
|
|
2554
|
+
}
|
|
2555
|
+
function startAgent(agent, callback) {
|
|
2556
|
+
const resolved = resolveAgent(agent);
|
|
2557
|
+
if (!resolved) {
|
|
2558
|
+
return callback(unreadableAgent(agent));
|
|
2559
|
+
}
|
|
2560
|
+
const { id, parentId, name, properties, parentContext } = resolved;
|
|
2561
|
+
return context5.with(
|
|
2562
|
+
parentContext,
|
|
2563
|
+
() => callWithProperties(properties, () => callback(agentHandle(id, parentId, name)))
|
|
2564
|
+
);
|
|
2565
|
+
}
|
|
2566
|
+
function withAgent(agent, fn, thisArg) {
|
|
2567
|
+
return function wrapped(...args) {
|
|
2568
|
+
return startAgent(
|
|
2569
|
+
agent,
|
|
2570
|
+
() => fn.apply(thisArg !== void 0 ? thisArg : this, args)
|
|
2571
|
+
);
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
function setAgent(agent) {
|
|
2575
|
+
const resolved = resolveAgent(agent);
|
|
2576
|
+
if (!resolved) {
|
|
2577
|
+
return unreadableAgent(agent);
|
|
2578
|
+
}
|
|
2579
|
+
const { id, parentId, name, properties, parentContext } = resolved;
|
|
2580
|
+
setCurrentSpanCustomProperties(properties);
|
|
2581
|
+
propagatePropertiesImperatively(properties, parentContext);
|
|
2582
|
+
return agentHandle(id, parentId, name);
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2365
2585
|
// src/internal/sdk.ts
|
|
2366
2586
|
function resolveMcpSessionTracking(configured) {
|
|
2367
2587
|
const fromEnv = process.env["BRIZZ_MCP_SESSION_TRACKING"];
|
|
@@ -2392,6 +2612,7 @@ var _Brizz = class __Brizz {
|
|
|
2392
2612
|
setupInstrumentation(options) {
|
|
2393
2613
|
const registry = InstrumentationRegistry.getInstance();
|
|
2394
2614
|
configure(resolveMcpSessionTracking(options.mcpSessionTracking));
|
|
2615
|
+
patchInstalledCallbackManager();
|
|
2395
2616
|
if (options.instrumentModules && Object.keys(options.instrumentModules).length > 0) {
|
|
2396
2617
|
registry.setManualModules(options.instrumentModules);
|
|
2397
2618
|
}
|
|
@@ -2613,6 +2834,7 @@ export {
|
|
|
2613
2834
|
maskValue,
|
|
2614
2835
|
recordFeedback,
|
|
2615
2836
|
recordMetric,
|
|
2837
|
+
setAgent,
|
|
2616
2838
|
setCurrentSpanCustomProperties,
|
|
2617
2839
|
setLogLevel,
|
|
2618
2840
|
setMessageId,
|
|
@@ -2620,8 +2842,10 @@ export {
|
|
|
2620
2842
|
setServiceName,
|
|
2621
2843
|
setSessionId,
|
|
2622
2844
|
setUser,
|
|
2845
|
+
startAgent,
|
|
2623
2846
|
startSession,
|
|
2624
2847
|
startSessionTitle,
|
|
2848
|
+
withAgent,
|
|
2625
2849
|
withMessageId,
|
|
2626
2850
|
withMute,
|
|
2627
2851
|
withOrganization,
|
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
InterruptPropagator,
|
|
3
3
|
_resetInterruptState,
|
|
4
4
|
createInterruptIntegration
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-APOYOP7D.js";
|
|
6
|
+
import "./chunk-AOT5NJDV.js";
|
|
7
7
|
import "./chunk-3RG5ZIWI.js";
|
|
8
8
|
export {
|
|
9
9
|
InterruptPropagator,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunk3IGBYXLRcjs = require('./chunk-3IGBYXLR.cjs');
|
|
6
|
+
require('./chunk-5WBPX342.cjs');
|
|
7
|
+
require('./chunk-OBGZSXTJ.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.InterruptPropagator = _chunk3IGBYXLRcjs.InterruptPropagator; exports._resetInterruptState = _chunk3IGBYXLRcjs._resetInterruptState; exports.createInterruptIntegration = _chunk3IGBYXLRcjs.createInterruptIntegration;
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkCBEDIRVKcjs = require('./chunk-CBEDIRVK.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
|
|
15
|
-
require('./chunk-
|
|
15
|
+
require('./chunk-5WBPX342.cjs');
|
|
16
16
|
require('./chunk-OBGZSXTJ.cjs');
|
|
17
17
|
|
|
18
18
|
// src/internal/instrumentation/mcp/instrumentation.ts
|
|
@@ -387,14 +387,14 @@ function wrapOnRequest(original, tracer) {
|
|
|
387
387
|
return original.apply(this, args);
|
|
388
388
|
}
|
|
389
389
|
const method = request.method;
|
|
390
|
-
if (method === METHOD_TOOLS_CALL &&
|
|
390
|
+
if (method === METHOD_TOOLS_CALL && _chunkCBEDIRVKcjs.isSessionToolCall.call(void 0, request)) {
|
|
391
391
|
return answerSessionToolCall(this, request, tracer, args, original);
|
|
392
392
|
}
|
|
393
393
|
const handler = _nullishCoalesce(handlers.get(method), () => ( this.fallbackRequestHandler));
|
|
394
394
|
if (!handler) {
|
|
395
395
|
return original.apply(this, args);
|
|
396
396
|
}
|
|
397
|
-
const tracking =
|
|
397
|
+
const tracking = _chunkCBEDIRVKcjs.isEnabled.call(void 0, ) && method === METHOD_TOOLS_CALL ? _chunkCBEDIRVKcjs.popTrackingArguments.call(void 0, request) : {};
|
|
398
398
|
const started = safeStartServerSpan(tracer, request, this, tracking);
|
|
399
399
|
if (!started) {
|
|
400
400
|
return original.apply(this, args);
|
|
@@ -404,9 +404,9 @@ function wrapOnRequest(original, tracer) {
|
|
|
404
404
|
if (method === METHOD_TOOLS_LIST) {
|
|
405
405
|
hooks.onResult = (result) => {
|
|
406
406
|
let advertised = result;
|
|
407
|
-
if (
|
|
407
|
+
if (_chunkCBEDIRVKcjs.isEnabled.call(void 0, )) {
|
|
408
408
|
try {
|
|
409
|
-
advertised =
|
|
409
|
+
advertised = _chunkCBEDIRVKcjs.patchListToolsResult.call(void 0, result);
|
|
410
410
|
} catch (error) {
|
|
411
411
|
_chunkWC573FCIcjs.logger.warn(
|
|
412
412
|
`Brizz MCP: failed to patch tools/list schemas: ${String(error)}`
|
|
@@ -417,7 +417,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
417
417
|
try {
|
|
418
418
|
emitSchemaSpansFromListResponse(
|
|
419
419
|
advertised,
|
|
420
|
-
|
|
420
|
+
_chunkCBEDIRVKcjs.resolveTransportSessionId.call(void 0, this),
|
|
421
421
|
tracer
|
|
422
422
|
);
|
|
423
423
|
} catch (error) {
|
|
@@ -430,7 +430,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
430
430
|
}
|
|
431
431
|
if (method !== METHOD_TOOLS_CALL) {
|
|
432
432
|
hooks.onError = () => {
|
|
433
|
-
|
|
433
|
+
_chunkCBEDIRVKcjs.stampAndPropagateSession.call(void 0, span, _chunkCBEDIRVKcjs.resolveSessionId.call(void 0, this, spanCtx), spanCtx);
|
|
434
434
|
};
|
|
435
435
|
}
|
|
436
436
|
const wrappedHandler = (req, extra) => _api.context.with(
|
|
@@ -464,7 +464,7 @@ function answerSessionToolCall(protocol, request, tracer, args, original) {
|
|
|
464
464
|
if (!handlers) {
|
|
465
465
|
return original.apply(protocol, args);
|
|
466
466
|
}
|
|
467
|
-
const { id, result } =
|
|
467
|
+
const { id, result } = _chunkCBEDIRVKcjs.sessionToolResult.call(void 0, );
|
|
468
468
|
const started = safeStartServerSpan(tracer, request, protocol, { sessionId: id });
|
|
469
469
|
const handler = () => started ? _api.context.with(started.spanCtx, () => result) : result;
|
|
470
470
|
const hadEntry = handlers.has(METHOD_TOOLS_CALL);
|
|
@@ -554,8 +554,8 @@ function safeStartServerSpan(tracer, request, protocol, tracking = {}) {
|
|
|
554
554
|
parentCtx
|
|
555
555
|
);
|
|
556
556
|
applyServerRequestAttributes(span, request, protocol);
|
|
557
|
-
const resolved = request.method === METHOD_TOOLS_CALL ? _nullishCoalesce(tracking.sessionId, () => (
|
|
558
|
-
const { context: sessCtx } =
|
|
557
|
+
const resolved = request.method === METHOD_TOOLS_CALL ? _nullishCoalesce(tracking.sessionId, () => ( _chunkCBEDIRVKcjs.resolveSessionId.call(void 0, protocol, parentCtx))) : void 0;
|
|
558
|
+
const { context: sessCtx } = _chunkCBEDIRVKcjs.stampAndPropagateSession.call(void 0,
|
|
559
559
|
span,
|
|
560
560
|
resolved,
|
|
561
561
|
parentCtx,
|
|
@@ -611,7 +611,7 @@ function safeEnd(span) {
|
|
|
611
611
|
|
|
612
612
|
// src/internal/instrumentation/mcp/version.ts
|
|
613
613
|
var INSTRUMENTATION_NAME = "@brizz/sdk/mcp";
|
|
614
|
-
var INSTRUMENTATION_VERSION =
|
|
614
|
+
var INSTRUMENTATION_VERSION = _chunkCBEDIRVKcjs.getSDKVersion.call(void 0, );
|
|
615
615
|
|
|
616
616
|
// src/internal/instrumentation/mcp/instrumentation.ts
|
|
617
617
|
var PROTOCOL_MODULE_NAME = "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
@@ -8,11 +8,11 @@ import {
|
|
|
8
8
|
resolveTransportSessionId,
|
|
9
9
|
sessionToolResult,
|
|
10
10
|
stampAndPropagateSession
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-BAQTZKGI.js";
|
|
12
12
|
import {
|
|
13
13
|
logger
|
|
14
14
|
} from "./chunk-Y4HNUX3Q.js";
|
|
15
|
-
import "./chunk-
|
|
15
|
+
import "./chunk-AOT5NJDV.js";
|
|
16
16
|
import "./chunk-3RG5ZIWI.js";
|
|
17
17
|
|
|
18
18
|
// src/internal/instrumentation/mcp/instrumentation.ts
|
|
@@ -2,8 +2,8 @@ import './internal/instrumentation/auto-init.js';
|
|
|
2
2
|
export { Brizz, type IBrizzInitializeOptions } from './internal/sdk.js';
|
|
3
3
|
export { type IInstrumentModules, type IMCPManualModules, } from './internal/instrumentation/index.js';
|
|
4
4
|
export { emitEvent, emitEventWithSessionId } from './internal/log/index.js';
|
|
5
|
-
export { getSpanExporter, getSpanProcessor, withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, setServiceName, withServiceName, callWithServiceName, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './internal/trace/index.js';
|
|
6
|
-
export type { IMuteOptions } from './internal/trace/index.js';
|
|
5
|
+
export { getSpanExporter, getSpanProcessor, withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, setServiceName, withServiceName, callWithServiceName, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startAgent, withAgent, setAgent, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './internal/trace/index.js';
|
|
6
|
+
export type { IMuteOptions, AgentRef, IAgent, IAgentOptions } from './internal/trace/index.js';
|
|
7
7
|
export { getMetricsExporter, getMetricsReader } from './internal/metric/index.js';
|
|
8
8
|
export type { IMaskingConfig, ISpanMaskingConfig, ILogMaskingConfig, IEventMaskingConfig, IEventMaskingRule, MaskingMode, IAttributesMaskingRule, } from './internal/masking/index.js';
|
|
9
9
|
export { DEFAULT_PII_PATTERNS } from './internal/masking/patterns.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
2
|
+
export declare function patchCallbackManagerModule(module: unknown): boolean;
|
|
3
|
+
export declare function patchInstalledCallbackManager(): void;
|
|
4
|
+
export declare function restampLangChainSpan(span: ReadableSpan): void;
|
|
@@ -26,6 +26,9 @@ export declare const SERVICE_NAME_ATTRIBUTE = "brizz.service.name";
|
|
|
26
26
|
export declare const SESSION_TITLE_SPAN_NAME = "brizz.session_title";
|
|
27
27
|
export declare const SESSION_TITLE_GENERATION = "session.title_generation";
|
|
28
28
|
export declare const SESSION_TITLE = "brizz.session.title";
|
|
29
|
+
export declare const AGENT_ID = "internal.agent.id";
|
|
30
|
+
export declare const AGENT_PARENT_ID = "internal.agent.parent_id";
|
|
31
|
+
export declare const AGENT_NAME = "internal.agent.name";
|
|
29
32
|
export declare const INTERRUPT_TOOLS = "brizz.internal.interrupt";
|
|
30
33
|
export declare const INTERNAL_EVENT_PREFIX = "brizz.internal.";
|
|
31
34
|
export declare const EXTERNAL_LINK_EVENT_NAME = "brizz.internal.external_link";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface IAgent {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly parentId: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly traceparent: string;
|
|
6
|
+
readonly sessionId: string;
|
|
7
|
+
readonly token: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IAgentOptions {
|
|
10
|
+
name?: string;
|
|
11
|
+
id?: string;
|
|
12
|
+
parentId?: string;
|
|
13
|
+
token?: string;
|
|
14
|
+
}
|
|
15
|
+
export type AgentRef = string | IAgentOptions;
|
|
16
|
+
export declare function startAgent<T>(agent: AgentRef, callback: (agent: IAgent) => T): T;
|
|
17
|
+
export declare function withAgent<F extends (this: any, ...args: any[]) => any>(agent: AgentRef, fn: F, thisArg?: ThisParameterType<F>): F;
|
|
18
|
+
export declare function setAgent(agent: AgentRef): IAgent;
|
|
@@ -2,3 +2,5 @@ export { TracingModule, getSpanExporter, getSpanProcessor } from './tracing.js';
|
|
|
2
2
|
export { BrizzBatchSpanProcessor, BrizzSimpleSpanProcessor } from './processors/span-processor.js';
|
|
3
3
|
export { withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, setServiceName, withServiceName, callWithServiceName, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './session.js';
|
|
4
4
|
export type { IMuteOptions } from './session.js';
|
|
5
|
+
export { startAgent, withAgent, setAgent } from './agent.js';
|
|
6
|
+
export type { AgentRef, IAgent, IAgentOptions } from './agent.js';
|