@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.
@@ -1,6 +1,6 @@
1
1
  // src/internal/version.ts
2
2
  function getSDKVersion() {
3
- return "0.1.39";
3
+ return "0.1.40";
4
4
  }
5
5
 
6
6
  export {
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/internal/version.ts
2
2
  function getSDKVersion() {
3
- return "0.1.39";
3
+ return "0.1.40";
4
4
  }
5
5
 
6
6
 
package/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@
4
4
  var _chunkUNLNNKZ7cjs = require('./chunk-UNLNNKZ7.cjs');
5
5
 
6
6
 
7
- var _chunkNMDPWJMUcjs = require('./chunk-NMDPWJMU.cjs');
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-3N3DAQGD.cjs")));
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-3N3DAQGD.cjs")));
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]: _chunkNMDPWJMUcjs.getSDKVersion.call(void 0, ),
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]: _chunkNMDPWJMUcjs.getSDKVersion.call(void 0, ),
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]: _chunkNMDPWJMUcjs.getSDKVersion.call(void 0, ),
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
- 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.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;
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-JBNWC4YN.js";
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-EWOGAW4J.js");
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-EWOGAW4J.js");
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 _chunkNMDPWJMUcjs = require('./chunk-NMDPWJMU.cjs');
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', _ => _["name"]]) === "string" ? params["name"] : "";
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', _2 => _2["uri"]]) === "string" ? params["uri"] : "";
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', _3 => _3["name"]]) === "string" ? params["name"] : "";
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 (e2) {
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', _4 => _4.params, 'optionalAccess', _5 => _5["arguments"]]);
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', _6 => _6._transport, 'optionalAccess', _7 => _7.sessionId])));
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', _8 => _8["content"]]), () => ( result));
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', _9 => _9.code]);
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', _10 => _10.name]) === "AbortError") {
303
+ } else if (_optionalChain([error, 'optionalAccess', _13 => _13.name]) === "AbortError") {
276
304
  span.setAttribute(ERROR_TYPE, "cancelled");
277
- } else if (_optionalChain([error, 'optionalAccess', _11 => _11.name]) === "TimeoutError") {
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', _12 => _12.constructor, 'optionalAccess', _13 => _13.name]) || _optionalChain([error, 'optionalAccess', _14 => _14.name]) || "Error");
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 (e3) {
312
+ } catch (e4) {
285
313
  }
286
314
  span.setStatus({
287
315
  code: _api.SpanStatusCode.ERROR,
288
- message: typeof _optionalChain([error, 'optionalAccess', _15 => _15.message]) === "string" ? error.message : void 0
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 (e4) {
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 (e5) {
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(this.sessionId, () => ( _optionalChain([this, 'access', _16 => _16._transport, 'optionalAccess', _17 => _17.sessionId])));
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', _18 => _18._transport, 'optionalAccess', _19 => _19.constructor, 'optionalAccess', _20 => _20.name])
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 sessionId = _nullishCoalesce(protocol.sessionId, () => ( _optionalChain([protocol, 'access', _21 => _21._transport, 'optionalAccess', _22 => _22.sessionId])));
522
- const { context: sessCtx } = stampAndPropagateSession(span, sessionId, parentCtx);
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', _23 => _23.params, 'optionalAccess', _24 => _24._meta]);
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 = _chunkNMDPWJMUcjs.getSDKVersion.call(void 0, );
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', _25 => _25.instrumentationConfig]) });
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', _26 => _26.Protocol, 'optionalAccess', _27 => _27.prototype]);
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-JBNWC4YN.js";
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 = this.sessionId ?? this._transport?.sessionId;
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 sessionId = protocol.sessionId ?? protocol._transport?.sessionId;
522
- const { context: sessCtx } = stampAndPropagateSession(span, sessionId, parentCtx);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brizz/sdk",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
4
4
  "type": "module",
5
5
  "description": "OpenTelemetry-based observability SDK for AI applications",
6
6
  "keywords": [