@brizz/sdk 0.1.39 → 0.1.40
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-JBNWC4YN.js → chunk-BGLKBQ6N.js} +1 -1
- package/dist/{chunk-NMDPWJMU.cjs → chunk-RNU3DOSR.cjs} +1 -1
- package/dist/index.cjs +13 -7
- package/dist/index.js +9 -3
- package/dist/{mcp-3N3DAQGD.cjs → mcp-64ZNSCIR.cjs} +53 -25
- package/dist/{mcp-EWOGAW4J.js → mcp-HBOMHU67.js} +33 -5
- package/dist/types/cjs/index.d.ts +1 -1
- package/dist/types/cjs/internal/instrumentation/mcp/session.d.ts +1 -0
- package/dist/types/cjs/internal/trace/index.d.ts +1 -1
- package/dist/types/cjs/internal/trace/session.d.ts +1 -0
- package/dist/types/esm/index.d.ts +1 -1
- package/dist/types/esm/internal/instrumentation/mcp/session.d.ts +1 -0
- package/dist/types/esm/internal/trace/index.d.ts +1 -1
- package/dist/types/esm/internal/trace/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 _chunkRNU3DOSRcjs = require('./chunk-RNU3DOSR.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-64ZNSCIR.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-64ZNSCIR.cjs")));
|
|
511
511
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
512
512
|
instrumentation.manuallyInstrument(mcpModules);
|
|
513
513
|
_chunkWC573FCIcjs.logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -649,6 +649,11 @@ function setMessageId(id) {
|
|
|
649
649
|
setCurrentSpanCustomProperties(properties);
|
|
650
650
|
propagatePropertiesImperatively(properties);
|
|
651
651
|
}
|
|
652
|
+
function setSessionId(id) {
|
|
653
|
+
const properties = { [_chunk77UGZGMPcjs.SESSION_ID]: id };
|
|
654
|
+
setCurrentSpanCustomProperties(properties);
|
|
655
|
+
propagatePropertiesImperatively(properties);
|
|
656
|
+
}
|
|
652
657
|
function userProperties(user) {
|
|
653
658
|
const properties = { [_chunk77UGZGMPcjs.USER_ID]: user.id };
|
|
654
659
|
if (user.email !== void 0) {
|
|
@@ -1764,7 +1769,7 @@ var LoggingModule = (_class3 = class _LoggingModule {constructor() { _class3.pro
|
|
|
1764
1769
|
const resourceAttributes = {
|
|
1765
1770
|
...config.resourceAttributes,
|
|
1766
1771
|
"service.name": config.appName,
|
|
1767
|
-
[BRIZZ_SDK_VERSION]:
|
|
1772
|
+
[BRIZZ_SDK_VERSION]: _chunkRNU3DOSRcjs.getSDKVersion.call(void 0, ),
|
|
1768
1773
|
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
1769
1774
|
};
|
|
1770
1775
|
if (config.environment) {
|
|
@@ -1989,7 +1994,7 @@ var BrizzSpanExporter = class {
|
|
|
1989
1994
|
const resourceAttrs = {
|
|
1990
1995
|
...config.resourceAttributes,
|
|
1991
1996
|
"service.name": config.appName,
|
|
1992
|
-
[BRIZZ_SDK_VERSION]:
|
|
1997
|
+
[BRIZZ_SDK_VERSION]: _chunkRNU3DOSRcjs.getSDKVersion.call(void 0, ),
|
|
1993
1998
|
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
1994
1999
|
};
|
|
1995
2000
|
if (config.environment) {
|
|
@@ -2281,7 +2286,7 @@ var _Brizz = (_class6 = class __Brizz {constructor() { _class6.prototype.__init1
|
|
|
2281
2286
|
const resourceAttributes = {
|
|
2282
2287
|
...resolvedConfig.resourceAttributes,
|
|
2283
2288
|
"service.name": resolvedConfig.appName,
|
|
2284
|
-
[BRIZZ_SDK_VERSION]:
|
|
2289
|
+
[BRIZZ_SDK_VERSION]: _chunkRNU3DOSRcjs.getSDKVersion.call(void 0, ),
|
|
2285
2290
|
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
2286
2291
|
};
|
|
2287
2292
|
if (resolvedConfig.environment) {
|
|
@@ -2492,4 +2497,5 @@ var Brizz = new _Brizz();
|
|
|
2492
2497
|
|
|
2493
2498
|
|
|
2494
2499
|
|
|
2495
|
-
|
|
2500
|
+
|
|
2501
|
+
exports.Brizz = Brizz; exports.DEFAULT_PII_PATTERNS = DEFAULT_PII_PATTERNS; exports.LogLevel = _chunkWC573FCIcjs.LogLevel; exports.Session = Session; exports.SessionTitle = SessionTitle; exports.SeverityNumber = _apilogs.SeverityNumber; exports.addExternalLink = addExternalLink; exports.callWithMessageId = callWithMessageId; exports.callWithMute = callWithMute; exports.callWithOrganization = callWithOrganization; exports.callWithProperties = callWithProperties; exports.callWithSessionId = callWithSessionId; exports.callWithUser = callWithUser; exports.emitEvent = emitEvent; exports.emitEventWithSessionId = emitEventWithSessionId; exports.getActiveSession = getActiveSession; exports.getLogLevel = _chunkWC573FCIcjs.getLogLevel; exports.getMetricsExporter = getMetricsExporter; exports.getMetricsReader = getMetricsReader; exports.getSpanExporter = getSpanExporter; exports.getSpanProcessor = getSpanProcessor; exports.logger = _chunkWC573FCIcjs.logger; exports.maskAttributes = maskAttributes; exports.maskValue = maskValue; exports.recordFeedback = recordFeedback; exports.recordMetric = recordMetric; exports.setCurrentSpanCustomProperties = setCurrentSpanCustomProperties; exports.setLogLevel = _chunkWC573FCIcjs.setLogLevel; exports.setMessageId = setMessageId; exports.setOrganization = setOrganization; exports.setSessionId = setSessionId; exports.setUser = setUser; exports.startSession = startSession; exports.startSessionTitle = startSessionTitle; exports.withMessageId = withMessageId; exports.withMute = withMute; exports.withOrganization = withOrganization; exports.withProperties = withProperties; exports.withSessionId = withSessionId; exports.withUser = withUser;
|
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-BGLKBQ6N.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-HBOMHU67.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-HBOMHU67.js");
|
|
511
511
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
512
512
|
instrumentation.manuallyInstrument(mcpModules);
|
|
513
513
|
logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -649,6 +649,11 @@ function setMessageId(id) {
|
|
|
649
649
|
setCurrentSpanCustomProperties(properties);
|
|
650
650
|
propagatePropertiesImperatively(properties);
|
|
651
651
|
}
|
|
652
|
+
function setSessionId(id) {
|
|
653
|
+
const properties = { [SESSION_ID]: id };
|
|
654
|
+
setCurrentSpanCustomProperties(properties);
|
|
655
|
+
propagatePropertiesImperatively(properties);
|
|
656
|
+
}
|
|
652
657
|
function userProperties(user) {
|
|
653
658
|
const properties = { [USER_ID]: user.id };
|
|
654
659
|
if (user.email !== void 0) {
|
|
@@ -2483,6 +2488,7 @@ export {
|
|
|
2483
2488
|
setLogLevel,
|
|
2484
2489
|
setMessageId,
|
|
2485
2490
|
setOrganization,
|
|
2491
|
+
setSessionId,
|
|
2486
2492
|
setUser,
|
|
2487
2493
|
startSession,
|
|
2488
2494
|
startSessionTitle,
|
|
@@ -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 _chunkRNU3DOSRcjs = require('./chunk-RNU3DOSR.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
|
|
@@ -133,6 +133,34 @@ function extractTools(result) {
|
|
|
133
133
|
|
|
134
134
|
// src/internal/instrumentation/mcp/session.ts
|
|
135
135
|
|
|
136
|
+
var FALLBACK_SESSION_ID = /* @__PURE__ */ Symbol("brizz.mcp.fallback-session-id");
|
|
137
|
+
var FALLBACK_SESSION_ID_BYTES = 16;
|
|
138
|
+
function generateSessionId() {
|
|
139
|
+
let id = "";
|
|
140
|
+
for (let i = 0; i < FALLBACK_SESSION_ID_BYTES; i++) {
|
|
141
|
+
id += Math.floor(Math.random() * 256).toString(16).padStart(2, "0");
|
|
142
|
+
}
|
|
143
|
+
return id;
|
|
144
|
+
}
|
|
145
|
+
function resolveSessionId(protocol, baseContext) {
|
|
146
|
+
if (typeof protocol !== "object" || protocol === null) {
|
|
147
|
+
return void 0;
|
|
148
|
+
}
|
|
149
|
+
const carrier = protocol;
|
|
150
|
+
const fromTransport = _nullishCoalesce(carrier.sessionId, () => ( _optionalChain([carrier, 'access', _ => _._transport, 'optionalAccess', _2 => _2.sessionId])));
|
|
151
|
+
if (fromTransport) {
|
|
152
|
+
return fromTransport;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
const bound = baseContext.getValue(_chunk77UGZGMPcjs.PROPERTIES_CONTEXT_KEY);
|
|
156
|
+
if (_optionalChain([bound, 'optionalAccess', _3 => _3[_chunk77UGZGMPcjs.SESSION_ID]])) {
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
159
|
+
} catch (e2) {
|
|
160
|
+
}
|
|
161
|
+
carrier[FALLBACK_SESSION_ID] ??= generateSessionId();
|
|
162
|
+
return carrier[FALLBACK_SESSION_ID];
|
|
163
|
+
}
|
|
136
164
|
function stampAndPropagateSession(span, sessionId, baseContext = _api.context.active()) {
|
|
137
165
|
if (!sessionId) {
|
|
138
166
|
return { context: baseContext, sessionId: null };
|
|
@@ -164,19 +192,19 @@ function stampAndPropagateSession(span, sessionId, baseContext = _api.context.ac
|
|
|
164
192
|
function deriveSpanName(method, params) {
|
|
165
193
|
try {
|
|
166
194
|
if (method === METHOD_TOOLS_CALL) {
|
|
167
|
-
const name = typeof _optionalChain([params, 'optionalAccess',
|
|
195
|
+
const name = typeof _optionalChain([params, 'optionalAccess', _4 => _4["name"]]) === "string" ? params["name"] : "";
|
|
168
196
|
return name ? `${SPAN_NAME_TOOLS_CALL} ${name}` : SPAN_NAME_TOOLS_CALL;
|
|
169
197
|
}
|
|
170
198
|
if (method === METHOD_RESOURCES_READ) {
|
|
171
|
-
const uri = typeof _optionalChain([params, 'optionalAccess',
|
|
199
|
+
const uri = typeof _optionalChain([params, 'optionalAccess', _5 => _5["uri"]]) === "string" ? params["uri"] : "";
|
|
172
200
|
return uri ? `${METHOD_RESOURCES_READ} ${uri}` : METHOD_RESOURCES_READ;
|
|
173
201
|
}
|
|
174
202
|
if (method === METHOD_PROMPTS_GET) {
|
|
175
|
-
const name = typeof _optionalChain([params, 'optionalAccess',
|
|
203
|
+
const name = typeof _optionalChain([params, 'optionalAccess', _6 => _6["name"]]) === "string" ? params["name"] : "";
|
|
176
204
|
return name ? `${METHOD_PROMPTS_GET} ${name}` : METHOD_PROMPTS_GET;
|
|
177
205
|
}
|
|
178
206
|
return method;
|
|
179
|
-
} catch (
|
|
207
|
+
} catch (e3) {
|
|
180
208
|
return method || "mcp";
|
|
181
209
|
}
|
|
182
210
|
}
|
|
@@ -205,12 +233,12 @@ function applyServerRequestAttributes(span, request, protocol) {
|
|
|
205
233
|
applyBaseAttributes(span, request);
|
|
206
234
|
applyMethodSpecificRequestAttributes(span, request);
|
|
207
235
|
if (request.method === METHOD_TOOLS_CALL) {
|
|
208
|
-
const args = _optionalChain([request, 'access',
|
|
236
|
+
const args = _optionalChain([request, 'access', _7 => _7.params, 'optionalAccess', _8 => _8["arguments"]]);
|
|
209
237
|
if (args !== void 0) {
|
|
210
238
|
span.setAttribute(MCP_TOOL_ARGUMENTS, serializeForAttribute(args));
|
|
211
239
|
}
|
|
212
240
|
}
|
|
213
|
-
const sessionId = _nullishCoalesce(protocol.sessionId, () => ( _optionalChain([protocol, 'access',
|
|
241
|
+
const sessionId = _nullishCoalesce(protocol.sessionId, () => ( _optionalChain([protocol, 'access', _9 => _9._transport, 'optionalAccess', _10 => _10.sessionId])));
|
|
214
242
|
if (sessionId) {
|
|
215
243
|
span.setAttribute(MCP_SESSION_ID, sessionId);
|
|
216
244
|
}
|
|
@@ -258,7 +286,7 @@ function applyResultAttributes(span, method, result) {
|
|
|
258
286
|
return;
|
|
259
287
|
}
|
|
260
288
|
const obj = result && typeof result === "object" ? result : null;
|
|
261
|
-
const content = _nullishCoalesce(_optionalChain([obj, 'optionalAccess',
|
|
289
|
+
const content = _nullishCoalesce(_optionalChain([obj, 'optionalAccess', _11 => _11["content"]]), () => ( result));
|
|
262
290
|
span.setAttribute(MCP_TOOL_RESULT, serializeForAttribute(content));
|
|
263
291
|
if (obj && obj["isError"] === true) {
|
|
264
292
|
span.setAttribute(ERROR_TYPE, ERROR_TYPE_TOOL);
|
|
@@ -268,24 +296,24 @@ function applyResultAttributes(span, method, result) {
|
|
|
268
296
|
}
|
|
269
297
|
function applyErrorAttributes(span, err) {
|
|
270
298
|
const error = err;
|
|
271
|
-
const code = _optionalChain([error, 'optionalAccess',
|
|
299
|
+
const code = _optionalChain([error, 'optionalAccess', _12 => _12.code]);
|
|
272
300
|
if (typeof code === "number") {
|
|
273
301
|
span.setAttribute(RPC_RESPONSE_STATUS_CODE, code);
|
|
274
302
|
span.setAttribute(ERROR_TYPE, String(code));
|
|
275
|
-
} else if (_optionalChain([error, 'optionalAccess',
|
|
303
|
+
} else if (_optionalChain([error, 'optionalAccess', _13 => _13.name]) === "AbortError") {
|
|
276
304
|
span.setAttribute(ERROR_TYPE, "cancelled");
|
|
277
|
-
} else if (_optionalChain([error, 'optionalAccess',
|
|
305
|
+
} else if (_optionalChain([error, 'optionalAccess', _14 => _14.name]) === "TimeoutError") {
|
|
278
306
|
span.setAttribute(ERROR_TYPE, "timeout");
|
|
279
307
|
} else {
|
|
280
|
-
span.setAttribute(ERROR_TYPE, _optionalChain([error, 'optionalAccess',
|
|
308
|
+
span.setAttribute(ERROR_TYPE, _optionalChain([error, 'optionalAccess', _15 => _15.constructor, 'optionalAccess', _16 => _16.name]) || _optionalChain([error, 'optionalAccess', _17 => _17.name]) || "Error");
|
|
281
309
|
}
|
|
282
310
|
try {
|
|
283
311
|
span.recordException(error);
|
|
284
|
-
} catch (
|
|
312
|
+
} catch (e4) {
|
|
285
313
|
}
|
|
286
314
|
span.setStatus({
|
|
287
315
|
code: _api.SpanStatusCode.ERROR,
|
|
288
|
-
message: typeof _optionalChain([error, 'optionalAccess',
|
|
316
|
+
message: typeof _optionalChain([error, 'optionalAccess', _18 => _18.message]) === "string" ? error.message : void 0
|
|
289
317
|
});
|
|
290
318
|
}
|
|
291
319
|
function serializeForAttribute(value) {
|
|
@@ -304,7 +332,7 @@ function rawSerialize(value) {
|
|
|
304
332
|
}
|
|
305
333
|
try {
|
|
306
334
|
return JSON.stringify(value);
|
|
307
|
-
} catch (
|
|
335
|
+
} catch (e5) {
|
|
308
336
|
try {
|
|
309
337
|
if (value === null || value === void 0) {
|
|
310
338
|
return "";
|
|
@@ -314,7 +342,7 @@ function rawSerialize(value) {
|
|
|
314
342
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
315
343
|
String(value)
|
|
316
344
|
) : tag;
|
|
317
|
-
} catch (
|
|
345
|
+
} catch (e6) {
|
|
318
346
|
return "";
|
|
319
347
|
}
|
|
320
348
|
}
|
|
@@ -421,7 +449,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
421
449
|
return original.apply(this, args);
|
|
422
450
|
}
|
|
423
451
|
const { span, spanCtx } = started;
|
|
424
|
-
const transportSessionId = _nullishCoalesce(
|
|
452
|
+
const transportSessionId = _nullishCoalesce(started.sessionId, () => ( void 0));
|
|
425
453
|
const postResult = method === METHOD_TOOLS_LIST ? (result) => {
|
|
426
454
|
try {
|
|
427
455
|
emitSchemaSpansFromListResponse(result, transportSessionId, tracer);
|
|
@@ -500,7 +528,7 @@ function safeStartClientSpan(tracer, request, protocol) {
|
|
|
500
528
|
applyClientRequestAttributes(
|
|
501
529
|
span,
|
|
502
530
|
request,
|
|
503
|
-
_optionalChain([protocol, 'access',
|
|
531
|
+
_optionalChain([protocol, 'access', _19 => _19._transport, 'optionalAccess', _20 => _20.constructor, 'optionalAccess', _21 => _21.name])
|
|
504
532
|
);
|
|
505
533
|
return span;
|
|
506
534
|
} catch (error) {
|
|
@@ -518,9 +546,9 @@ function safeStartServerSpan(tracer, request, protocol) {
|
|
|
518
546
|
parentCtx
|
|
519
547
|
);
|
|
520
548
|
applyServerRequestAttributes(span, request, protocol);
|
|
521
|
-
const
|
|
522
|
-
const { context: sessCtx } = stampAndPropagateSession(span,
|
|
523
|
-
return { span, spanCtx: _api.trace.setSpan(sessCtx, span) };
|
|
549
|
+
const resolved = resolveSessionId(protocol, parentCtx);
|
|
550
|
+
const { context: sessCtx, sessionId } = stampAndPropagateSession(span, resolved, parentCtx);
|
|
551
|
+
return { span, spanCtx: _api.trace.setSpan(sessCtx, span), sessionId };
|
|
524
552
|
} catch (error) {
|
|
525
553
|
_chunkWC573FCIcjs.logger.debug(`Brizz MCP: failed to open SERVER span: ${String(error)}`);
|
|
526
554
|
return null;
|
|
@@ -528,7 +556,7 @@ function safeStartServerSpan(tracer, request, protocol) {
|
|
|
528
556
|
}
|
|
529
557
|
function extractParentContext(request) {
|
|
530
558
|
try {
|
|
531
|
-
const meta = _optionalChain([request, 'access',
|
|
559
|
+
const meta = _optionalChain([request, 'access', _22 => _22.params, 'optionalAccess', _23 => _23._meta]);
|
|
532
560
|
if (meta && typeof meta === "object") {
|
|
533
561
|
return _api.propagation.extract(_api.context.active(), meta);
|
|
534
562
|
}
|
|
@@ -570,7 +598,7 @@ function safeEnd(span) {
|
|
|
570
598
|
|
|
571
599
|
// src/internal/instrumentation/mcp/version.ts
|
|
572
600
|
var INSTRUMENTATION_NAME = "@brizz/sdk/mcp";
|
|
573
|
-
var INSTRUMENTATION_VERSION =
|
|
601
|
+
var INSTRUMENTATION_VERSION = _chunkRNU3DOSRcjs.getSDKVersion.call(void 0, );
|
|
574
602
|
|
|
575
603
|
// src/internal/instrumentation/mcp/instrumentation.ts
|
|
576
604
|
var PROTOCOL_MODULE_NAME = "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
@@ -588,7 +616,7 @@ var MCPInstrumentation = class extends _openinferenceinstrumentationmcp.MCPInstr
|
|
|
588
616
|
*/
|
|
589
617
|
|
|
590
618
|
constructor(_config) {
|
|
591
|
-
super({ instrumentationConfig: _optionalChain([_config, 'optionalAccess',
|
|
619
|
+
super({ instrumentationConfig: _optionalChain([_config, 'optionalAccess', _24 => _24.instrumentationConfig]) });
|
|
592
620
|
this.brizzTracer = _api.trace.getTracer(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION);
|
|
593
621
|
}
|
|
594
622
|
/**
|
|
@@ -598,7 +626,7 @@ var MCPInstrumentation = class extends _openinferenceinstrumentationmcp.MCPInstr
|
|
|
598
626
|
* calls `patchProtocolPrototype`.
|
|
599
627
|
*/
|
|
600
628
|
patchProtocolModule(module) {
|
|
601
|
-
const proto = _optionalChain([module, 'optionalAccess',
|
|
629
|
+
const proto = _optionalChain([module, 'optionalAccess', _25 => _25.Protocol, 'optionalAccess', _26 => _26.prototype]);
|
|
602
630
|
if (!proto) {
|
|
603
631
|
_chunkWC573FCIcjs.logger.debug(
|
|
604
632
|
"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-BGLKBQ6N.js";
|
|
4
4
|
import {
|
|
5
5
|
logger
|
|
6
6
|
} from "./chunk-Y4HNUX3Q.js";
|
|
@@ -133,6 +133,34 @@ function extractTools(result) {
|
|
|
133
133
|
|
|
134
134
|
// src/internal/instrumentation/mcp/session.ts
|
|
135
135
|
import { context } from "@opentelemetry/api";
|
|
136
|
+
var FALLBACK_SESSION_ID = /* @__PURE__ */ Symbol("brizz.mcp.fallback-session-id");
|
|
137
|
+
var FALLBACK_SESSION_ID_BYTES = 16;
|
|
138
|
+
function generateSessionId() {
|
|
139
|
+
let id = "";
|
|
140
|
+
for (let i = 0; i < FALLBACK_SESSION_ID_BYTES; i++) {
|
|
141
|
+
id += Math.floor(Math.random() * 256).toString(16).padStart(2, "0");
|
|
142
|
+
}
|
|
143
|
+
return id;
|
|
144
|
+
}
|
|
145
|
+
function resolveSessionId(protocol, baseContext) {
|
|
146
|
+
if (typeof protocol !== "object" || protocol === null) {
|
|
147
|
+
return void 0;
|
|
148
|
+
}
|
|
149
|
+
const carrier = protocol;
|
|
150
|
+
const fromTransport = carrier.sessionId ?? carrier._transport?.sessionId;
|
|
151
|
+
if (fromTransport) {
|
|
152
|
+
return fromTransport;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
const bound = baseContext.getValue(PROPERTIES_CONTEXT_KEY);
|
|
156
|
+
if (bound?.[SESSION_ID]) {
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
159
|
+
} catch {
|
|
160
|
+
}
|
|
161
|
+
carrier[FALLBACK_SESSION_ID] ??= generateSessionId();
|
|
162
|
+
return carrier[FALLBACK_SESSION_ID];
|
|
163
|
+
}
|
|
136
164
|
function stampAndPropagateSession(span, sessionId, baseContext = context.active()) {
|
|
137
165
|
if (!sessionId) {
|
|
138
166
|
return { context: baseContext, sessionId: null };
|
|
@@ -421,7 +449,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
421
449
|
return original.apply(this, args);
|
|
422
450
|
}
|
|
423
451
|
const { span, spanCtx } = started;
|
|
424
|
-
const transportSessionId =
|
|
452
|
+
const transportSessionId = started.sessionId ?? void 0;
|
|
425
453
|
const postResult = method === METHOD_TOOLS_LIST ? (result) => {
|
|
426
454
|
try {
|
|
427
455
|
emitSchemaSpansFromListResponse(result, transportSessionId, tracer);
|
|
@@ -518,9 +546,9 @@ function safeStartServerSpan(tracer, request, protocol) {
|
|
|
518
546
|
parentCtx
|
|
519
547
|
);
|
|
520
548
|
applyServerRequestAttributes(span, request, protocol);
|
|
521
|
-
const
|
|
522
|
-
const { context: sessCtx } = stampAndPropagateSession(span,
|
|
523
|
-
return { span, spanCtx: trace.setSpan(sessCtx, span) };
|
|
549
|
+
const resolved = resolveSessionId(protocol, parentCtx);
|
|
550
|
+
const { context: sessCtx, sessionId } = stampAndPropagateSession(span, resolved, parentCtx);
|
|
551
|
+
return { span, spanCtx: trace.setSpan(sessCtx, span), sessionId };
|
|
524
552
|
} catch (error) {
|
|
525
553
|
logger.debug(`Brizz MCP: failed to open SERVER span: ${String(error)}`);
|
|
526
554
|
return null;
|
|
@@ -2,7 +2,7 @@ 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, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './internal/trace/index.js';
|
|
5
|
+
export { getSpanExporter, getSpanProcessor, withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './internal/trace/index.js';
|
|
6
6
|
export type { IMuteOptions } 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';
|
|
@@ -3,4 +3,5 @@ export interface ISessionAttachResult {
|
|
|
3
3
|
context: Context;
|
|
4
4
|
sessionId: string | null;
|
|
5
5
|
}
|
|
6
|
+
export declare function resolveSessionId(protocol: unknown, baseContext: Context): string | undefined;
|
|
6
7
|
export declare function stampAndPropagateSession(span: Span, sessionId: string | null | undefined, baseContext?: Context): ISessionAttachResult;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { TracingModule, getSpanExporter, getSpanProcessor } from './tracing.js';
|
|
2
2
|
export { BrizzBatchSpanProcessor, BrizzSimpleSpanProcessor } from './processors/span-processor.js';
|
|
3
|
-
export { withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './session.js';
|
|
3
|
+
export { withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, 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';
|
|
@@ -22,6 +22,7 @@ export declare function setOrganization(org: {
|
|
|
22
22
|
traits?: Record<string, string>;
|
|
23
23
|
}): void;
|
|
24
24
|
export declare function setMessageId(id: string): void;
|
|
25
|
+
export declare function setSessionId(id: string): void;
|
|
25
26
|
export declare function callWithUser<A extends unknown[], F extends (...args: A) => ReturnType<F>>(user: {
|
|
26
27
|
id: string;
|
|
27
28
|
email?: string;
|
|
@@ -2,7 +2,7 @@ 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, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './internal/trace/index.js';
|
|
5
|
+
export { getSpanExporter, getSpanProcessor, withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './internal/trace/index.js';
|
|
6
6
|
export type { IMuteOptions } 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';
|
|
@@ -3,4 +3,5 @@ export interface ISessionAttachResult {
|
|
|
3
3
|
context: Context;
|
|
4
4
|
sessionId: string | null;
|
|
5
5
|
}
|
|
6
|
+
export declare function resolveSessionId(protocol: unknown, baseContext: Context): string | undefined;
|
|
6
7
|
export declare function stampAndPropagateSession(span: Span, sessionId: string | null | undefined, baseContext?: Context): ISessionAttachResult;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { TracingModule, getSpanExporter, getSpanProcessor } from './tracing.js';
|
|
2
2
|
export { BrizzBatchSpanProcessor, BrizzSimpleSpanProcessor } from './processors/span-processor.js';
|
|
3
|
-
export { withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './session.js';
|
|
3
|
+
export { withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, 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';
|
|
@@ -22,6 +22,7 @@ export declare function setOrganization(org: {
|
|
|
22
22
|
traits?: Record<string, string>;
|
|
23
23
|
}): void;
|
|
24
24
|
export declare function setMessageId(id: string): void;
|
|
25
|
+
export declare function setSessionId(id: string): void;
|
|
25
26
|
export declare function callWithUser<A extends unknown[], F extends (...args: A) => ReturnType<F>>(user: {
|
|
26
27
|
id: string;
|
|
27
28
|
email?: string;
|