@brizz/sdk 0.1.47 → 0.1.48

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/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  configure,
7
7
  getSDKVersion
8
- } from "./chunk-V727EJE5.js";
8
+ } from "./chunk-L4P4RJT5.js";
9
9
  import {
10
10
  DEFAULT_LOG_LEVEL,
11
11
  LogLevel,
@@ -16,7 +16,7 @@ import {
16
16
  } from "./chunk-Y4HNUX3Q.js";
17
17
  import {
18
18
  InterruptPropagator
19
- } from "./chunk-APOYOP7D.js";
19
+ } from "./chunk-3OMB2F7B.js";
20
20
  import {
21
21
  AGENT_ID,
22
22
  AGENT_NAME,
@@ -45,6 +45,7 @@ import {
45
45
  METRIC_POLARITY_NEGATIVE,
46
46
  METRIC_POLARITY_POSITIVE,
47
47
  METRIC_TIMESTAMP,
48
+ METRIC_TRACE_ID,
48
49
  METRIC_UNIT,
49
50
  METRIC_VALUE,
50
51
  MUTE_INPUT,
@@ -73,7 +74,7 @@ import {
73
74
  USER_NAME,
74
75
  USER_PLAN,
75
76
  USER_ROLE
76
- } from "./chunk-AOT5NJDV.js";
77
+ } from "./chunk-FVVRWMPV.js";
77
78
  import {
78
79
  __require
79
80
  } from "./chunk-3RG5ZIWI.js";
@@ -418,7 +419,7 @@ function loadGenAIInstrumentations() {
418
419
  function loadMCPInstrumentation() {
419
420
  void (async () => {
420
421
  try {
421
- const { MCPInstrumentation } = await import("./mcp-GANFYW4J.js");
422
+ const { MCPInstrumentation } = await import("./mcp-RLTZLXHY.js");
422
423
  const mcp = new MCPInstrumentation({ exceptionLogger });
423
424
  registerInstrumentations({ instrumentations: [mcp] });
424
425
  logger.debug("Auto-loaded MCP instrumentation");
@@ -482,7 +483,7 @@ function loadVercelAITelemetry() {
482
483
  }
483
484
  const isV7 = typeof ai.registerTelemetry === "function";
484
485
  const integrations = [];
485
- const { createInterruptIntegration } = await import("./interrupt-A6O7N72X.js");
486
+ const { createInterruptIntegration } = await import("./interrupt-YO3ID433.js");
486
487
  integrations.push(createInterruptIntegration());
487
488
  let otelCollectorLoaded = false;
488
489
  try {
@@ -914,7 +915,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
914
915
  const mcpModules = this.manualModules.mcp;
915
916
  void (async () => {
916
917
  try {
917
- const { MCPInstrumentation } = await import("./mcp-GANFYW4J.js");
918
+ const { MCPInstrumentation } = await import("./mcp-RLTZLXHY.js");
918
919
  const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
919
920
  instrumentation.manuallyInstrument(mcpModules);
920
921
  logger.debug("Manual instrumentation enabled for MCP");
@@ -1059,22 +1060,23 @@ function setSessionId(id) {
1059
1060
  propagatePropertiesImperatively(properties);
1060
1061
  }
1061
1062
  var SERVICE_NAME_MAX_BYTES = 256;
1062
- function serviceNameProperties(name) {
1063
+ function serviceNameProblem(name) {
1063
1064
  if (typeof name !== "string" || name === "") {
1064
- logger.warn("Service name must be a non-empty string; keeping the configured appName.");
1065
- return {};
1065
+ return "must be a non-empty string";
1066
1066
  }
1067
1067
  if (/[\r\n\0]/.test(name)) {
1068
- logger.warn(
1069
- `Service name ${JSON.stringify(name)} contains CR, LF, or NUL; keeping the configured appName.`
1070
- );
1071
- return {};
1068
+ return `${JSON.stringify(name)} contains CR, LF, or NUL`;
1072
1069
  }
1073
1070
  const byteLength = new globalThis.TextEncoder().encode(name).length;
1074
1071
  if (byteLength > SERVICE_NAME_MAX_BYTES) {
1075
- logger.warn(
1076
- `Service name is ${byteLength} bytes, over the ${SERVICE_NAME_MAX_BYTES}-byte limit; keeping the configured appName.`
1077
- );
1072
+ return `is ${byteLength} bytes, over the ${SERVICE_NAME_MAX_BYTES}-byte limit`;
1073
+ }
1074
+ return void 0;
1075
+ }
1076
+ function serviceNameProperties(name) {
1077
+ const problem = serviceNameProblem(name);
1078
+ if (problem !== void 0) {
1079
+ logger.warn(`Service name ${problem}; keeping the configured appName.`);
1078
1080
  return {};
1079
1081
  }
1080
1082
  return { [SERVICE_NAME]: name };
@@ -1457,6 +1459,13 @@ function recordMetricImpl(options) {
1457
1459
  );
1458
1460
  return;
1459
1461
  }
1462
+ if (options.serviceName !== void 0) {
1463
+ const problem = serviceNameProblem(options.serviceName);
1464
+ if (problem !== void 0) {
1465
+ logger.warn(`recordMetric(${name}) service name ${problem}; metric dropped.`);
1466
+ return;
1467
+ }
1468
+ }
1460
1469
  const eventAttributes = {
1461
1470
  [METRIC_NAME]: name,
1462
1471
  [METRIC_VALUE]: numericValue
@@ -1526,16 +1535,32 @@ function recordMetricImpl(options) {
1526
1535
  accepted += 1;
1527
1536
  }
1528
1537
  }
1529
- const sessionId = options.sessionId ?? resolveSessionIdFromContext();
1530
- if (sessionId === void 0) {
1538
+ const traceId = typeof options.traceId === "string" && options.traceId !== "" ? options.traceId : void 0;
1539
+ if (traceId !== void 0) {
1540
+ eventAttributes[METRIC_TRACE_ID] = traceId;
1541
+ }
1542
+ const sessionId = options.sessionId ?? (traceId === void 0 ? resolveSessionIdFromContext() : void 0);
1543
+ if (sessionId === void 0 && traceId === void 0) {
1531
1544
  logger.warn(
1532
- `recordMetric(${name}) called with no resolvable session id; the metric cannot be attributed to a conversation and is dropped. Pass options.sessionId or call inside a startSession/callWithSessionId scope.`
1545
+ `recordMetric(${name}) called with no resolvable session id or trace id; the metric cannot be attributed to a conversation and is dropped. Pass options.sessionId or options.traceId, or call inside a startSession/callWithSessionId scope.`
1533
1546
  );
1534
1547
  return;
1535
1548
  }
1549
+ const base = context3.active();
1550
+ const ambient = base.getValue(PROPERTIES_CONTEXT_KEY);
1551
+ const properties = { ...ambient };
1552
+ if (sessionId === void 0) {
1553
+ delete properties[SESSION_ID];
1554
+ delete properties[MESSAGE_ID];
1555
+ } else {
1556
+ properties[SESSION_ID] = sessionId;
1557
+ }
1558
+ if (options.serviceName !== void 0) {
1559
+ properties[SERVICE_NAME] = options.serviceName;
1560
+ }
1536
1561
  try {
1537
- callWithProperties(
1538
- { [SESSION_ID]: sessionId },
1562
+ context3.with(
1563
+ base.setValue(PROPERTIES_CONTEXT_KEY, properties),
1539
1564
  () => emitEvent(METRIC_EVENT_NAME, eventAttributes)
1540
1565
  );
1541
1566
  } catch (error) {
@@ -2161,7 +2186,16 @@ var LoggingModule = class _LoggingModule {
2161
2186
  createLogExporter(config, serviceName) {
2162
2187
  if (config.customLogExporter) {
2163
2188
  logger.debug("Using custom log exporter");
2164
- return config.customLogExporter;
2189
+ if (serviceName === config.appName) {
2190
+ return config.customLogExporter;
2191
+ }
2192
+ const shared = config.customLogExporter;
2193
+ return {
2194
+ export: (logs, resultCallback) => shared.export(logs, resultCallback),
2195
+ forceFlush: async () => shared.forceFlush(),
2196
+ shutdown: async () => {
2197
+ }
2198
+ };
2165
2199
  }
2166
2200
  const logsUrl = config.baseUrl.replace(/\/$/, "") + "/v1/logs";
2167
2201
  logger.debug("Initializing default OTLP log exporter", { url: logsUrl, serviceName });
@@ -2287,12 +2321,12 @@ var LoggingModule = class _LoggingModule {
2287
2321
  */
2288
2322
  async shutdown() {
2289
2323
  logger.debug("Shutting down logging module");
2324
+ await Promise.all([...this.scopedProviders.values()].map(async (p) => p.shutdown()));
2325
+ this.scopedProviders.clear();
2290
2326
  if (this.loggerProvider) {
2291
2327
  await this.loggerProvider.shutdown();
2292
2328
  this.loggerProvider = null;
2293
2329
  }
2294
- await Promise.all([...this.scopedProviders.values()].map(async (p) => p.shutdown()));
2295
- this.scopedProviders.clear();
2296
2330
  this.config = null;
2297
2331
  if (_LoggingModule.instance === this) {
2298
2332
  _LoggingModule.instance = null;
@@ -2,8 +2,8 @@ import {
2
2
  InterruptPropagator,
3
3
  _resetInterruptState,
4
4
  createInterruptIntegration
5
- } from "./chunk-APOYOP7D.js";
6
- import "./chunk-AOT5NJDV.js";
5
+ } from "./chunk-3OMB2F7B.js";
6
+ import "./chunk-FVVRWMPV.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 _chunkELLCNMLIcjs = require('./chunk-ELLCNMLI.cjs');
6
+ require('./chunk-GMZQ6N77.cjs');
7
+ require('./chunk-OBGZSXTJ.cjs');
8
+
9
+
10
+
11
+
12
+ exports.InterruptPropagator = _chunkELLCNMLIcjs.InterruptPropagator; exports._resetInterruptState = _chunkELLCNMLIcjs._resetInterruptState; exports.createInterruptIntegration = _chunkELLCNMLIcjs.createInterruptIntegration;
@@ -8,11 +8,11 @@
8
8
 
9
9
 
10
10
 
11
- var _chunkEWT4TUB7cjs = require('./chunk-EWT4TUB7.cjs');
11
+ var _chunkJDJLJ2V2cjs = require('./chunk-JDJLJ2V2.cjs');
12
12
 
13
13
 
14
14
  var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
15
- require('./chunk-5WBPX342.cjs');
15
+ require('./chunk-GMZQ6N77.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 && _chunkEWT4TUB7cjs.isSessionToolCall.call(void 0, request)) {
390
+ if (method === METHOD_TOOLS_CALL && _chunkJDJLJ2V2cjs.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 = _chunkEWT4TUB7cjs.isEnabled.call(void 0, ) && method === METHOD_TOOLS_CALL ? _chunkEWT4TUB7cjs.popTrackingArguments.call(void 0, request) : {};
397
+ const tracking = _chunkJDJLJ2V2cjs.isEnabled.call(void 0, ) && method === METHOD_TOOLS_CALL ? _chunkJDJLJ2V2cjs.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 (_chunkEWT4TUB7cjs.isEnabled.call(void 0, )) {
407
+ if (_chunkJDJLJ2V2cjs.isEnabled.call(void 0, )) {
408
408
  try {
409
- advertised = _chunkEWT4TUB7cjs.patchListToolsResult.call(void 0, result);
409
+ advertised = _chunkJDJLJ2V2cjs.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
- _chunkEWT4TUB7cjs.resolveTransportSessionId.call(void 0, this),
420
+ _chunkJDJLJ2V2cjs.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
- _chunkEWT4TUB7cjs.stampAndPropagateSession.call(void 0, span, _chunkEWT4TUB7cjs.resolveSessionId.call(void 0, this, spanCtx), spanCtx);
433
+ _chunkJDJLJ2V2cjs.stampAndPropagateSession.call(void 0, span, _chunkJDJLJ2V2cjs.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 } = _chunkEWT4TUB7cjs.sessionToolResult.call(void 0, );
467
+ const { id, result } = _chunkJDJLJ2V2cjs.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, () => ( _chunkEWT4TUB7cjs.resolveSessionId.call(void 0, protocol, parentCtx))) : void 0;
558
- const { context: sessCtx } = _chunkEWT4TUB7cjs.stampAndPropagateSession.call(void 0,
557
+ const resolved = request.method === METHOD_TOOLS_CALL ? _nullishCoalesce(tracking.sessionId, () => ( _chunkJDJLJ2V2cjs.resolveSessionId.call(void 0, protocol, parentCtx))) : void 0;
558
+ const { context: sessCtx } = _chunkJDJLJ2V2cjs.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 = _chunkEWT4TUB7cjs.getSDKVersion.call(void 0, );
614
+ var INSTRUMENTATION_VERSION = _chunkJDJLJ2V2cjs.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-V727EJE5.js";
11
+ } from "./chunk-L4P4RJT5.js";
12
12
  import {
13
13
  logger
14
14
  } from "./chunk-Y4HNUX3Q.js";
15
- import "./chunk-AOT5NJDV.js";
15
+ import "./chunk-FVVRWMPV.js";
16
16
  import "./chunk-3RG5ZIWI.js";
17
17
 
18
18
  // src/internal/instrumentation/mcp/instrumentation.ts
@@ -53,6 +53,7 @@ export declare const METRIC_POLARITY = "brizz.internal.metric.polarity";
53
53
  export declare const METRIC_MIN = "brizz.internal.metric.min";
54
54
  export declare const METRIC_MAX = "brizz.internal.metric.max";
55
55
  export declare const METRIC_TIMESTAMP = "brizz.internal.metric.timestamp";
56
+ export declare const METRIC_TRACE_ID = "brizz.internal.metric.trace_id";
56
57
  export declare const METRIC_ATTRIBUTE_PREFIX = "brizz.internal.metric.attribute.";
57
58
  export declare const RESERVED_METRIC_NAMES: Set<string>;
58
59
  export declare const METRIC_POLARITY_POSITIVE = "positive";
@@ -132,6 +132,8 @@ export declare function recordMetric(options: {
132
132
  maxValue?: number;
133
133
  timestamp?: Date;
134
134
  sessionId?: string;
135
+ traceId?: string;
136
+ serviceName?: string;
135
137
  }): void;
136
138
  export declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>, options?: {
137
139
  mode?: 'default' | 'title';
@@ -53,6 +53,7 @@ export declare const METRIC_POLARITY = "brizz.internal.metric.polarity";
53
53
  export declare const METRIC_MIN = "brizz.internal.metric.min";
54
54
  export declare const METRIC_MAX = "brizz.internal.metric.max";
55
55
  export declare const METRIC_TIMESTAMP = "brizz.internal.metric.timestamp";
56
+ export declare const METRIC_TRACE_ID = "brizz.internal.metric.trace_id";
56
57
  export declare const METRIC_ATTRIBUTE_PREFIX = "brizz.internal.metric.attribute.";
57
58
  export declare const RESERVED_METRIC_NAMES: Set<string>;
58
59
  export declare const METRIC_POLARITY_POSITIVE = "positive";
@@ -132,6 +132,8 @@ export declare function recordMetric(options: {
132
132
  maxValue?: number;
133
133
  timestamp?: Date;
134
134
  sessionId?: string;
135
+ traceId?: string;
136
+ serviceName?: string;
135
137
  }): void;
136
138
  export declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>, options?: {
137
139
  mode?: 'default' | 'title';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brizz/sdk",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "type": "module",
5
5
  "description": "OpenTelemetry-based observability SDK for AI applications",
6
6
  "keywords": [
@@ -1,12 +0,0 @@
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;