@brizz/sdk 0.1.49 → 0.1.51

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-HTFR2LKY.js";
8
+ } from "./chunk-G6GTIFEQ.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-3OMB2F7B.js";
19
+ } from "./chunk-7PRTTYWM.js";
20
20
  import {
21
21
  AGENT_ID,
22
22
  AGENT_NAME,
@@ -44,6 +44,9 @@ import {
44
44
  METRIC_POLARITY,
45
45
  METRIC_POLARITY_NEGATIVE,
46
46
  METRIC_POLARITY_POSITIVE,
47
+ METRIC_SCOPE,
48
+ METRIC_SCOPE_SESSION,
49
+ METRIC_SCOPE_TRACE,
47
50
  METRIC_TIMESTAMP,
48
51
  METRIC_TRACE_ID,
49
52
  METRIC_UNIT,
@@ -74,7 +77,7 @@ import {
74
77
  USER_NAME,
75
78
  USER_PLAN,
76
79
  USER_ROLE
77
- } from "./chunk-FVVRWMPV.js";
80
+ } from "./chunk-GUKWVI53.js";
78
81
  import {
79
82
  __require
80
83
  } from "./chunk-3RG5ZIWI.js";
@@ -465,7 +468,7 @@ function loadGenAIInstrumentations() {
465
468
  function loadMCPInstrumentation() {
466
469
  void (async () => {
467
470
  try {
468
- const { MCPInstrumentation } = await import("./mcp-LIAXZGBN.js");
471
+ const { MCPInstrumentation } = await import("./mcp-2ZFV5BK5.js");
469
472
  const mcp = new MCPInstrumentation({ exceptionLogger });
470
473
  registerInstrumentations({ instrumentations: [mcp] });
471
474
  logger.debug("Auto-loaded MCP instrumentation");
@@ -529,7 +532,7 @@ function loadVercelAITelemetry() {
529
532
  }
530
533
  const isV7 = typeof ai.registerTelemetry === "function";
531
534
  const integrations = [];
532
- const { createInterruptIntegration } = await import("./interrupt-YO3ID433.js");
535
+ const { createInterruptIntegration } = await import("./interrupt-UKJK5WOA.js");
533
536
  integrations.push(createInterruptIntegration());
534
537
  let otelCollectorLoaded = false;
535
538
  try {
@@ -961,7 +964,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
961
964
  const mcpModules = this.manualModules.mcp;
962
965
  void (async () => {
963
966
  try {
964
- const { MCPInstrumentation } = await import("./mcp-LIAXZGBN.js");
967
+ const { MCPInstrumentation } = await import("./mcp-2ZFV5BK5.js");
965
968
  const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
966
969
  instrumentation.manuallyInstrument(mcpModules);
967
970
  logger.debug("Manual instrumentation enabled for MCP");
@@ -1004,7 +1007,7 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
1004
1007
  import { LoggerProvider } from "@opentelemetry/sdk-logs";
1005
1008
 
1006
1009
  // src/internal/trace/session.ts
1007
- import { context as context3, trace as trace2, SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
1010
+ import { context as context3, isSpanContextValid, trace as trace2, SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
1008
1011
  function setCurrentSpanCustomProperties(properties) {
1009
1012
  const current = trace2.getActiveSpan();
1010
1013
  if (!current || !current.isRecording()) {
@@ -1512,10 +1515,20 @@ function recordMetricImpl(options) {
1512
1515
  return;
1513
1516
  }
1514
1517
  }
1518
+ const scope = options.scope ?? METRIC_SCOPE_SESSION;
1519
+ if (scope !== METRIC_SCOPE_SESSION && scope !== METRIC_SCOPE_TRACE) {
1520
+ logger.warn(
1521
+ `recordMetric(${name}) called with an invalid scope ${JSON.stringify(scope)}; expected '${METRIC_SCOPE_SESSION}' or '${METRIC_SCOPE_TRACE}'. Metric dropped.`
1522
+ );
1523
+ return;
1524
+ }
1515
1525
  const eventAttributes = {
1516
1526
  [METRIC_NAME]: name,
1517
1527
  [METRIC_VALUE]: numericValue
1518
1528
  };
1529
+ if (options.scope !== void 0) {
1530
+ eventAttributes[METRIC_SCOPE] = scope;
1531
+ }
1519
1532
  if (options.unit !== void 0) {
1520
1533
  eventAttributes[METRIC_UNIT] = options.unit;
1521
1534
  }
@@ -1585,6 +1598,16 @@ function recordMetricImpl(options) {
1585
1598
  if (traceId !== void 0) {
1586
1599
  eventAttributes[METRIC_TRACE_ID] = traceId;
1587
1600
  }
1601
+ if (scope === METRIC_SCOPE_TRACE && traceId === void 0) {
1602
+ const spanContext = trace2.getActiveSpan()?.spanContext();
1603
+ if (!spanContext || !isSpanContextValid(spanContext)) {
1604
+ logger.warn(
1605
+ `recordMetric(${name}) called with scope 'trace' but no trace; metric dropped. Pass options.traceId, or call inside the span of the trace being scored.`
1606
+ );
1607
+ return;
1608
+ }
1609
+ eventAttributes[METRIC_TRACE_ID] = spanContext.traceId;
1610
+ }
1588
1611
  const sessionId = options.sessionId ?? (traceId === void 0 ? resolveSessionIdFromContext() : void 0);
1589
1612
  if (sessionId === void 0 && traceId === void 0) {
1590
1613
  logger.warn(
@@ -2659,9 +2682,27 @@ function applyContextAttributes(span) {
2659
2682
  }
2660
2683
  }
2661
2684
  }
2685
+ var LIBRARY_ID_ATTRIBUTES = [
2686
+ "mcp.request.id",
2687
+ "mcp.session.id",
2688
+ "jsonrpc.request.id",
2689
+ "gen_ai.response.id",
2690
+ "ai.response.id",
2691
+ // Session-id aliases the streamer copies into brizz.session.id (sessionIDAliases).
2692
+ "session.id",
2693
+ "langfuse.trace.metadata.session.id",
2694
+ "langfuse.trace.metadata.brizz.session.id",
2695
+ "langsmith.metadata.thread_id",
2696
+ "langsmith.metadata.session_id",
2697
+ "langsmith.metadata.conversation_id",
2698
+ "langsmith.trace.session_id"
2699
+ ];
2700
+ var DEFAULT_RULE_ATTRIBUTES = String.raw`^(?!brizz\.(?!session\.(?:input|output)(?:\.context)?$|session\.title$|internal\.intent$)` + `|(?:${LIBRARY_ID_ATTRIBUTES.map((key) => key.replaceAll(".", String.raw`\.`)).join("|")})$)`;
2701
+ var isText = (value) => typeof value === "string" || Array.isArray(value) && value.some((item) => typeof item === "string");
2662
2702
  var DEFAULT_MASKING_RULES = [
2663
2703
  {
2664
2704
  mode: "partial",
2705
+ attributePattern: DEFAULT_RULE_ATTRIBUTES,
2665
2706
  patterns: DEFAULT_PII_PATTERNS
2666
2707
  }
2667
2708
  ];
@@ -2708,17 +2749,19 @@ function maskReadableSpan(span, config) {
2708
2749
  if (!attrs || Object.keys(attrs).length === 0) {
2709
2750
  return;
2710
2751
  }
2711
- let rules = config.rules ? [...config.rules] : [];
2712
- if (!config.disableDefaultRules) {
2713
- rules = [...rules, ...DEFAULT_MASKING_RULES];
2714
- }
2715
2752
  try {
2716
- const input = {};
2753
+ let masked = {};
2717
2754
  for (const [k, v] of Object.entries(attrs)) {
2718
- input[k] = v;
2755
+ masked[k] = v;
2756
+ }
2757
+ if (config.rules?.length) {
2758
+ masked = maskAttributes(masked, config.rules);
2759
+ }
2760
+ if (!config.disableDefaultRules) {
2761
+ const text = Object.fromEntries(Object.entries(masked).filter(([k]) => isText(attrs[k])));
2762
+ Object.assign(masked, maskAttributes(text, DEFAULT_MASKING_RULES));
2719
2763
  }
2720
- const masked = maskAttributes(input, rules);
2721
- const maskedEntries = Object.entries(masked ?? {});
2764
+ const maskedEntries = Object.entries(masked);
2722
2765
  for (const [k, v] of maskedEntries) {
2723
2766
  if (attrs[k] !== v) {
2724
2767
  attrs[k] = v;
@@ -0,0 +1,12 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkO2IBZJOJcjs = require('./chunk-O2IBZJOJ.cjs');
6
+ require('./chunk-RV7JIIDG.cjs');
7
+ require('./chunk-OBGZSXTJ.cjs');
8
+
9
+
10
+
11
+
12
+ exports.InterruptPropagator = _chunkO2IBZJOJcjs.InterruptPropagator; exports._resetInterruptState = _chunkO2IBZJOJcjs._resetInterruptState; exports.createInterruptIntegration = _chunkO2IBZJOJcjs.createInterruptIntegration;
@@ -2,8 +2,8 @@ import {
2
2
  InterruptPropagator,
3
3
  _resetInterruptState,
4
4
  createInterruptIntegration
5
- } from "./chunk-3OMB2F7B.js";
6
- import "./chunk-FVVRWMPV.js";
5
+ } from "./chunk-7PRTTYWM.js";
6
+ import "./chunk-GUKWVI53.js";
7
7
  import "./chunk-3RG5ZIWI.js";
8
8
  export {
9
9
  InterruptPropagator,
@@ -8,11 +8,11 @@ import {
8
8
  resolveTransportSessionId,
9
9
  sessionToolResult,
10
10
  stampAndPropagateSession
11
- } from "./chunk-HTFR2LKY.js";
11
+ } from "./chunk-G6GTIFEQ.js";
12
12
  import {
13
13
  logger
14
14
  } from "./chunk-Y4HNUX3Q.js";
15
- import "./chunk-FVVRWMPV.js";
15
+ import "./chunk-GUKWVI53.js";
16
16
  import "./chunk-3RG5ZIWI.js";
17
17
 
18
18
  // src/internal/instrumentation/mcp/instrumentation.ts
@@ -8,11 +8,11 @@
8
8
 
9
9
 
10
10
 
11
- var _chunkVAUO47L3cjs = require('./chunk-VAUO47L3.cjs');
11
+ var _chunkJSTTHMQ3cjs = require('./chunk-JSTTHMQ3.cjs');
12
12
 
13
13
 
14
14
  var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
15
- require('./chunk-GMZQ6N77.cjs');
15
+ require('./chunk-RV7JIIDG.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 && _chunkVAUO47L3cjs.isSessionToolCall.call(void 0, request)) {
390
+ if (method === METHOD_TOOLS_CALL && _chunkJSTTHMQ3cjs.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 = _chunkVAUO47L3cjs.isEnabled.call(void 0, ) && method === METHOD_TOOLS_CALL ? _chunkVAUO47L3cjs.popTrackingArguments.call(void 0, request) : {};
397
+ const tracking = _chunkJSTTHMQ3cjs.isEnabled.call(void 0, ) && method === METHOD_TOOLS_CALL ? _chunkJSTTHMQ3cjs.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 (_chunkVAUO47L3cjs.isEnabled.call(void 0, )) {
407
+ if (_chunkJSTTHMQ3cjs.isEnabled.call(void 0, )) {
408
408
  try {
409
- advertised = _chunkVAUO47L3cjs.patchListToolsResult.call(void 0, result);
409
+ advertised = _chunkJSTTHMQ3cjs.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
- _chunkVAUO47L3cjs.resolveTransportSessionId.call(void 0, this),
420
+ _chunkJSTTHMQ3cjs.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
- _chunkVAUO47L3cjs.stampAndPropagateSession.call(void 0, span, _chunkVAUO47L3cjs.resolveSessionId.call(void 0, this, spanCtx), spanCtx);
433
+ _chunkJSTTHMQ3cjs.stampAndPropagateSession.call(void 0, span, _chunkJSTTHMQ3cjs.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 } = _chunkVAUO47L3cjs.sessionToolResult.call(void 0, );
467
+ const { id, result } = _chunkJSTTHMQ3cjs.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, () => ( _chunkVAUO47L3cjs.resolveSessionId.call(void 0, protocol, parentCtx))) : void 0;
558
- const { context: sessCtx } = _chunkVAUO47L3cjs.stampAndPropagateSession.call(void 0,
557
+ const resolved = request.method === METHOD_TOOLS_CALL ? _nullishCoalesce(tracking.sessionId, () => ( _chunkJSTTHMQ3cjs.resolveSessionId.call(void 0, protocol, parentCtx))) : void 0;
558
+ const { context: sessCtx } = _chunkJSTTHMQ3cjs.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 = _chunkVAUO47L3cjs.getSDKVersion.call(void 0, );
614
+ var INSTRUMENTATION_VERSION = _chunkJSTTHMQ3cjs.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";
@@ -54,7 +54,10 @@ 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
56
  export declare const METRIC_TRACE_ID = "brizz.internal.metric.trace_id";
57
+ export declare const METRIC_SCOPE = "brizz.internal.metric.scope";
57
58
  export declare const METRIC_ATTRIBUTE_PREFIX = "brizz.internal.metric.attribute.";
58
59
  export declare const RESERVED_METRIC_NAMES: Set<string>;
59
60
  export declare const METRIC_POLARITY_POSITIVE = "positive";
60
61
  export declare const METRIC_POLARITY_NEGATIVE = "negative";
62
+ export declare const METRIC_SCOPE_SESSION = "session";
63
+ export declare const METRIC_SCOPE_TRACE = "trace";
@@ -134,6 +134,7 @@ export declare function recordMetric(options: {
134
134
  sessionId?: string;
135
135
  traceId?: string;
136
136
  serviceName?: string;
137
+ scope?: 'session' | 'trace';
137
138
  }): void;
138
139
  export declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>, options?: {
139
140
  mode?: 'default' | 'title';
@@ -54,7 +54,10 @@ 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
56
  export declare const METRIC_TRACE_ID = "brizz.internal.metric.trace_id";
57
+ export declare const METRIC_SCOPE = "brizz.internal.metric.scope";
57
58
  export declare const METRIC_ATTRIBUTE_PREFIX = "brizz.internal.metric.attribute.";
58
59
  export declare const RESERVED_METRIC_NAMES: Set<string>;
59
60
  export declare const METRIC_POLARITY_POSITIVE = "positive";
60
61
  export declare const METRIC_POLARITY_NEGATIVE = "negative";
62
+ export declare const METRIC_SCOPE_SESSION = "session";
63
+ export declare const METRIC_SCOPE_TRACE = "trace";
@@ -134,6 +134,7 @@ export declare function recordMetric(options: {
134
134
  sessionId?: string;
135
135
  traceId?: string;
136
136
  serviceName?: string;
137
+ scope?: 'session' | 'trace';
137
138
  }): void;
138
139
  export declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>, options?: {
139
140
  mode?: 'default' | 'title';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brizz/sdk",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
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 _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;