@brizz/sdk 0.1.15 → 0.1.17

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
@@ -95,6 +95,7 @@ interface IBrizzInitializeOptions {
95
95
  customSpanExporter?: SpanExporter;
96
96
  customLogExporter?: LogRecordExporter;
97
97
  customMetricReader?: MetricReader;
98
+ disableSpanExporter?: boolean;
98
99
  }
99
100
  declare class _Brizz {
100
101
  private static instance;
@@ -132,10 +133,21 @@ declare class Session {
132
133
  constructor(sessionId: string, span: Span);
133
134
  setInput(text: string | null): void;
134
135
  setOutput(text: string | null): void;
136
+ setTitle(title: string): void;
135
137
  updateProperties(properties: Record<string, AttributeValue>): void;
136
138
  }
139
+ declare class SessionTitle {
140
+ private readonly span;
141
+ constructor(span: Span);
142
+ setTitle(title: string): void;
143
+ }
137
144
  declare function getActiveSession(): Session | undefined;
138
- declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>): T;
145
+ declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>, options?: {
146
+ mode?: 'default' | 'title';
147
+ }): T;
148
+ declare function startSessionTitle<T>(callback: (title: SessionTitle) => T, options?: {
149
+ sessionId?: string;
150
+ }): T;
139
151
 
140
152
  declare function getMetricsExporter(): OTLPMetricExporter;
141
153
  declare function getMetricsReader(): MetricReader;
@@ -153,4 +165,4 @@ declare namespace init {
153
165
  export { };
154
166
  }
155
167
 
156
- 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, getActiveSession, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, startSession, withProperties, withSessionId };
168
+ 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, SessionTitle, callWithProperties, callWithSessionId, detectRuntime, emitEvent, getActiveSession, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, startSession, startSessionTitle, withProperties, withSessionId };
package/dist/index.d.ts CHANGED
@@ -95,6 +95,7 @@ interface IBrizzInitializeOptions {
95
95
  customSpanExporter?: SpanExporter;
96
96
  customLogExporter?: LogRecordExporter;
97
97
  customMetricReader?: MetricReader;
98
+ disableSpanExporter?: boolean;
98
99
  }
99
100
  declare class _Brizz {
100
101
  private static instance;
@@ -132,10 +133,21 @@ declare class Session {
132
133
  constructor(sessionId: string, span: Span);
133
134
  setInput(text: string | null): void;
134
135
  setOutput(text: string | null): void;
136
+ setTitle(title: string): void;
135
137
  updateProperties(properties: Record<string, AttributeValue>): void;
136
138
  }
139
+ declare class SessionTitle {
140
+ private readonly span;
141
+ constructor(span: Span);
142
+ setTitle(title: string): void;
143
+ }
137
144
  declare function getActiveSession(): Session | undefined;
138
- declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>): T;
145
+ declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>, options?: {
146
+ mode?: 'default' | 'title';
147
+ }): T;
148
+ declare function startSessionTitle<T>(callback: (title: SessionTitle) => T, options?: {
149
+ sessionId?: string;
150
+ }): T;
139
151
 
140
152
  declare function getMetricsExporter(): OTLPMetricExporter;
141
153
  declare function getMetricsReader(): MetricReader;
@@ -153,4 +165,4 @@ declare namespace init {
153
165
  export { };
154
166
  }
155
167
 
