@brizz/sdk 0.1.8 → 0.1.10

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;
@@ -121,8 +122,19 @@ declare function callWithProperties<A extends unknown[], F extends (...args: A)
121
122
  declare function withProperties<F extends (this: any, ...args: any[]) => any>(properties: {
122
123
  [name: string]: string;
123
124
  }, fn: F, thisArg?: ThisParameterType<F>): F;
124
- declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>): F;
125
+ declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, extraProperties?: Record<string, string>): F;
125
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, extraProperties?: Record<string, AttributeValue>): T;
126
138
 
127
139
  declare function getMetricsExporter(): OTLPMetricExporter;
128
140
  declare function getMetricsReader(): MetricReader;
@@ -140,4 +152,4 @@ declare namespace init {
140
152
  export { };
141
153
  }
142
154
 
143
- 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;
@@ -121,8 +122,19 @@ declare function callWithProperties<A extends unknown[], F extends (...args: A)
121
122
  declare function withProperties<F extends (this: any, ...args: any[]) => any>(properties: {
122
123
  [name: string]: string;
123
124
  }, fn: F, thisArg?: ThisParameterType<F>): F;
124
- declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>): F;
125
+ declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, extraProperties?: Record<string, string>): F;
125
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, extraProperties?: Record<string, AttributeValue>): T;
126
138
 
127
139
  declare function getMetricsExporter(): OTLPMetricExporter;
128
140
  declare function getMetricsReader(): MetricReader;
@@ -140,4 +152,4 @@ declare namespace init {
140
152
  export { };
141
153
  }
142
154
 
143
- 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.8";
437
+ return "0.1.10";
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 = [
@@ -1427,7 +1430,7 @@ function getMetricsReader() {
1427
1430
  }
1428
1431
 
1429
1432
  // src/internal/trace/tracing.ts
1430
- import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
1433
+ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
1431
1434
 
1432
1435
  // src/internal/trace/processors/span-processor.ts
1433
1436
  import { context as context2 } from "@opentelemetry/api";
@@ -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);
@@ -1646,12 +1649,97 @@ function withProperties(properties, fn, thisArg) {
1646
1649
  );
1647
1650
  };
1648
1651
  }
1649
- function withSessionId(sessionId, fn, thisArg) {
1650
- return withProperties({ [SESSION_ID]: sessionId }, fn, thisArg);
1652
+ function withSessionId(sessionId, fn, thisArg, extraProperties) {
1653
+ const properties = { [SESSION_ID]: sessionId, ...extraProperties };
1654
+ return withProperties(properties, fn, thisArg);
1651
1655
  }
1652
1656
  function callWithSessionId(sessionId, fn, thisArg, ...args) {
1653
1657
  return callWithProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
1654
1658
  }
1659
+ var Session = class {
1660
+ sessionId;
1661
+ span;
1662
+ inputs = [];
1663
+ outputs = [];
1664
+ constructor(sessionId, span) {
1665
+ this.sessionId = sessionId;
1666
+ this.span = span;
1667
+ }
1668
+ /**
1669
+ * (Optional) Append text to session input tracking.
1670
+ * Use when you need to track specific input data that differs from what's sent to the LLM.
1671
+ * Multiple calls accumulate in an array.
1672
+ *
1673
+ * @param text - Text to append to session input
1674
+ */
1675
+ setInput(text) {
1676
+ this.inputs.push(text);
1677
+ this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
1678
+ }
1679
+ /**
1680
+ * (Optional) Append text to session output tracking.
1681
+ * Use when you need to track specific output data that differs from what's received from the LLM.
1682
+ * Multiple calls accumulate in an array.
1683
+ *
1684
+ * @param text - Text to append to session output
1685
+ */
1686
+ setOutput(text) {
1687
+ this.outputs.push(text);
1688
+ this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
1689
+ }
1690
+ /**
1691
+ * Update custom properties on the session span.
1692
+ * Properties are prefixed with 'brizz.'.
1693
+ *
1694
+ * @param properties - Key-value properties to set on the session
1695
+ */
1696
+ updateProperties(properties) {
1697
+ for (const [key, value] of Object.entries(properties)) {
1698
+ this.span.setAttribute(`${BRIZZ}.${key}`, value);
1699
+ }
1700
+ }
1701
+ };
1702
+ function startSession(sessionId, callback, extraProperties) {
1703
+ const tracer = trace.getTracer("@brizz/sdk");
1704
+ return tracer.startActiveSpan(SESSION_SPAN_NAME, (span) => {
1705
+ span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
1706
+ if (extraProperties) {
1707
+ for (const [key, value] of Object.entries(extraProperties)) {
1708
+ span.setAttribute(`${BRIZZ}.${key}`, value);
1709
+ }
1710
+ }
1711
+ const session = new Session(sessionId, span);
1712
+ const contextProperties = { [SESSION_ID]: sessionId };
1713
+ if (extraProperties) {
1714
+ for (const [key, value] of Object.entries(extraProperties)) {
1715
+ contextProperties[key] = String(value);
1716
+ }
1717
+ }
1718
+ return callWithProperties(contextProperties, () => {
1719
+ try {
1720
+ const result = callback(session);
1721
+ if (result && typeof result.then === "function") {
1722
+ return result.then((value) => {
1723
+ span.end();
1724
+ return value;
1725
+ }).catch((error) => {
1726
+ span.recordException(error);
1727
+ span.setStatus({ code: SpanStatusCode.ERROR });
1728
+ span.end();
1729
+ throw error;
1730
+ });
1731
+ }
1732
+ span.end();
1733
+ return result;
1734
+ } catch (error) {
1735
+ span.recordException(error);
1736
+ span.setStatus({ code: SpanStatusCode.ERROR });
1737
+ span.end();
1738
+ throw error;
1739
+ }
1740
+ });
1741
+ });
1742
+ }
1655
1743
 
1656
1744
  // src/internal/sdk.ts
1657
1745
  var _Brizz = class __Brizz {
@@ -1901,6 +1989,7 @@ export {
1901
1989
  Brizz,
1902
1990
  DEFAULT_PII_PATTERNS,
1903
1991
  LogLevel,
1992
+ Session,
1904
1993
  SeverityNumber2 as SeverityNumber,
1905
1994
  callWithProperties,
1906
1995
  callWithSessionId,
@@ -1916,6 +2005,7 @@ export {
1916
2005
  maskAttributes,
1917
2006
  maskValue,
1918
2007
  setLogLevel,
2008
+ startSession,
1919
2009
  withProperties,
1920
2010
  withSessionId
1921
2011
  };