@brizz/sdk 0.1.15 → 0.1.16
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/README.md +33 -0
- package/dist/index.cjs +74 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +72 -3
- package/dist/index.js.map +1 -1
- package/dist/preload.cjs +1 -1
- package/dist/preload.cjs.map +1 -1
- package/dist/preload.js +1 -1
- package/dist/preload.js.map +1 -1
- package/package.json +11 -11
package/dist/index.d.cts
CHANGED
|
@@ -132,10 +132,21 @@ declare class Session {
|
|
|
132
132
|
constructor(sessionId: string, span: Span);
|
|
133
133
|
setInput(text: string | null): void;
|
|
134
134
|
setOutput(text: string | null): void;
|
|
135
|
+
setTitle(title: string): void;
|
|
135
136
|
updateProperties(properties: Record<string, AttributeValue>): void;
|
|
136
137
|
}
|
|
138
|
+
declare class SessionTitle {
|
|
139
|
+
private readonly span;
|
|
140
|
+
constructor(span: Span);
|
|
141
|
+
setTitle(title: string): void;
|
|
142
|
+
}
|
|
137
143
|
declare function getActiveSession(): Session | undefined;
|
|
138
|
-
declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue
|
|
144
|
+
declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>, options?: {
|
|
145
|
+
mode?: 'default' | 'title';
|
|
146
|
+
}): T;
|
|
147
|
+
declare function startSessionTitle<T>(callback: (title: SessionTitle) => T, options?: {
|
|
148
|
+
sessionId?: string;
|
|
149
|
+
}): T;
|
|
139
150
|
|
|
140
151
|
declare function getMetricsExporter(): OTLPMetricExporter;
|
|
141
152
|
declare function getMetricsReader(): MetricReader;
|
|
@@ -153,4 +164,4 @@ declare namespace init {
|
|
|
153
164
|
export { };
|
|
154
165
|
}
|
|
155
166
|
|
|
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 };
|
|
167
|
+
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
|
@@ -132,10 +132,21 @@ declare class Session {
|
|
|
132
132
|
constructor(sessionId: string, span: Span);
|
|
133
133
|
setInput(text: string | null): void;
|
|
134
134
|
setOutput(text: string | null): void;
|
|
135
|
+
setTitle(title: string): void;
|
|
135
136
|
updateProperties(properties: Record<string, AttributeValue>): void;
|
|
136
137
|
}
|
|
138
|
+
declare class SessionTitle {
|
|
139
|
+
private readonly span;
|
|
140
|
+
constructor(span: Span);
|
|
141
|
+
setTitle(title: string): void;
|
|
142
|
+
}
|
|
137
143
|
declare function getActiveSession(): Session | undefined;
|
|
138
|
-
declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue
|
|
144
|
+
declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>, options?: {
|
|
145
|
+
mode?: 'default' | 'title';
|
|
146
|
+
}): T;
|
|
147
|
+
declare function startSessionTitle<T>(callback: (title: SessionTitle) => T, options?: {
|
|
148
|
+
sessionId?: string;
|
|
149
|
+
}): T;
|
|
139
150
|
|
|
140
151
|
declare function getMetricsExporter(): OTLPMetricExporter;
|
|
141
152
|
declare function getMetricsReader(): MetricReader;
|
|
@@ -153,4 +164,4 @@ declare namespace init {
|
|
|
153
164
|
export { };
|
|
154
165
|
}
|
|
155
166
|
|
|
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 };
|
|
167
|
+
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
|
@@ -445,7 +445,7 @@ import {
|
|
|
445
445
|
|
|
446
446
|
// src/internal/version.ts
|
|
447
447
|
function getSDKVersion() {
|
|
448
|
-
return "0.1.
|
|
448
|
+
return "0.1.16";
|
|
449
449
|
}
|
|
450
450
|
|
|
451
451
|
// src/internal/log/processors/log-processor.ts
|
|
@@ -1086,6 +1086,9 @@ var SESSION_OBJECT_CONTEXT_KEY = createContextKey("brizz.session.object");
|
|
|
1086
1086
|
var SESSION_INPUT = "brizz.session.input";
|
|
1087
1087
|
var SESSION_OUTPUT = "brizz.session.output";
|
|
1088
1088
|
var SESSION_SPAN_NAME = "brizz.start_session";
|
|
1089
|
+
var SESSION_TITLE_SPAN_NAME = "brizz.session_title";
|
|
1090
|
+
var SESSION_TITLE_GENERATION = "session.title_generation";
|
|
1091
|
+
var SESSION_TITLE = "brizz.session.title";
|
|
1089
1092
|
|
|
1090
1093
|
// src/internal/log/processors/log-processor.ts
|
|
1091
1094
|
var DEFAULT_LOG_MASKING_RULES = [
|
|
@@ -1735,6 +1738,14 @@ var Session = class {
|
|
|
1735
1738
|
this.outputs.push(text);
|
|
1736
1739
|
this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
|
|
1737
1740
|
}
|
|
1741
|
+
/**
|
|
1742
|
+
* Set the session title on the span.
|
|
1743
|
+
*
|
|
1744
|
+
* @param title - The generated title string
|
|
1745
|
+
*/
|
|
1746
|
+
setTitle(title) {
|
|
1747
|
+
this.span.setAttribute(SESSION_TITLE, title);
|
|
1748
|
+
}
|
|
1738
1749
|
/**
|
|
1739
1750
|
* Update custom properties on the session span.
|
|
1740
1751
|
* Properties are prefixed with 'brizz.'.
|
|
@@ -1747,12 +1758,28 @@ var Session = class {
|
|
|
1747
1758
|
}
|
|
1748
1759
|
}
|
|
1749
1760
|
};
|
|
1761
|
+
var SessionTitle = class {
|
|
1762
|
+
span;
|
|
1763
|
+
constructor(span) {
|
|
1764
|
+
this.span = span;
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Set the generated title on the wrapper span.
|
|
1768
|
+
*
|
|
1769
|
+
* @param title - The generated title string
|
|
1770
|
+
*/
|
|
1771
|
+
setTitle(title) {
|
|
1772
|
+
this.span.setAttribute(SESSION_TITLE, title);
|
|
1773
|
+
}
|
|
1774
|
+
};
|
|
1750
1775
|
function getActiveSession() {
|
|
1751
1776
|
return context3.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
|
|
1752
1777
|
}
|
|
1753
|
-
function startSession(sessionId, callback, extraProperties) {
|
|
1778
|
+
function startSession(sessionId, callback, extraProperties, options) {
|
|
1779
|
+
const isTitle = options?.mode === "title";
|
|
1780
|
+
const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
|
|
1754
1781
|
const tracer = trace.getTracer("@brizz/sdk");
|
|
1755
|
-
return tracer.startActiveSpan(
|
|
1782
|
+
return tracer.startActiveSpan(spanName, (span) => {
|
|
1756
1783
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
1757
1784
|
if (extraProperties) {
|
|
1758
1785
|
for (const [key, value] of Object.entries(extraProperties)) {
|
|
@@ -1761,6 +1788,9 @@ function startSession(sessionId, callback, extraProperties) {
|
|
|
1761
1788
|
}
|
|
1762
1789
|
const session = new Session(sessionId, span);
|
|
1763
1790
|
const contextProperties = { [SESSION_ID]: sessionId };
|
|
1791
|
+
if (isTitle) {
|
|
1792
|
+
contextProperties[SESSION_TITLE_GENERATION] = "true";
|
|
1793
|
+
}
|
|
1764
1794
|
if (extraProperties) {
|
|
1765
1795
|
for (const [key, value] of Object.entries(extraProperties)) {
|
|
1766
1796
|
contextProperties[key] = String(value);
|
|
@@ -1794,6 +1824,43 @@ function startSession(sessionId, callback, extraProperties) {
|
|
|
1794
1824
|
});
|
|
1795
1825
|
});
|
|
1796
1826
|
}
|
|
1827
|
+
function startSessionTitle(callback, options) {
|
|
1828
|
+
const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
|
|
1829
|
+
const tracer = trace.getTracer("@brizz/sdk");
|
|
1830
|
+
return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
|
|
1831
|
+
if (resolvedSessionId) {
|
|
1832
|
+
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
|
|
1833
|
+
}
|
|
1834
|
+
const sessionTitle = new SessionTitle(span);
|
|
1835
|
+
const properties = { [SESSION_TITLE_GENERATION]: "true" };
|
|
1836
|
+
if (resolvedSessionId) {
|
|
1837
|
+
properties[SESSION_ID] = resolvedSessionId;
|
|
1838
|
+
}
|
|
1839
|
+
return callWithProperties(properties, () => {
|
|
1840
|
+
try {
|
|
1841
|
+
const result = callback(sessionTitle);
|
|
1842
|
+
if (result && typeof result.then === "function") {
|
|
1843
|
+
return result.then((value) => {
|
|
1844
|
+
span.end();
|
|
1845
|
+
return value;
|
|
1846
|
+
}).catch((error) => {
|
|
1847
|
+
span.recordException(error);
|
|
1848
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1849
|
+
span.end();
|
|
1850
|
+
throw error;
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
span.end();
|
|
1854
|
+
return result;
|
|
1855
|
+
} catch (error) {
|
|
1856
|
+
span.recordException(error);
|
|
1857
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1858
|
+
span.end();
|
|
1859
|
+
throw error;
|
|
1860
|
+
}
|
|
1861
|
+
});
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1797
1864
|
|
|
1798
1865
|
// src/internal/sdk.ts
|
|
1799
1866
|
var _Brizz = class __Brizz {
|
|
@@ -2044,6 +2111,7 @@ export {
|
|
|
2044
2111
|
DEFAULT_PII_PATTERNS,
|
|
2045
2112
|
LogLevel,
|
|
2046
2113
|
Session,
|
|
2114
|
+
SessionTitle,
|
|
2047
2115
|
SeverityNumber2 as SeverityNumber,
|
|
2048
2116
|
callWithProperties,
|
|
2049
2117
|
callWithSessionId,
|
|
@@ -2061,6 +2129,7 @@ export {
|
|
|
2061
2129
|
maskValue,
|
|
2062
2130
|
setLogLevel,
|
|
2063
2131
|
startSession,
|
|
2132
|
+
startSessionTitle,
|
|
2064
2133
|
withProperties,
|
|
2065
2134
|
withSessionId
|
|
2066
2135
|
};
|