@brizz/sdk 0.1.7 → 0.1.9

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
@@ -5,6 +5,7 @@ import { LogBody, SeverityNumber } from '@opentelemetry/api-logs';
5
5
  export { SeverityNumber } from '@opentelemetry/api-logs';
6
6
  import { SpanProcessor } from '@opentelemetry/sdk-trace-node';
7
7
  import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
8
+ import { Span, AttributeValue } from '@opentelemetry/api';
8
9
 
9
10
  interface IInstrumentModules {
10
11
  openAI?: unknown;
@@ -15,9 +16,7 @@ interface IInstrumentModules {
15
16
  bedrock?: unknown;
16
17
  pinecone?: unknown;
17
18
  langchain?: {
18
- chains?: unknown;
19
- agents?: unknown;
20
- tools?: unknown;
19
+ callbackManagerModule?: unknown;
21
20
  };
22
21
  llamaindex?: unknown;
23
22
  chromadb?: unknown;
@@ -125,6 +124,17 @@ declare function withProperties<F extends (this: any, ...args: any[]) => any>(pr
125
124
  }, fn: F, thisArg?: ThisParameterType<F>): F;
126
125
  declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>): F;
127
126
  declare function callWithSessionId<A extends unknown[], F extends (...args: A) => ReturnType<F>>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
127
+ declare class Session {
128
+ readonly sessionId: string;
129
+ private readonly span;
130
+ private inputs;
131
+ private outputs;
132
+ constructor(sessionId: string, span: Span);
133
+ setInput(text: string): void;
134
+ setOutput(text: string): void;
135
+ updateProperties(properties: Record<string, AttributeValue>): void;
136
+ }
137
+ declare function startSession<T>(sessionId: string, callback: (session: Session) => T): T;
128
138
 
129
139
  declare function getMetricsExporter(): OTLPMetricExporter;
130
140
  declare function getMetricsReader(): MetricReader;
@@ -142,4 +152,4 @@ declare namespace init {
142
152
  export { };
143
153
  }
144
154
 
145
- 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, callWithProperties, callWithSessionId, detectRuntime, emitEvent, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, withProperties, withSessionId };
155
+ 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, Session, callWithProperties, callWithSessionId, detectRuntime, emitEvent, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, startSession, withProperties, withSessionId };
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ import { LogBody, SeverityNumber } from '@opentelemetry/api-logs';
5
5
  export { SeverityNumber } from '@opentelemetry/api-logs';
6
6
  import { SpanProcessor } from '@opentelemetry/sdk-trace-node';
7
7
  import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
8
+ import { Span, AttributeValue } from '@opentelemetry/api';
8
9
 
9
10
  interface IInstrumentModules {
10
11
  openAI?: unknown;
@@ -15,9 +16,7 @@ interface IInstrumentModules {
15
16
  bedrock?: unknown;
16
17
  pinecone?: unknown;
17
18
  langchain?: {
18
- chains?: unknown;
19
- agents?: unknown;
20
- tools?: unknown;
19
+ callbackManagerModule?: unknown;
21
20
  };
22
21
  llamaindex?: unknown;
23
22
  chromadb?: unknown;
@@ -125,6 +124,17 @@ declare function withProperties<F extends (this: any, ...args: any[]) => any>(pr
125
124
  }, fn: F, thisArg?: ThisParameterType<F>): F;
126
125
  declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>): F;
127
126
  declare function callWithSessionId<A extends unknown[], F extends (...args: A) => ReturnType<F>>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
127
+ declare class Session {
128
+ readonly sessionId: string;
129
+ private readonly span;
130
+ private inputs;
131
+ private outputs;
132
+ constructor(sessionId: string, span: Span);
133
+ setInput(text: string): void;
134
+ setOutput(text: string): void;
135
+ updateProperties(properties: Record<string, AttributeValue>): void;
136
+ }
137
+ declare function startSession<T>(sessionId: string, callback: (session: Session) => T): T;
128
138
 
129
139
  declare function getMetricsExporter(): OTLPMetricExporter;
130
140
  declare function getMetricsReader(): MetricReader;
@@ -142,4 +152,4 @@ declare namespace init {
142
152
  export { };
143
153
  }
144
154
 
