@brizz/sdk 0.1.40 → 0.1.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-RNU3DOSR.cjs → chunk-3QYP2SDN.cjs} +1 -1
- package/dist/{chunk-BGLKBQ6N.js → chunk-QRHMDRW6.js} +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.js +3 -3
- package/dist/{mcp-64ZNSCIR.cjs → mcp-DU7AUWUH.cjs} +54 -38
- package/dist/{mcp-HBOMHU67.js → mcp-TI3IDGUJ.js} +49 -33
- package/dist/types/cjs/internal/instrumentation/mcp/session.d.ts +1 -0
- package/dist/types/esm/internal/instrumentation/mcp/session.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
var _chunkUNLNNKZ7cjs = require('./chunk-UNLNNKZ7.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunk3QYP2SDNcjs = require('./chunk-3QYP2SDN.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -124,7 +124,7 @@ function loadGenAIInstrumentations() {
|
|
|
124
124
|
function loadMCPInstrumentation() {
|
|
125
125
|
void (async () => {
|
|
126
126
|
try {
|
|
127
|
-
const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-
|
|
127
|
+
const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-DU7AUWUH.cjs")));
|
|
128
128
|
const mcp = new MCPInstrumentation({ exceptionLogger });
|
|
129
129
|
_instrumentation.registerInstrumentations.call(void 0, { instrumentations: [mcp] });
|
|
130
130
|
_chunkWC573FCIcjs.logger.debug("Auto-loaded MCP instrumentation");
|
|
@@ -507,7 +507,7 @@ var InstrumentationRegistry = (_class = class _InstrumentationRegistry {construc
|
|
|
507
507
|
const mcpModules = this.manualModules.mcp;
|
|
508
508
|
void (async () => {
|
|
509
509
|
try {
|
|
510
|
-
const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-
|
|
510
|
+
const { MCPInstrumentation } = await Promise.resolve().then(() => _interopRequireWildcard(require("./mcp-DU7AUWUH.cjs")));
|
|
511
511
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
512
512
|
instrumentation.manuallyInstrument(mcpModules);
|
|
513
513
|
_chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -1769,7 +1769,7 @@ var LoggingModule = (_class3 = class _LoggingModule {constructor() { _class3.pro
|
|
|
1769
1769
|
const resourceAttributes = {
|
|
1770
1770
|
...config.resourceAttributes,
|
|
1771
1771
|
"service.name": config.appName,
|
|
1772
|
-
[BRIZZ_SDK_VERSION]:
|
|
1772
|
+
[BRIZZ_SDK_VERSION]: _chunk3QYP2SDNcjs.getSDKVersion.call(void 0, ),
|
|
1773
1773
|
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
1774
1774
|
};
|
|
1775
1775
|
if (config.environment) {
|
|
@@ -1994,7 +1994,7 @@ var BrizzSpanExporter = class {
|
|
|
1994
1994
|
const resourceAttrs = {
|
|
1995
1995
|
...config.resourceAttributes,
|
|
1996
1996
|
"service.name": config.appName,
|
|
1997
|
-
[BRIZZ_SDK_VERSION]:
|
|
1997
|
+
[BRIZZ_SDK_VERSION]: _chunk3QYP2SDNcjs.getSDKVersion.call(void 0, ),
|
|
1998
1998
|
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
1999
1999
|
};
|
|
2000
2000
|
if (config.environment) {
|
|
@@ -2286,7 +2286,7 @@ var _Brizz = (_class6 = class __Brizz {constructor() { _class6.prototype.__init1
|
|
|
2286
2286
|
const resourceAttributes = {
|
|
2287
2287
|
...resolvedConfig.resourceAttributes,
|
|
2288
2288
|
"service.name": resolvedConfig.appName,
|
|
2289
|
-
[BRIZZ_SDK_VERSION]:
|
|
2289
|
+
[BRIZZ_SDK_VERSION]: _chunk3QYP2SDNcjs.getSDKVersion.call(void 0, ),
|
|
2290
2290
|
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
2291
2291
|
};
|
|
2292
2292
|
if (resolvedConfig.environment) {
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-7SUF4VVI.js";
|
|
5
5
|
import {
|
|
6
6
|
getSDKVersion
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-QRHMDRW6.js";
|
|
8
8
|
import {
|
|
9
9
|
DEFAULT_LOG_LEVEL,
|
|
10
10
|
LogLevel,
|
|
@@ -124,7 +124,7 @@ function loadGenAIInstrumentations() {
|
|
|
124
124
|
function loadMCPInstrumentation() {
|
|
125
125
|
void (async () => {
|
|
126
126
|
try {
|
|
127
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
127
|
+
const { MCPInstrumentation } = await import("./mcp-TI3IDGUJ.js");
|
|
128
128
|
const mcp = new MCPInstrumentation({ exceptionLogger });
|
|
129
129
|
registerInstrumentations({ instrumentations: [mcp] });
|
|
130
130
|
logger.debug("Auto-loaded MCP instrumentation");
|
|
@@ -507,7 +507,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
507
507
|
const mcpModules = this.manualModules.mcp;
|
|
508
508
|
void (async () => {
|
|
509
509
|
try {
|
|
510
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
510
|
+
const { MCPInstrumentation } = await import("./mcp-TI3IDGUJ.js");
|
|
511
511
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
512
512
|
instrumentation.manuallyInstrument(mcpModules);
|
|
513
513
|
logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk3QYP2SDNcjs = require('./chunk-3QYP2SDN.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
|
|
@@ -77,9 +77,6 @@ function safeStringify(value) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
function emitSchemaSpansFromListResponse(result, transportSessionId, tracer) {
|
|
80
|
-
if (!transportSessionId) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
80
|
const tools = extractTools(result);
|
|
84
81
|
if (tools === void 0) {
|
|
85
82
|
return;
|
|
@@ -112,7 +109,9 @@ function stampSchemaAttributes(span, toolName, transportSessionId, tool) {
|
|
|
112
109
|
const outputSchema = tool.outputSchema !== void 0 && tool.outputSchema !== null ? truncateSchemaAttr(safeStringify(tool.outputSchema)) : "";
|
|
113
110
|
span.setAttribute(RPC_SYSTEM, RPC_SYSTEM_MCP);
|
|
114
111
|
span.setAttribute(MCP_COMPONENT_TYPE, MCP_COMPONENT_TOOL_SCHEMA);
|
|
115
|
-
|
|
112
|
+
if (transportSessionId) {
|
|
113
|
+
span.setAttribute(MCP_SESSION_ID, transportSessionId);
|
|
114
|
+
}
|
|
116
115
|
span.setAttribute(MCP_TOOL_NAME, toolName);
|
|
117
116
|
span.setAttribute(MCP_TOOL_SCHEMA_PARAMETERS, parameters);
|
|
118
117
|
span.setAttribute(MCP_TOOL_SCHEMA_OUTPUT, outputSchema);
|
|
@@ -142,12 +141,20 @@ function generateSessionId() {
|
|
|
142
141
|
}
|
|
143
142
|
return id;
|
|
144
143
|
}
|
|
144
|
+
function isSessionCarrier(value) {
|
|
145
|
+
return typeof value === "object" && value !== null;
|
|
146
|
+
}
|
|
147
|
+
function resolveTransportSessionId(protocol) {
|
|
148
|
+
if (!isSessionCarrier(protocol)) {
|
|
149
|
+
return void 0;
|
|
150
|
+
}
|
|
151
|
+
return _nullishCoalesce(protocol.sessionId, () => ( _optionalChain([protocol, 'access', _ => _._transport, 'optionalAccess', _2 => _2.sessionId])));
|
|
152
|
+
}
|
|
145
153
|
function resolveSessionId(protocol, baseContext) {
|
|
146
|
-
if (
|
|
154
|
+
if (!isSessionCarrier(protocol)) {
|
|
147
155
|
return void 0;
|
|
148
156
|
}
|
|
149
|
-
const
|
|
150
|
-
const fromTransport = _nullishCoalesce(carrier.sessionId, () => ( _optionalChain([carrier, 'access', _ => _._transport, 'optionalAccess', _2 => _2.sessionId])));
|
|
157
|
+
const fromTransport = resolveTransportSessionId(protocol);
|
|
151
158
|
if (fromTransport) {
|
|
152
159
|
return fromTransport;
|
|
153
160
|
}
|
|
@@ -158,8 +165,8 @@ function resolveSessionId(protocol, baseContext) {
|
|
|
158
165
|
}
|
|
159
166
|
} catch (e2) {
|
|
160
167
|
}
|
|
161
|
-
|
|
162
|
-
return
|
|
168
|
+
protocol[FALLBACK_SESSION_ID] ??= generateSessionId();
|
|
169
|
+
return protocol[FALLBACK_SESSION_ID];
|
|
163
170
|
}
|
|
164
171
|
function stampAndPropagateSession(span, sessionId, baseContext = _api.context.active()) {
|
|
165
172
|
if (!sessionId) {
|
|
@@ -449,19 +456,30 @@ function wrapOnRequest(original, tracer) {
|
|
|
449
456
|
return original.apply(this, args);
|
|
450
457
|
}
|
|
451
458
|
const { span, spanCtx } = started;
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
459
|
+
const hooks = {};
|
|
460
|
+
if (method === METHOD_TOOLS_LIST) {
|
|
461
|
+
hooks.onResult = (result) => {
|
|
462
|
+
try {
|
|
463
|
+
emitSchemaSpansFromListResponse(
|
|
464
|
+
result,
|
|
465
|
+
resolveTransportSessionId(this),
|
|
466
|
+
tracer
|
|
467
|
+
);
|
|
468
|
+
} catch (error) {
|
|
469
|
+
_chunkWC573FCIcjs.logger.warn(
|
|
470
|
+
`Brizz MCP: failed to emit tools/list schema spans: ${String(error)}`
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
if (method !== METHOD_TOOLS_CALL) {
|
|
476
|
+
hooks.onError = () => {
|
|
477
|
+
stampAndPropagateSession(span, resolveSessionId(this, spanCtx), spanCtx);
|
|
478
|
+
};
|
|
479
|
+
}
|
|
462
480
|
const wrappedHandler = (req, extra) => _api.context.with(
|
|
463
481
|
spanCtx,
|
|
464
|
-
() => executeHandler(span, method, handler, req, extra,
|
|
482
|
+
() => executeHandler(span, method, handler, req, extra, hooks)
|
|
465
483
|
);
|
|
466
484
|
const hadEntry = handlers.has(method);
|
|
467
485
|
const prev = handlers.get(method);
|
|
@@ -485,41 +503,39 @@ function wrapOnRequest(original, tracer) {
|
|
|
485
503
|
}
|
|
486
504
|
};
|
|
487
505
|
}
|
|
488
|
-
function executeAroundSpan(span, method, run,
|
|
506
|
+
function executeAroundSpan(span, method, run, hooks) {
|
|
489
507
|
let result;
|
|
490
508
|
try {
|
|
491
509
|
result = run();
|
|
492
510
|
} catch (error) {
|
|
493
511
|
safeApplyErrorAttributes(span, error);
|
|
512
|
+
_optionalChain([hooks, 'optionalAccess', _19 => _19.onError, 'optionalCall', _20 => _20()]);
|
|
494
513
|
safeEnd(span);
|
|
495
514
|
throw error;
|
|
496
515
|
}
|
|
497
516
|
if (!isThenable(result)) {
|
|
498
517
|
safeApplyResultAttributes(span, method, result);
|
|
499
|
-
|
|
500
|
-
postResult(result);
|
|
501
|
-
}
|
|
518
|
+
_optionalChain([hooks, 'optionalAccess', _21 => _21.onResult, 'optionalCall', _22 => _22(result)]);
|
|
502
519
|
safeEnd(span);
|
|
503
520
|
return result;
|
|
504
521
|
}
|
|
505
522
|
return result.then(
|
|
506
523
|
(value) => {
|
|
507
524
|
safeApplyResultAttributes(span, method, value);
|
|
508
|
-
|
|
509
|
-
postResult(value);
|
|
510
|
-
}
|
|
525
|
+
_optionalChain([hooks, 'optionalAccess', _23 => _23.onResult, 'optionalCall', _24 => _24(value)]);
|
|
511
526
|
safeEnd(span);
|
|
512
527
|
return value;
|
|
513
528
|
},
|
|
514
529
|
(error) => {
|
|
515
530
|
safeApplyErrorAttributes(span, error);
|
|
531
|
+
_optionalChain([hooks, 'optionalAccess', _25 => _25.onError, 'optionalCall', _26 => _26()]);
|
|
516
532
|
safeEnd(span);
|
|
517
533
|
throw error;
|
|
518
534
|
}
|
|
519
535
|
);
|
|
520
536
|
}
|
|
521
|
-
function executeHandler(span, method, handler, req, extra,
|
|
522
|
-
return executeAroundSpan(span, method, () => handler(req, extra),
|
|
537
|
+
function executeHandler(span, method, handler, req, extra, hooks) {
|
|
538
|
+
return executeAroundSpan(span, method, () => handler(req, extra), hooks);
|
|
523
539
|
}
|
|
524
540
|
function safeStartClientSpan(tracer, request, protocol) {
|
|
525
541
|
try {
|
|
@@ -528,7 +544,7 @@ function safeStartClientSpan(tracer, request, protocol) {
|
|
|
528
544
|
applyClientRequestAttributes(
|
|
529
545
|
span,
|
|
530
546
|
request,
|
|
531
|
-
_optionalChain([protocol, 'access',
|
|
547
|
+
_optionalChain([protocol, 'access', _27 => _27._transport, 'optionalAccess', _28 => _28.constructor, 'optionalAccess', _29 => _29.name])
|
|
532
548
|
);
|
|
533
549
|
return span;
|
|
534
550
|
} catch (error) {
|
|
@@ -546,9 +562,9 @@ function safeStartServerSpan(tracer, request, protocol) {
|
|
|
546
562
|
parentCtx
|
|
547
563
|
);
|
|
548
564
|
applyServerRequestAttributes(span, request, protocol);
|
|
549
|
-
const resolved = resolveSessionId(protocol, parentCtx);
|
|
550
|
-
const { context: sessCtx
|
|
551
|
-
return { span, spanCtx: _api.trace.setSpan(sessCtx, span)
|
|
565
|
+
const resolved = request.method === METHOD_TOOLS_CALL ? resolveSessionId(protocol, parentCtx) : void 0;
|
|
566
|
+
const { context: sessCtx } = stampAndPropagateSession(span, resolved, parentCtx);
|
|
567
|
+
return { span, spanCtx: _api.trace.setSpan(sessCtx, span) };
|
|
552
568
|
} catch (error) {
|
|
553
569
|
_chunkWC573FCIcjs.logger.debug(`Brizz MCP: failed to open SERVER span: ${String(error)}`);
|
|
554
570
|
return null;
|
|
@@ -556,7 +572,7 @@ function safeStartServerSpan(tracer, request, protocol) {
|
|
|
556
572
|
}
|
|
557
573
|
function extractParentContext(request) {
|
|
558
574
|
try {
|
|
559
|
-
const meta = _optionalChain([request, 'access',
|
|
575
|
+
const meta = _optionalChain([request, 'access', _30 => _30.params, 'optionalAccess', _31 => _31._meta]);
|
|
560
576
|
if (meta && typeof meta === "object") {
|
|
561
577
|
return _api.propagation.extract(_api.context.active(), meta);
|
|
562
578
|
}
|
|
@@ -598,7 +614,7 @@ function safeEnd(span) {
|
|
|
598
614
|
|
|
599
615
|
// src/internal/instrumentation/mcp/version.ts
|
|
600
616
|
var INSTRUMENTATION_NAME = "@brizz/sdk/mcp";
|
|
601
|
-
var INSTRUMENTATION_VERSION =
|
|
617
|
+
var INSTRUMENTATION_VERSION = _chunk3QYP2SDNcjs.getSDKVersion.call(void 0, );
|
|
602
618
|
|
|
603
619
|
// src/internal/instrumentation/mcp/instrumentation.ts
|
|
604
620
|
var PROTOCOL_MODULE_NAME = "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
@@ -616,7 +632,7 @@ var MCPInstrumentation = class extends _openinferenceinstrumentationmcp.MCPInstr
|
|
|
616
632
|
*/
|
|
617
633
|
|
|
618
634
|
constructor(_config) {
|
|
619
|
-
super({ instrumentationConfig: _optionalChain([_config, 'optionalAccess',
|
|
635
|
+
super({ instrumentationConfig: _optionalChain([_config, 'optionalAccess', _32 => _32.instrumentationConfig]) });
|
|
620
636
|
this.brizzTracer = _api.trace.getTracer(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION);
|
|
621
637
|
}
|
|
622
638
|
/**
|
|
@@ -626,7 +642,7 @@ var MCPInstrumentation = class extends _openinferenceinstrumentationmcp.MCPInstr
|
|
|
626
642
|
* calls `patchProtocolPrototype`.
|
|
627
643
|
*/
|
|
628
644
|
patchProtocolModule(module) {
|
|
629
|
-
const proto = _optionalChain([module, 'optionalAccess',
|
|
645
|
+
const proto = _optionalChain([module, 'optionalAccess', _33 => _33.Protocol, 'optionalAccess', _34 => _34.prototype]);
|
|
630
646
|
if (!proto) {
|
|
631
647
|
_chunkWC573FCIcjs.logger.debug(
|
|
632
648
|
"Brizz MCP: module does not expose Protocol.prototype \u2014 skipping protocol patches"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getSDKVersion
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QRHMDRW6.js";
|
|
4
4
|
import {
|
|
5
5
|
logger
|
|
6
6
|
} from "./chunk-Y4HNUX3Q.js";
|
|
@@ -77,9 +77,6 @@ function safeStringify(value) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
function emitSchemaSpansFromListResponse(result, transportSessionId, tracer) {
|
|
80
|
-
if (!transportSessionId) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
80
|
const tools = extractTools(result);
|
|
84
81
|
if (tools === void 0) {
|
|
85
82
|
return;
|
|
@@ -112,7 +109,9 @@ function stampSchemaAttributes(span, toolName, transportSessionId, tool) {
|
|
|
112
109
|
const outputSchema = tool.outputSchema !== void 0 && tool.outputSchema !== null ? truncateSchemaAttr(safeStringify(tool.outputSchema)) : "";
|
|
113
110
|
span.setAttribute(RPC_SYSTEM, RPC_SYSTEM_MCP);
|
|
114
111
|
span.setAttribute(MCP_COMPONENT_TYPE, MCP_COMPONENT_TOOL_SCHEMA);
|
|
115
|
-
|
|
112
|
+
if (transportSessionId) {
|
|
113
|
+
span.setAttribute(MCP_SESSION_ID, transportSessionId);
|
|
114
|
+
}
|
|
116
115
|
span.setAttribute(MCP_TOOL_NAME, toolName);
|
|
117
116
|
span.setAttribute(MCP_TOOL_SCHEMA_PARAMETERS, parameters);
|
|
118
117
|
span.setAttribute(MCP_TOOL_SCHEMA_OUTPUT, outputSchema);
|
|
@@ -142,12 +141,20 @@ function generateSessionId() {
|
|
|
142
141
|
}
|
|
143
142
|
return id;
|
|
144
143
|
}
|
|
144
|
+
function isSessionCarrier(value) {
|
|
145
|
+
return typeof value === "object" && value !== null;
|
|
146
|
+
}
|
|
147
|
+
function resolveTransportSessionId(protocol) {
|
|
148
|
+
if (!isSessionCarrier(protocol)) {
|
|
149
|
+
return void 0;
|
|
150
|
+
}
|
|
151
|
+
return protocol.sessionId ?? protocol._transport?.sessionId;
|
|
152
|
+
}
|
|
145
153
|
function resolveSessionId(protocol, baseContext) {
|
|
146
|
-
if (
|
|
154
|
+
if (!isSessionCarrier(protocol)) {
|
|
147
155
|
return void 0;
|
|
148
156
|
}
|
|
149
|
-
const
|
|
150
|
-
const fromTransport = carrier.sessionId ?? carrier._transport?.sessionId;
|
|
157
|
+
const fromTransport = resolveTransportSessionId(protocol);
|
|
151
158
|
if (fromTransport) {
|
|
152
159
|
return fromTransport;
|
|
153
160
|
}
|
|
@@ -158,8 +165,8 @@ function resolveSessionId(protocol, baseContext) {
|
|
|
158
165
|
}
|
|
159
166
|
} catch {
|
|
160
167
|
}
|
|
161
|
-
|
|
162
|
-
return
|
|
168
|
+
protocol[FALLBACK_SESSION_ID] ??= generateSessionId();
|
|
169
|
+
return protocol[FALLBACK_SESSION_ID];
|
|
163
170
|
}
|
|
164
171
|
function stampAndPropagateSession(span, sessionId, baseContext = context.active()) {
|
|
165
172
|
if (!sessionId) {
|
|
@@ -449,19 +456,30 @@ function wrapOnRequest(original, tracer) {
|
|
|
449
456
|
return original.apply(this, args);
|
|
450
457
|
}
|
|
451
458
|
const { span, spanCtx } = started;
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
459
|
+
const hooks = {};
|
|
460
|
+
if (method === METHOD_TOOLS_LIST) {
|
|
461
|
+
hooks.onResult = (result) => {
|
|
462
|
+
try {
|
|
463
|
+
emitSchemaSpansFromListResponse(
|
|
464
|
+
result,
|
|
465
|
+
resolveTransportSessionId(this),
|
|
466
|
+
tracer
|
|
467
|
+
);
|
|
468
|
+
} catch (error) {
|
|
469
|
+
logger.warn(
|
|
470
|
+
`Brizz MCP: failed to emit tools/list schema spans: ${String(error)}`
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
if (method !== METHOD_TOOLS_CALL) {
|
|
476
|
+
hooks.onError = () => {
|
|
477
|
+
stampAndPropagateSession(span, resolveSessionId(this, spanCtx), spanCtx);
|
|
478
|
+
};
|
|
479
|
+
}
|
|
462
480
|
const wrappedHandler = (req, extra) => context2.with(
|
|
463
481
|
spanCtx,
|
|
464
|
-
() => executeHandler(span, method, handler, req, extra,
|
|
482
|
+
() => executeHandler(span, method, handler, req, extra, hooks)
|
|
465
483
|
);
|
|
466
484
|
const hadEntry = handlers.has(method);
|
|
467
485
|
const prev = handlers.get(method);
|
|
@@ -485,41 +503,39 @@ function wrapOnRequest(original, tracer) {
|
|
|
485
503
|
}
|
|
486
504
|
};
|
|
487
505
|
}
|
|
488
|
-
function executeAroundSpan(span, method, run,
|
|
506
|
+
function executeAroundSpan(span, method, run, hooks) {
|
|
489
507
|
let result;
|
|
490
508
|
try {
|
|
491
509
|
result = run();
|
|
492
510
|
} catch (error) {
|
|
493
511
|
safeApplyErrorAttributes(span, error);
|
|
512
|
+
hooks?.onError?.();
|
|
494
513
|
safeEnd(span);
|
|
495
514
|
throw error;
|
|
496
515
|
}
|
|
497
516
|
if (!isThenable(result)) {
|
|
498
517
|
safeApplyResultAttributes(span, method, result);
|
|
499
|
-
|
|
500
|
-
postResult(result);
|
|
501
|
-
}
|
|
518
|
+
hooks?.onResult?.(result);
|
|
502
519
|
safeEnd(span);
|
|
503
520
|
return result;
|
|
504
521
|
}
|
|
505
522
|
return result.then(
|
|
506
523
|
(value) => {
|
|
507
524
|
safeApplyResultAttributes(span, method, value);
|
|
508
|
-
|
|
509
|
-
postResult(value);
|
|
510
|
-
}
|
|
525
|
+
hooks?.onResult?.(value);
|
|
511
526
|
safeEnd(span);
|
|
512
527
|
return value;
|
|
513
528
|
},
|
|
514
529
|
(error) => {
|
|
515
530
|
safeApplyErrorAttributes(span, error);
|
|
531
|
+
hooks?.onError?.();
|
|
516
532
|
safeEnd(span);
|
|
517
533
|
throw error;
|
|
518
534
|
}
|
|
519
535
|
);
|
|
520
536
|
}
|
|
521
|
-
function executeHandler(span, method, handler, req, extra,
|
|
522
|
-
return executeAroundSpan(span, method, () => handler(req, extra),
|
|
537
|
+
function executeHandler(span, method, handler, req, extra, hooks) {
|
|
538
|
+
return executeAroundSpan(span, method, () => handler(req, extra), hooks);
|
|
523
539
|
}
|
|
524
540
|
function safeStartClientSpan(tracer, request, protocol) {
|
|
525
541
|
try {
|
|
@@ -546,9 +562,9 @@ function safeStartServerSpan(tracer, request, protocol) {
|
|
|
546
562
|
parentCtx
|
|
547
563
|
);
|
|
548
564
|
applyServerRequestAttributes(span, request, protocol);
|
|
549
|
-
const resolved = resolveSessionId(protocol, parentCtx);
|
|
550
|
-
const { context: sessCtx
|
|
551
|
-
return { span, spanCtx: trace.setSpan(sessCtx, span)
|
|
565
|
+
const resolved = request.method === METHOD_TOOLS_CALL ? resolveSessionId(protocol, parentCtx) : void 0;
|
|
566
|
+
const { context: sessCtx } = stampAndPropagateSession(span, resolved, parentCtx);
|
|
567
|
+
return { span, spanCtx: trace.setSpan(sessCtx, span) };
|
|
552
568
|
} catch (error) {
|
|
553
569
|
logger.debug(`Brizz MCP: failed to open SERVER span: ${String(error)}`);
|
|
554
570
|
return null;
|
|
@@ -3,5 +3,6 @@ export interface ISessionAttachResult {
|
|
|
3
3
|
context: Context;
|
|
4
4
|
sessionId: string | null;
|
|
5
5
|
}
|
|
6
|
+
export declare function resolveTransportSessionId(protocol: unknown): string | undefined;
|
|
6
7
|
export declare function resolveSessionId(protocol: unknown, baseContext: Context): string | undefined;
|
|
7
8
|
export declare function stampAndPropagateSession(span: Span, sessionId: string | null | undefined, baseContext?: Context): ISessionAttachResult;
|
|
@@ -3,5 +3,6 @@ export interface ISessionAttachResult {
|
|
|
3
3
|
context: Context;
|
|
4
4
|
sessionId: string | null;
|
|
5
5
|
}
|
|
6
|
+
export declare function resolveTransportSessionId(protocol: unknown): string | undefined;
|
|
6
7
|
export declare function resolveSessionId(protocol: unknown, baseContext: Context): string | undefined;
|
|
7
8
|
export declare function stampAndPropagateSession(span: Span, sessionId: string | null | undefined, baseContext?: Context): ISessionAttachResult;
|