@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/README.md +48 -1
- package/dist/index.cjs +85 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +83 -4
- package/dist/index.js.map +1 -1
- package/dist/preload.cjs +12 -2
- package/dist/preload.cjs.map +1 -1
- package/dist/preload.js +12 -2
- package/dist/preload.js.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ libraries including OpenAI, Anthropic, Vercel AI SDK, and more.
|
|
|
20
20
|
- [Session Tracking](#session-tracking)
|
|
21
21
|
- [Custom Events & Logging](#custom-events--logging)
|
|
22
22
|
- [Environment Variables](#environment-variables)
|
|
23
|
+
- [Disable Span Export](#disable-span-export)
|
|
23
24
|
- [Advanced Configuration](#advanced-configuration)
|
|
24
25
|
- [Testing & Development](#testing--development)
|
|
25
26
|
- [Package.json Examples](#packagejson-examples)
|
|
@@ -288,6 +289,7 @@ const result = await startSession(
|
|
|
288
289
|
- `session.updateProperties({ key: value })` - Add custom properties to the session span
|
|
289
290
|
- `session.setInput(text)` - (Optional) Manually track input text
|
|
290
291
|
- `session.setOutput(text)` - (Optional) Manually track output text
|
|
292
|
+
- `session.setTitle(text)` - Set a session title (typically used with `mode: 'title'`)
|
|
291
293
|
|
|
292
294
|
**When to use manual input/output tracking:**
|
|
293
295
|
|
|
@@ -313,6 +315,38 @@ await startSession('session-456', async (session) => {
|
|
|
313
315
|
});
|
|
314
316
|
```
|
|
315
317
|
|
|
318
|
+
### Session Title Generation
|
|
319
|
+
|
|
320
|
+
If you use an LLM call to generate session titles, wrap it so those spans don't appear as part of the conversation:
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
import { startSession, startSessionTitle } from '@brizz/sdk';
|
|
324
|
+
|
|
325
|
+
await startSession('session-123', async (session) => {
|
|
326
|
+
const response = await openai.chat.completions.create({...});
|
|
327
|
+
|
|
328
|
+
// Title generation — excluded from conversation view
|
|
329
|
+
await startSessionTitle(async (title) => {
|
|
330
|
+
const t = await openai.chat.completions.create({
|
|
331
|
+
model: 'gpt-4',
|
|
332
|
+
messages: [{ role: 'user', content: 'Summarize this chat in 3 words' }],
|
|
333
|
+
});
|
|
334
|
+
title.setTitle(t.choices[0].message.content);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// Or use mode: 'title' on startSession directly
|
|
339
|
+
await startSession('session-123', async (session) => {
|
|
340
|
+
const t = await openai.chat.completions.create({...});
|
|
341
|
+
session.setTitle(t.choices[0].message.content);
|
|
342
|
+
}, undefined, { mode: 'title' });
|
|
343
|
+
|
|
344
|
+
// Or use startSessionTitle outside a session (pass sessionId explicitly)
|
|
345
|
+
await startSessionTitle(async (title) => {
|
|
346
|
+
title.setTitle('My Title');
|
|
347
|
+
}, { sessionId: 'session-123' });
|
|
348
|
+
```
|
|
349
|
+
|
|
316
350
|
### Accessing the Active Session
|
|
317
351
|
|
|
318
352
|
Use `getActiveSession()` to retrieve the current session from anywhere within a `startSession` scope — no need to pass the session object through your call stack:
|
|
@@ -474,13 +508,26 @@ BRIZZ_BASE_URL=https://telemetry.brizz.dev # Default telemetry endpoint
|
|
|
474
508
|
BRIZZ_APP_NAME=my-app # Application name
|
|
475
509
|
BRIZZ_APP_VERSION=1.0.0 # Application version
|
|
476
510
|
BRIZZ_ENVIRONMENT=production # Environment (dev, staging, prod)
|
|
477
|
-
BRIZZ_LOG_LEVEL=info
|
|
511
|
+
BRIZZ_LOG_LEVEL=info # SDK log level
|
|
512
|
+
BRIZZ_DISABLE_SPAN_EXPORTER=true # Skip span export (see "Disable Span Export")
|
|
478
513
|
|
|
479
514
|
# OpenTelemetry Standard Variables
|
|
480
515
|
OTEL_SERVICE_NAME=my-service # Service name
|
|
481
516
|
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true # Capture AI content
|
|
482
517
|
```
|
|
483
518
|
|
|
519
|
+
## Disable Span Export
|
|
520
|
+
|
|
521
|
+
Keep `Brizz.initialize()` in your code without sending any spans — useful for dev/test
|
|
522
|
+
environments. When enabled, the SDK skips span exporter and processor setup, so no
|
|
523
|
+
spans are exported. Metrics and logs continue to work.
|
|
524
|
+
|
|
525
|
+
```typescript
|
|
526
|
+
Brizz.initialize({ apiKey: 'your-api-key', disableSpanExporter: true });
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
Or via env var: `BRIZZ_DISABLE_SPAN_EXPORTER=true`.
|
|
530
|
+
|
|
484
531
|
## Advanced Configuration
|
|
485
532
|
|
|
486
533
|
```typescript
|
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
DEFAULT_PII_PATTERNS: () => DEFAULT_PII_PATTERNS,
|
|
35
35
|
LogLevel: () => LogLevel,
|
|
36
36
|
Session: () => Session,
|
|
37
|
+
SessionTitle: () => SessionTitle,
|
|
37
38
|
SeverityNumber: () => import_api_logs2.SeverityNumber,
|
|
38
39
|
callWithProperties: () => callWithProperties,
|
|
39
40
|
callWithSessionId: () => callWithSessionId,
|
|
@@ -51,6 +52,7 @@ __export(src_exports, {
|
|
|
51
52
|
maskValue: () => maskValue,
|
|
52
53
|
setLogLevel: () => setLogLevel,
|
|
53
54
|
startSession: () => startSession,
|
|
55
|
+
startSessionTitle: () => startSessionTitle,
|
|
54
56
|
withProperties: () => withProperties,
|
|
55
57
|
withSessionId: () => withSessionId
|
|
56
58
|
});
|
|
@@ -329,6 +331,7 @@ function resolveConfig(options) {
|
|
|
329
331
|
headers: { ...options.headers },
|
|
330
332
|
apiKey: process.env["BRIZZ_API_KEY"] || options.apiKey,
|
|
331
333
|
disableBatch: process.env["BRIZZ_DISABLE_BATCH"] === "true" || !!options.disableBatch,
|
|
334
|
+
disableSpanExporter: process.env["BRIZZ_DISABLE_SPAN_EXPORTER"] === "true" || !!options.disableSpanExporter,
|
|
332
335
|
environment: process.env["BRIZZ_ENVIRONMENT"] || options.environment,
|
|
333
336
|
logLevel: resolvedLogLevel,
|
|
334
337
|
masking: resolvedMasking
|
|
@@ -494,7 +497,7 @@ var import_sdk_logs2 = require("@opentelemetry/sdk-logs");
|
|
|
494
497
|
|
|
495
498
|
// src/internal/version.ts
|
|
496
499
|
function getSDKVersion() {
|
|
497
|
-
return "0.1.
|
|
500
|
+
return "0.1.17";
|
|
498
501
|
}
|
|
499
502
|
|
|
500
503
|
// src/internal/log/processors/log-processor.ts
|
|
@@ -1135,6 +1138,9 @@ var SESSION_OBJECT_CONTEXT_KEY = (0, import_api2.createContextKey)("brizz.sessio
|
|
|
1135
1138
|
var SESSION_INPUT = "brizz.session.input";
|
|
1136
1139
|
var SESSION_OUTPUT = "brizz.session.output";
|
|
1137
1140
|
var SESSION_SPAN_NAME = "brizz.start_session";
|
|
1141
|
+
var SESSION_TITLE_SPAN_NAME = "brizz.session_title";
|
|
1142
|
+
var SESSION_TITLE_GENERATION = "session.title_generation";
|
|
1143
|
+
var SESSION_TITLE = "brizz.session.title";
|
|
1138
1144
|
|
|
1139
1145
|
// src/internal/log/processors/log-processor.ts
|
|
1140
1146
|
var DEFAULT_LOG_MASKING_RULES = [
|
|
@@ -1638,6 +1644,15 @@ var TracingModule = class _TracingModule {
|
|
|
1638
1644
|
*/
|
|
1639
1645
|
setup(config) {
|
|
1640
1646
|
logger.info("Setting up tracing module");
|
|
1647
|
+
if (config.disableSpanExporter) {
|
|
1648
|
+
logger.info(
|
|
1649
|
+
"Span exporter disabled via disableSpanExporter; skipping exporter and processor setup"
|
|
1650
|
+
);
|
|
1651
|
+
this.spanExporter = null;
|
|
1652
|
+
this.spanProcessor = null;
|
|
1653
|
+
_TracingModule.instance = this;
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1641
1656
|
this.initSpanExporter(config);
|
|
1642
1657
|
this.initSpanProcessor(config);
|
|
1643
1658
|
_TracingModule.instance = this;
|
|
@@ -1781,6 +1796,14 @@ var Session = class {
|
|
|
1781
1796
|
this.outputs.push(text);
|
|
1782
1797
|
this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
|
|
1783
1798
|
}
|
|
1799
|
+
/**
|
|
1800
|
+
* Set the session title on the span.
|
|
1801
|
+
*
|
|
1802
|
+
* @param title - The generated title string
|
|
1803
|
+
*/
|
|
1804
|
+
setTitle(title) {
|
|
1805
|
+
this.span.setAttribute(SESSION_TITLE, title);
|
|
1806
|
+
}
|
|
1784
1807
|
/**
|
|
1785
1808
|
* Update custom properties on the session span.
|
|
1786
1809
|
* Properties are prefixed with 'brizz.'.
|
|
@@ -1793,12 +1816,28 @@ var Session = class {
|
|
|
1793
1816
|
}
|
|
1794
1817
|
}
|
|
1795
1818
|
};
|
|
1819
|
+
var SessionTitle = class {
|
|
1820
|
+
span;
|
|
1821
|
+
constructor(span) {
|
|
1822
|
+
this.span = span;
|
|
1823
|
+
}
|
|
1824
|
+
/**
|
|
1825
|
+
* Set the generated title on the wrapper span.
|
|
1826
|
+
*
|
|
1827
|
+
* @param title - The generated title string
|
|
1828
|
+
*/
|
|
1829
|
+
setTitle(title) {
|
|
1830
|
+
this.span.setAttribute(SESSION_TITLE, title);
|
|
1831
|
+
}
|
|
1832
|
+
};
|
|
1796
1833
|
function getActiveSession() {
|
|
1797
1834
|
return import_api5.context.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
|
|
1798
1835
|
}
|
|
1799
|
-
function startSession(sessionId, callback, extraProperties) {
|
|
1836
|
+
function startSession(sessionId, callback, extraProperties, options) {
|
|
1837
|
+
const isTitle = options?.mode === "title";
|
|
1838
|
+
const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
|
|
1800
1839
|
const tracer = import_api5.trace.getTracer("@brizz/sdk");
|
|
1801
|
-
return tracer.startActiveSpan(
|
|
1840
|
+
return tracer.startActiveSpan(spanName, (span) => {
|
|
1802
1841
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
1803
1842
|
if (extraProperties) {
|
|
1804
1843
|
for (const [key, value] of Object.entries(extraProperties)) {
|
|
@@ -1807,6 +1846,9 @@ function startSession(sessionId, callback, extraProperties) {
|
|
|
1807
1846
|
}
|
|
1808
1847
|
const session = new Session(sessionId, span);
|
|
1809
1848
|
const contextProperties = { [SESSION_ID]: sessionId };
|
|
1849
|
+
if (isTitle) {
|
|
1850
|
+
contextProperties[SESSION_TITLE_GENERATION] = "true";
|
|
1851
|
+
}
|
|
1810
1852
|
if (extraProperties) {
|
|
1811
1853
|
for (const [key, value] of Object.entries(extraProperties)) {
|
|
1812
1854
|
contextProperties[key] = String(value);
|
|
@@ -1840,6 +1882,43 @@ function startSession(sessionId, callback, extraProperties) {
|
|
|
1840
1882
|
});
|
|
1841
1883
|
});
|
|
1842
1884
|
}
|
|
1885
|
+
function startSessionTitle(callback, options) {
|
|
1886
|
+
const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
|
|
1887
|
+
const tracer = import_api5.trace.getTracer("@brizz/sdk");
|
|
1888
|
+
return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
|
|
1889
|
+
if (resolvedSessionId) {
|
|
1890
|
+
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
|
|
1891
|
+
}
|
|
1892
|
+
const sessionTitle = new SessionTitle(span);
|
|
1893
|
+
const properties = { [SESSION_TITLE_GENERATION]: "true" };
|
|
1894
|
+
if (resolvedSessionId) {
|
|
1895
|
+
properties[SESSION_ID] = resolvedSessionId;
|
|
1896
|
+
}
|
|
1897
|
+
return callWithProperties(properties, () => {
|
|
1898
|
+
try {
|
|
1899
|
+
const result = callback(sessionTitle);
|
|
1900
|
+
if (result && typeof result.then === "function") {
|
|
1901
|
+
return result.then((value) => {
|
|
1902
|
+
span.end();
|
|
1903
|
+
return value;
|
|
1904
|
+
}).catch((error) => {
|
|
1905
|
+
span.recordException(error);
|
|
1906
|
+
span.setStatus({ code: import_api5.SpanStatusCode.ERROR });
|
|
1907
|
+
span.end();
|
|
1908
|
+
throw error;
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
span.end();
|
|
1912
|
+
return result;
|
|
1913
|
+
} catch (error) {
|
|
1914
|
+
span.recordException(error);
|
|
1915
|
+
span.setStatus({ code: import_api5.SpanStatusCode.ERROR });
|
|
1916
|
+
span.end();
|
|
1917
|
+
throw error;
|
|
1918
|
+
}
|
|
1919
|
+
});
|
|
1920
|
+
});
|
|
1921
|
+
}
|
|
1843
1922
|
|
|
1844
1923
|
// src/internal/sdk.ts
|
|
1845
1924
|
var _Brizz = class __Brizz {
|
|
@@ -1920,7 +1999,7 @@ var _Brizz = class __Brizz {
|
|
|
1920
1999
|
resourceAttributes["deployment.environment"] = resolvedConfig.environment;
|
|
1921
2000
|
}
|
|
1922
2001
|
this._sdk = new import_sdk_node.NodeSDK({
|
|
1923
|
-
spanProcessors: [getSpanProcessor()],
|
|
2002
|
+
spanProcessors: resolvedConfig.disableSpanExporter ? [] : [getSpanProcessor()],
|
|
1924
2003
|
metricReader: getMetricsReader(),
|
|
1925
2004
|
resource: (0, import_resources3.resourceFromAttributes)(resourceAttributes),
|
|
1926
2005
|
instrumentations: manualInstrumentations
|
|
@@ -2091,6 +2170,7 @@ var init_exports = {};
|
|
|
2091
2170
|
DEFAULT_PII_PATTERNS,
|
|
2092
2171
|
LogLevel,
|
|
2093
2172
|
Session,
|
|
2173
|
+
SessionTitle,
|
|
2094
2174
|
SeverityNumber,
|
|
2095
2175
|
callWithProperties,
|
|
2096
2176
|
callWithSessionId,
|
|
@@ -2108,6 +2188,7 @@ var init_exports = {};
|
|
|
2108
2188
|
maskValue,
|
|
2109
2189
|
setLogLevel,
|
|
2110
2190
|
startSession,
|
|
2191
|
+
startSessionTitle,
|
|
2111
2192
|
withProperties,
|
|
2112
2193
|
withSessionId
|
|
2113
2194
|
});
|