@brizz/sdk 0.1.3-rc.1 → 0.1.4

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.d.cts CHANGED
@@ -116,7 +116,8 @@ declare function emitEvent(name: string, attributes?: Record<string, string | nu
116
116
  declare function getSpanExporter(): SpanExporter;
117
117
  declare function getSpanProcessor(): SpanProcessor;
118
118
 
119
- declare function WithSessionId<A extends unknown[], F extends (...args: A) => ReturnType<F>>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
119
+ declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>): F;
120
+ declare function callWithSessionId<A extends unknown[], F extends (...args: A) => ReturnType<F>>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
120
121
 
121
122
  declare function getMetricsExporter(): OTLPMetricExporter;
122
123
  declare function getMetricsReader(): MetricReader;
@@ -134,4 +135,4 @@ declare namespace init {
134
135
  export { };
135
136
  }
136
137
 
137
- export { Brizz, DEFAULT_PII_PATTERNS, type IAttributesMaskingRule, type IBrizzInitializeOptions, type IEventMaskingConfig, type IEventMaskingRule, type IInstrumentModules, type ILogMaskingConfig, type ILogger, type IMaskingConfig, type ISpanMaskingConfig, LogLevel, type MaskingMode, type RuntimeInfo, WithSessionId, detectRuntime, emitEvent, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel };
138
+ export { Brizz, DEFAULT_PII_PATTERNS, type IAttributesMaskingRule, type IBrizzInitializeOptions, type IEventMaskingConfig, type IEventMaskingRule, type IInstrumentModules, type ILogMaskingConfig, type ILogger, type IMaskingConfig, type ISpanMaskingConfig, LogLevel, type MaskingMode, type RuntimeInfo, callWithSessionId, detectRuntime, emitEvent, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, withSessionId };
package/dist/index.d.ts CHANGED
@@ -116,7 +116,8 @@ declare function emitEvent(name: string, attributes?: Record<string, string | nu
116
116
  declare function getSpanExporter(): SpanExporter;
117
117
  declare function getSpanProcessor(): SpanProcessor;
118
118
 
119
- declare function WithSessionId<A extends unknown[], F extends (...args: A) => ReturnType<F>>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
119
+ declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>): F;
120
+ declare function callWithSessionId<A extends unknown[], F extends (...args: A) => ReturnType<F>>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
120
121
 
121
122
  declare function getMetricsExporter(): OTLPMetricExporter;
122
123
  declare function getMetricsReader(): MetricReader;
@@ -134,4 +135,4 @@ declare namespace init {
134
135
  export { };
135
136
  }
136
137
 
137
- export { Brizz, DEFAULT_PII_PATTERNS, type IAttributesMaskingRule, type IBrizzInitializeOptions, type IEventMaskingConfig, type IEventMaskingRule, type IInstrumentModules, type ILogMaskingConfig, type ILogger, type IMaskingConfig, type ISpanMaskingConfig, LogLevel, type MaskingMode, type RuntimeInfo, WithSessionId, detectRuntime, emitEvent, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel };
138
+ export { Brizz, DEFAULT_PII_PATTERNS, type IAttributesMaskingRule, type IBrizzInitializeOptions, type IEventMaskingConfig, type IEventMaskingRule, type IInstrumentModules, type ILogMaskingConfig, type ILogger, type IMaskingConfig, type ISpanMaskingConfig, LogLevel, type MaskingMode, type RuntimeInfo, callWithSessionId, detectRuntime, emitEvent, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, withSessionId };
package/dist/index.js CHANGED
@@ -1429,7 +1429,7 @@ var HANDLED_SPAN_NAMES = {
1429
1429
  "ai.streamText": "ai.streamText",
1430
1430
  "ai.toolCall": (span) => {
1431
1431
  const toolName = span.attributes["ai.toolCall.name"];
1432
- return `${toolName}.tool`;
1432
+ return `${String(toolName ?? "unknown")}.tool`;
1433
1433
  }
1434
1434
  };
1435
1435
  var AI_RESPONSE_TEXT = "ai.response.text";
@@ -1439,10 +1439,11 @@ var AI_USAGE_COMPLETION_TOKENS = "ai.usage.completionTokens";
1439
1439
  var AI_MODEL_PROVIDER = "ai.model.provider";