145
- 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, callWithProperties, callWithSessionId, detectRuntime, emitEvent, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, withProperties, withSessionId };
155
+ 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, Session, callWithProperties, callWithSessionId, detectRuntime, emitEvent, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, startSession, withProperties, withSessionId };
package/dist/index.js CHANGED
@@ -434,7 +434,7 @@ import {
434
434
 
435
435
  // src/internal/version.ts
436
436
  function getSDKVersion() {
437
- return "0.1.7";
437
+ return "0.1.9";
438
438
  }
439
439
 
440
440
  // src/internal/log/processors/log-processor.ts
@@ -1069,6 +1069,9 @@ var BRIZZ = "brizz";
1069
1069
  var PROPERTIES = "properties";
1070
1070
  var SESSION_ID = "session.id";
1071
1071
  var PROPERTIES_CONTEXT_KEY = createContextKey(PROPERTIES);
1072
+ var SESSION_INPUT = "brizz.session.input";
1073
+ var SESSION_OUTPUT = "brizz.session.output";
1074
+ var SESSION_SPAN_NAME = "brizz.start_session";
1072
1075
 
1073
1076
  // src/internal/log/processors/log-processor.ts
1074
1077
  var DEFAULT_LOG_MASKING_RULES = [
@@ -1628,7 +1631,7 @@ function getSpanProcessor() {
1628
1631
  }
1629
1632
 
1630
1633
  // src/internal/trace/session.ts
1631
- import { context as context3 } from "@opentelemetry/api";
1634
+ import { context as context3, trace, SpanStatusCode } from "@opentelemetry/api";
1632
1635
  function callWithProperties(properties, fn, thisArg, ...args) {
1633
1636
  const base = context3.active();
1634
1637
  const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
@@ -1652,6 +1655,79 @@ function withSessionId(sessionId, fn, thisArg) {
1652
1655
  function callWithSessionId(sessionId, fn, thisArg, ...args) {
1653
1656
  return callWithProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
1654
1657
  }
1658
+ var Session = class {
1659
+ sessionId;
1660
+ span;
1661
+ inputs = [];
1662
+ outputs = [];
1663
+ constructor(sessionId, span) {
1664
+ this.sessionId = sessionId;
1665
+ this.span = span;
1666
+ }
1667
+ /**
1668
+ * (Optional) Append text to session input tracking.
1669
+ * Use when you need to track specific input data that differs from what's sent to the LLM.
1670
+ * Multiple calls accumulate in an array.
1671
+ *
1672
+ * @param text - Text to append to session input
1673
+ */
1674
+ setInput(text) {
1675
+ this.inputs.push(text);
1676
+ this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
1677
+ }
1678
+ /**
1679
+ * (Optional) Append text to session output tracking.
1680
+ * Use when you need to track specific output data that differs from what's received from the LLM.
1681
+ * Multiple calls accumulate in an array.
1682
+ *
1683
+ * @param text - Text to append to session output
1684
+ */
1685
+ setOutput(text) {
1686
+ this.outputs.push(text);
1687
+ this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
1688
+ }
1689
+ /**
1690
+ * Update custom properties on the session span.
1691
+ * Properties are prefixed with 'brizz.'.
1692
+ *
1693
+ * @param properties - Key-value properties to set on the session
1694
+ */
1695
+ updateProperties(properties) {
1696
+ for (const [key, value] of Object.entries(properties)) {
1697
+ this.span.setAttribute(`${BRIZZ}.${key}`, value);
1698
+ }
1699
+ }
1700
+ };
1701
+ function startSession(sessionId, callback) {
1702
+ const tracer = trace.getTracer("@brizz/sdk");
1703
+ return tracer.startActiveSpan(SESSION_SPAN_NAME, (span) => {
1704
+ span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
1705
+ const session = new Session(sessionId, span);
1706
+ return callWithProperties({ [SESSION_ID]: sessionId }, () => {
1707
+ try {
1708
+ const result = callback(session);
1709
+ if (result && typeof result.then === "function") {
1710
+ return result.then((value) => {
1711
+ span.end();
1712
+ return value;
1713
+ }).catch((error) => {
1714
+ span.recordException(error);
1715
+ span.setStatus({ code: SpanStatusCode.ERROR });
1716
+ span.end();
1717
+ throw error;
1718
+ });
1719
+ }
1720
+ span.end();
1721
+ return result;
1722
+ } catch (error) {
1723
+ span.recordException(error);
1724
+ span.setStatus({ code: SpanStatusCode.ERROR });
1725
+ span.end();
1726
+ throw error;
1727
+ }
1728
+ });
1729
+ });
1730
+ }
1655
1731
 
1656
1732
  // src/internal/sdk.ts
1657
1733
  var _Brizz = class __Brizz {
@@ -1901,6 +1977,7 @@ export {
1901
1977
  Brizz,
1902
1978
  DEFAULT_PII_PATTERNS,
1903
1979
  LogLevel,
1980
+ Session,
1904
1981
  SeverityNumber2 as SeverityNumber,
1905
1982
  callWithProperties,
1906
1983
  callWithSessionId,
@@ -1916,6 +1993,7 @@ export {
1916
1993
  maskAttributes,
1917
1994
  maskValue,
1918
1995
  setLogLevel,
1996
+ startSession,
1919
1997
  withProperties,
1920
1998
  withSessionId
1921
1999
  };