156
- 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, getActiveSession, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, startSession, withProperties, withSessionId };
168
+ 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, SessionTitle, callWithProperties, callWithSessionId, detectRuntime, emitEvent, getActiveSession, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, startSession, startSessionTitle, withProperties, withSessionId };
package/dist/index.js CHANGED
@@ -278,6 +278,7 @@ function resolveConfig(options) {
278
278
  headers: { ...options.headers },
279
279
  apiKey: process.env["BRIZZ_API_KEY"] || options.apiKey,
280
280
  disableBatch: process.env["BRIZZ_DISABLE_BATCH"] === "true" || !!options.disableBatch,
281
+ disableSpanExporter: process.env["BRIZZ_DISABLE_SPAN_EXPORTER"] === "true" || !!options.disableSpanExporter,
281
282
  environment: process.env["BRIZZ_ENVIRONMENT"] || options.environment,
282
283
  logLevel: resolvedLogLevel,
283
284
  masking: resolvedMasking
@@ -445,7 +446,7 @@ import {
445
446
 
446
447
  // src/internal/version.ts
447
448
  function getSDKVersion() {
448
- return "0.1.15";
449
+ return "0.1.17";
449
450
  }
450
451
 
451
452
  // src/internal/log/processors/log-processor.ts
@@ -1086,6 +1087,9 @@ var SESSION_OBJECT_CONTEXT_KEY = createContextKey("brizz.session.object");
1086
1087
  var SESSION_INPUT = "brizz.session.input";
1087
1088
  var SESSION_OUTPUT = "brizz.session.output";
1088
1089
  var SESSION_SPAN_NAME = "brizz.start_session";
1090
+ var SESSION_TITLE_SPAN_NAME = "brizz.session_title";
1091
+ var SESSION_TITLE_GENERATION = "session.title_generation";
1092
+ var SESSION_TITLE = "brizz.session.title";
1089
1093
 
1090
1094
  // src/internal/log/processors/log-processor.ts
1091
1095
  var DEFAULT_LOG_MASKING_RULES = [
@@ -1592,6 +1596,15 @@ var TracingModule = class _TracingModule {
1592
1596
  */
1593
1597
  setup(config) {
1594
1598
  logger.info("Setting up tracing module");
1599
+ if (config.disableSpanExporter) {
1600
+ logger.info(
1601
+ "Span exporter disabled via disableSpanExporter; skipping exporter and processor setup"
1602
+ );
1603
+ this.spanExporter = null;
1604
+ this.spanProcessor = null;
1605
+ _TracingModule.instance = this;
1606
+ return;
1607
+ }
1595
1608
  this.initSpanExporter(config);
1596
1609
  this.initSpanProcessor(config);
1597
1610
  _TracingModule.instance = this;
@@ -1735,6 +1748,14 @@ var Session = class {
1735
1748
  this.outputs.push(text);
1736
1749
  this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
1737
1750
  }
1751
+ /**
1752
+ * Set the session title on the span.
1753
+ *
1754
+ * @param title - The generated title string
1755
+ */
1756
+ setTitle(title) {
1757
+ this.span.setAttribute(SESSION_TITLE, title);
1758
+ }
1738
1759
  /**
1739
1760
  * Update custom properties on the session span.
1740
1761
  * Properties are prefixed with 'brizz.'.
@@ -1747,12 +1768,28 @@ var Session = class {
1747
1768
  }
1748
1769
  }
1749
1770
  };
1771
+ var SessionTitle = class {
1772
+ span;
1773
+ constructor(span) {
1774
+ this.span = span;
1775
+ }
1776
+ /**
1777
+ * Set the generated title on the wrapper span.
1778
+ *
1779
+ * @param title - The generated title string
1780
+ */
1781
+ setTitle(title) {
1782
+ this.span.setAttribute(SESSION_TITLE, title);
1783
+ }
1784
+ };
1750
1785
  function getActiveSession() {
1751
1786
  return context3.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
1752
1787
  }
1753
- function startSession(sessionId, callback, extraProperties) {
1788
+ function startSession(sessionId, callback, extraProperties, options) {
1789
+ const isTitle = options?.mode === "title";
1790
+ const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
1754
1791
  const tracer = trace.getTracer("@brizz/sdk");
1755
- return tracer.startActiveSpan(SESSION_SPAN_NAME, (span) => {
1792
+ return tracer.startActiveSpan(spanName, (span) => {
1756
1793
  span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
1757
1794
  if (extraProperties) {
1758
1795
  for (const [key, value] of Object.entries(extraProperties)) {
@@ -1761,6 +1798,9 @@ function startSession(sessionId, callback, extraProperties) {
1761
1798
  }
1762
1799
  const session = new Session(sessionId, span);
1763
1800
  const contextProperties = { [SESSION_ID]: sessionId };
1801
+ if (isTitle) {
1802
+ contextProperties[SESSION_TITLE_GENERATION] = "true";
1803
+ }
1764
1804
  if (extraProperties) {
1765
1805
  for (const [key, value] of Object.entries(extraProperties)) {
1766
1806
  contextProperties[key] = String(value);
@@ -1794,6 +1834,43 @@ function startSession(sessionId, callback, extraProperties) {
1794
1834
  });
1795
1835
  });
1796
1836
  }
1837
+ function startSessionTitle(callback, options) {
1838
+ const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
1839
+ const tracer = trace.getTracer("@brizz/sdk");
1840
+ return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
1841
+ if (resolvedSessionId) {
1842
+ span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
1843
+ }
1844
+ const sessionTitle = new SessionTitle(span);
1845
+ const properties = { [SESSION_TITLE_GENERATION]: "true" };
1846
+ if (resolvedSessionId) {
1847
+ properties[SESSION_ID] = resolvedSessionId;
1848
+ }
1849
+ return callWithProperties(properties, () => {
1850
+ try {
1851
+ const result = callback(sessionTitle);
1852
+ if (result && typeof result.then === "function") {
1853
+ return result.then((value) => {
1854
+ span.end();
1855
+ return value;
1856
+ }).catch((error) => {
1857
+ span.recordException(error);
1858
+ span.setStatus({ code: SpanStatusCode.ERROR });
1859
+ span.end();
1860
+ throw error;
1861
+ });
1862
+ }
1863
+ span.end();
1864
+ return result;
1865
+ } catch (error) {
1866
+ span.recordException(error);
1867
+ span.setStatus({ code: SpanStatusCode.ERROR });
1868
+ span.end();
1869
+ throw error;
1870
+ }
1871
+ });
1872
+ });
1873
+ }
1797
1874
 
1798
1875
  // src/internal/sdk.ts
1799
1876
  var _Brizz = class __Brizz {
@@ -1874,7 +1951,7 @@ var _Brizz = class __Brizz {
1874
1951
  resourceAttributes["deployment.environment"] = resolvedConfig.environment;
1875
1952
  }
1876
1953
  this._sdk = new NodeSDK({
1877
- spanProcessors: [getSpanProcessor()],
1954
+ spanProcessors: resolvedConfig.disableSpanExporter ? [] : [getSpanProcessor()],
1878
1955
  metricReader: getMetricsReader(),
1879
1956
  resource: resourceFromAttributes3(resourceAttributes),
1880
1957
  instrumentations: manualInstrumentations
@@ -2044,6 +2121,7 @@ export {
2044
2121
  DEFAULT_PII_PATTERNS,
2045
2122
  LogLevel,
2046
2123
  Session,
2124
+ SessionTitle,
2047
2125
  SeverityNumber2 as SeverityNumber,
2048
2126
  callWithProperties,
2049
2127
  callWithSessionId,
@@ -2061,6 +2139,7 @@ export {
2061
2139
  maskValue,
2062
2140
  setLogLevel,
2063
2141
  startSession,
2142
+ startSessionTitle,
2064
2143
  withProperties,
2065
2144
  withSessionId
2066
2145
  };