1440
1440
  var transformAiSdkSpanName = (span) => {
1441
1441
  if (span.name in HANDLED_SPAN_NAMES) {
1442
- if (typeof HANDLED_SPAN_NAMES[span.name] === "function") {
1443
- span.name = HANDLED_SPAN_NAMES[span.name](span);
1444
- } else {
1445
- span.name = HANDLED_SPAN_NAMES[span.name];
1442
+ const handler = HANDLED_SPAN_NAMES[span.name];
1443
+ if (typeof handler === "function") {
1444
+ span.name = handler(span);
1445
+ } else if (handler) {
1446
+ span.name = handler;
1446
1447
  }
1447
1448
  }
1448
1449
  };
@@ -1457,26 +1458,30 @@ var transformPromptMessages = (attributes) => {
1457
1458
  if (AI_PROMPT_MESSAGES in attributes) {
1458
1459
  try {
1459
1460
  const messages = JSON.parse(attributes[AI_PROMPT_MESSAGES]);
1460
- messages.forEach((msg, index) => {
1461
- logger.debug("Transforming prompt message", { msg, type: typeof msg.content });
1462
- if (typeof msg.content === "string") {
1463
- attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.content`] = msg.content;
1461
+ for (const [index, msg] of messages.entries()) {
1462
+ const message = msg;
1463
+ logger.debug("Transforming prompt message", { msg: message, type: typeof message.content });
1464
+ if (typeof message.content === "string") {
1465
+ attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.content`] = message.content;
1464
1466
  } else {
1465
- if (Array.isArray(msg.content) && msg.content.length > 0) {
1466
- const lastContent = msg.content[msg.content.length - 1];
1467
- if (lastContent.text) {
1467
+ if (Array.isArray(message.content) && message.content.length > 0) {
1468
+ const lastContent = message.content.at(-1);
1469
+ if (lastContent?.text) {
1468
1470
  attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.content`] = lastContent.text;
1469
1471
  }
1470
1472
  } else {
1471
1473
  attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.content`] = JSON.stringify(
1472
- msg.content
1474
+ message.content
1473
1475
  );
1474
1476
  }
1475
1477
  }
1476
- attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.role`] = msg.role;
1477
- });
1478
+ attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.role`] = message.role;
1479
+ }
1478
1480
  delete attributes[AI_PROMPT_MESSAGES];
1479
- } catch {
1481
+ } catch (error) {
1482
+ logger.debug("Skipping prompt messages transformation because of JSON parsing error", {
1483
+ e: error
1484
+ });
1480
1485
  }
1481
1486
  }
1482
1487
  };
@@ -1502,11 +1507,7 @@ var calculateTotalTokens = (attributes) => {
1502
1507
  var transformVendor = (attributes) => {
1503
1508
  if (AI_MODEL_PROVIDER in attributes) {
1504
1509
  const vendor = attributes[AI_MODEL_PROVIDER];
1505
- if (vendor && vendor.startsWith("openai")) {
1506
- attributes[SpanAttributes.LLM_SYSTEM] = "OpenAI";
1507
- } else {
1508
- attributes[SpanAttributes.LLM_SYSTEM] = vendor;
1509
- }
1510
+ attributes[SpanAttributes.LLM_SYSTEM] = vendor && vendor.startsWith("openai") ? "OpenAI" : vendor;
1510
1511
  delete attributes[AI_MODEL_PROVIDER];
1511
1512
  }
1512
1513
  };
@@ -1522,6 +1523,10 @@ var shouldHandleSpan = (span) => {
1522
1523
  return span.name in HANDLED_SPAN_NAMES;
1523
1524
  };
1524
1525
  var transformAiSdkSpan = (span) => {
1526
+ if (!shouldHandleSpan(span)) {
1527
+ logger.debug("Skipping span transformation", { spanName: span.name });
1528
+ return;
1529
+ }
1525
1530
  for (const key in span.attributes) {
1526
1531
  if (Number.isNaN(span.attributes[key])) {
1527
1532
  span.attributes[key] = 0;
@@ -1532,10 +1537,6 @@ var transformAiSdkSpan = (span) => {
1532
1537
  spanContext: span.spanContext(),
1533
1538
  attributes: span.attributes
1534
1539
  });
1535
- if (!shouldHandleSpan(span)) {
1536
- logger.debug("Skipping span transformation", { spanName: span.name });
1537
- return;
1538
- }
1539
1540
  transformAiSdkSpanName(span);
1540
1541
  transformAiSdkAttributes(span.attributes);
1541
1542
  };
@@ -1750,7 +1751,15 @@ function withProperties(properties, fn, thisArg, ...args) {
1750
1751
  const newContext = context3.active().setValue(PROPERTIES_CONTEXT_KEY, properties);
1751
1752
  return context3.with(newContext, fn, thisArg, ...args);
1752
1753
  }
1753
- function WithSessionId(sessionId, fn, thisArg, ...args) {
1754
+ function withSessionId(sessionId, fn, thisArg) {
1755
+ return function wrapped(...args) {
1756
+ const base = context3.active();
1757
+ const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
1758
+ const next = base.setValue(PROPERTIES_CONTEXT_KEY, prev ? { ...prev, [SESSION_ID]: sessionId } : { [SESSION_ID]: sessionId });
1759
+ return context3.with(next, fn, thisArg ?? this, ...args);
1760
+ };
1761
+ }
1762
+ function callWithSessionId(sessionId, fn, thisArg, ...args) {
1754
1763
  return withProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
1755
1764
  }
1756
1765
 
@@ -1993,7 +2002,7 @@ export {
1993
2002
  DEFAULT_PII_PATTERNS,
1994
2003
  LogLevel,
1995
2004
  SeverityNumber2 as SeverityNumber,
1996
- WithSessionId,
2005
+ callWithSessionId,
1997
2006
  detectRuntime,
1998
2007
  emitEvent,
1999
2008
  getLogLevel,
@@ -2005,6 +2014,7 @@ export {
2005
2014
  logger,
2006
2015
  maskAttributes,
2007
2016
  maskValue,
2008
- setLogLevel
2017
+ setLogLevel,
2018
+ withSessionId
2009
2019
  };
2010
2020
  //# sourceMappingURL=index.js.map