@brizz/sdk 0.1.9 → 0.1.11
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 +15 -10
- package/dist/index.cjs +61 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +61 -13
- package/dist/index.js.map +1 -1
- package/dist/preload.cjs +45 -9
- package/dist/preload.cjs.map +1 -1
- package/dist/preload.js +45 -9
- package/dist/preload.js.map +1 -1
- package/package.json +37 -37
package/README.md
CHANGED
|
@@ -267,17 +267,21 @@ The `startSession` function creates a session span and provides a `Session` obje
|
|
|
267
267
|
import { startSession } from '@brizz/sdk';
|
|
268
268
|
|
|
269
269
|
// Basic usage - all LLM calls within the callback are automatically linked
|
|
270
|
-
const result = await startSession(
|
|
271
|
-
|
|
272
|
-
session
|
|
270
|
+
const result = await startSession(
|
|
271
|
+
'session-123',
|
|
272
|
+
async (session) => {
|
|
273
|
+
// Add custom properties (optional)
|
|
274
|
+
session.updateProperties({ userId: 'user-456', model: 'gpt-4' });
|
|
273
275
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
276
|
+
const response = await openai.chat.completions.create({
|
|
277
|
+
model: 'gpt-4',
|
|
278
|
+
messages: [{ role: 'user', content: userQuery }],
|
|
279
|
+
});
|
|
278
280
|
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
+
return response;
|
|
282
|
+
},
|
|
283
|
+
{ feature: 'chat' }, // optional: extraProperties propagated to all spans
|
|
284
|
+
);
|
|
281
285
|
```
|
|
282
286
|
|
|
283
287
|
**Session Methods:**
|
|
@@ -328,7 +332,8 @@ async function processUserWorkflow(userId: string) {
|
|
|
328
332
|
}
|
|
329
333
|
|
|
330
334
|
// Create a wrapped function that always executes with session context
|
|
331
|
-
|
|
335
|
+
// withSessionId(sessionId, fn, thisArg?, extraProperties?)
|
|
336
|
+
const sessionedWorkflow = withSessionId('session-123', processUserWorkflow, undefined, { feature: 'workflow' });
|
|
332
337
|
|
|
333
338
|
// Call multiple times, each with the same session context
|
|
334
339
|
await sessionedWorkflow('user-456');
|
package/dist/index.cjs
CHANGED
|
@@ -280,7 +280,7 @@ function autoInitializeInstrumentations() {
|
|
|
280
280
|
autoInitializeInstrumentations();
|
|
281
281
|
|
|
282
282
|
// src/internal/sdk.ts
|
|
283
|
-
var
|
|
283
|
+
var import_resources3 = require("@opentelemetry/resources");
|
|
284
284
|
var import_sdk_node = require("@opentelemetry/sdk-node");
|
|
285
285
|
|
|
286
286
|
// src/internal/config.ts
|
|
@@ -346,7 +346,7 @@ function resolveConfig(options) {
|
|
|
346
346
|
});
|
|
347
347
|
} catch (error) {
|
|
348
348
|
logger.error("Failed to parse BRIZZ_HEADERS environment variable", { error });
|
|
349
|
-
throw new Error("Invalid JSON in BRIZZ_HEADERS environment variable");
|
|
349
|
+
throw new Error("Invalid JSON in BRIZZ_HEADERS environment variable", { cause: error });
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
logger.debug("Configuration resolved with environment variables", {
|
|
@@ -482,7 +482,7 @@ var import_sdk_logs2 = require("@opentelemetry/sdk-logs");
|
|
|
482
482
|
|
|
483
483
|
// src/internal/version.ts
|
|
484
484
|
function getSDKVersion() {
|
|
485
|
-
return "0.1.
|
|
485
|
+
return "0.1.11";
|
|
486
486
|
}
|
|
487
487
|
|
|
488
488
|
// src/internal/log/processors/log-processor.ts
|
|
@@ -928,7 +928,9 @@ function getGroupedPattern(patternEntry) {
|
|
|
928
928
|
try {
|
|
929
929
|
new RegExp(patternEntry.pattern);
|
|
930
930
|
} catch (error) {
|
|
931
|
-
throw new Error(`Invalid regex pattern '${patternEntry.pattern}': ${String(error)}
|
|
931
|
+
throw new Error(`Invalid regex pattern '${patternEntry.pattern}': ${String(error)}`, {
|
|
932
|
+
cause: error
|
|
933
|
+
});
|
|
932
934
|
}
|
|
933
935
|
return `(?<${name}>${patternEntry.pattern})`;
|
|
934
936
|
}
|
|
@@ -1478,7 +1480,40 @@ function getMetricsReader() {
|
|
|
1478
1480
|
}
|
|
1479
1481
|
|
|
1480
1482
|
// src/internal/trace/tracing.ts
|
|
1481
|
-
var
|
|
1483
|
+
var import_exporter_trace_otlp_proto = require("@opentelemetry/exporter-trace-otlp-proto");
|
|
1484
|
+
|
|
1485
|
+
// src/internal/trace/exporters/span-exporter.ts
|
|
1486
|
+
var import_resources2 = require("@opentelemetry/resources");
|
|
1487
|
+
var BrizzSpanExporter = class {
|
|
1488
|
+
_delegate;
|
|
1489
|
+
_brizzResource;
|
|
1490
|
+
constructor(delegate, config) {
|
|
1491
|
+
this._delegate = delegate;
|
|
1492
|
+
const resourceAttrs = {
|
|
1493
|
+
"service.name": config.appName,
|
|
1494
|
+
[BRIZZ_SDK_VERSION]: getSDKVersion(),
|
|
1495
|
+
[BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
|
|
1496
|
+
};
|
|
1497
|
+
if (config.environment) {
|
|
1498
|
+
resourceAttrs["deployment.environment"] = config.environment;
|
|
1499
|
+
}
|
|
1500
|
+
this._brizzResource = (0, import_resources2.resourceFromAttributes)(resourceAttrs);
|
|
1501
|
+
}
|
|
1502
|
+
export(spans, resultCallback) {
|
|
1503
|
+
const patchedSpans = spans.map((span) => ({
|
|
1504
|
+
...span,
|
|
1505
|
+
resource: span.resource.merge(this._brizzResource),
|
|
1506
|
+
spanContext: span.spanContext.bind(span)
|
|
1507
|
+
}));
|
|
1508
|
+
this._delegate.export(patchedSpans, resultCallback);
|
|
1509
|
+
}
|
|
1510
|
+
async shutdown() {
|
|
1511
|
+
return this._delegate.shutdown();
|
|
1512
|
+
}
|
|
1513
|
+
async forceFlush() {
|
|
1514
|
+
return this._delegate.forceFlush?.();
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1482
1517
|
|
|
1483
1518
|
// src/internal/trace/processors/span-processor.ts
|
|
1484
1519
|
var import_api4 = require("@opentelemetry/api");
|
|
@@ -1605,16 +1640,17 @@ var TracingModule = class _TracingModule {
|
|
|
1605
1640
|
}
|
|
1606
1641
|
if (config.customSpanExporter) {
|
|
1607
1642
|
logger.debug("Using custom span exporter");
|
|
1608
|
-
this.spanExporter = config.customSpanExporter;
|
|
1643
|
+
this.spanExporter = new BrizzSpanExporter(config.customSpanExporter, config);
|
|
1609
1644
|
logger.debug("Custom span exporter initialized successfully");
|
|
1610
1645
|
return;
|
|
1611
1646
|
}
|
|
1612
1647
|
const tracesUrl = config.baseUrl.replace(/\/$/, "") + "/v1/traces";
|
|
1613
1648
|
logger.debug("Initializing default OTLP span exporter", { url: tracesUrl });
|
|
1614
|
-
|
|
1649
|
+
const otlpExporter = new import_exporter_trace_otlp_proto.OTLPTraceExporter({
|
|
1615
1650
|
url: tracesUrl,
|
|
1616
1651
|
headers: config.headers
|
|
1617
1652
|
});
|
|
1653
|
+
this.spanExporter = new BrizzSpanExporter(otlpExporter, config);
|
|
1618
1654
|
logger.debug("OTLP span exporter initialized successfully");
|
|
1619
1655
|
}
|
|
1620
1656
|
/**
|
|
@@ -1694,8 +1730,9 @@ function withProperties(properties, fn, thisArg) {
|
|
|
1694
1730
|
);
|
|
1695
1731
|
};
|
|
1696
1732
|
}
|
|
1697
|
-
function withSessionId(sessionId, fn, thisArg) {
|
|
1698
|
-
|
|
1733
|
+
function withSessionId(sessionId, fn, thisArg, extraProperties) {
|
|
1734
|
+
const properties = { [SESSION_ID]: sessionId, ...extraProperties };
|
|
1735
|
+
return withProperties(properties, fn, thisArg);
|
|
1699
1736
|
}
|
|
1700
1737
|
function callWithSessionId(sessionId, fn, thisArg, ...args) {
|
|
1701
1738
|
return callWithProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
|
|
@@ -1743,12 +1780,23 @@ var Session = class {
|
|
|
1743
1780
|
}
|
|
1744
1781
|
}
|
|
1745
1782
|
};
|
|
1746
|
-
function startSession(sessionId, callback) {
|
|
1783
|
+
function startSession(sessionId, callback, extraProperties) {
|
|
1747
1784
|
const tracer = import_api5.trace.getTracer("@brizz/sdk");
|
|
1748
1785
|
return tracer.startActiveSpan(SESSION_SPAN_NAME, (span) => {
|
|
1749
1786
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
1787
|
+
if (extraProperties) {
|
|
1788
|
+
for (const [key, value] of Object.entries(extraProperties)) {
|
|
1789
|
+
span.setAttribute(`${BRIZZ}.${key}`, value);
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1750
1792
|
const session = new Session(sessionId, span);
|
|
1751
|
-
|
|
1793
|
+
const contextProperties = { [SESSION_ID]: sessionId };
|
|
1794
|
+
if (extraProperties) {
|
|
1795
|
+
for (const [key, value] of Object.entries(extraProperties)) {
|
|
1796
|
+
contextProperties[key] = String(value);
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
return callWithProperties(contextProperties, () => {
|
|
1752
1800
|
try {
|
|
1753
1801
|
const result = callback(session);
|
|
1754
1802
|
if (result && typeof result.then === "function") {
|
|
@@ -1819,7 +1867,7 @@ var _Brizz = class __Brizz {
|
|
|
1819
1867
|
});
|
|
1820
1868
|
} catch (error) {
|
|
1821
1869
|
logger.error("Failed to initialize Brizz SDK", { error });
|
|
1822
|
-
throw new Error(`Failed to initialize SDK: ${String(error)}
|
|
1870
|
+
throw new Error(`Failed to initialize SDK: ${String(error)}`, { cause: error });
|
|
1823
1871
|
}
|
|
1824
1872
|
}
|
|
1825
1873
|
/**
|
|
@@ -1855,7 +1903,7 @@ var _Brizz = class __Brizz {
|
|
|
1855
1903
|
this._sdk = new import_sdk_node.NodeSDK({
|
|
1856
1904
|
spanProcessors: [getSpanProcessor()],
|
|
1857
1905
|
metricReader: getMetricsReader(),
|
|
1858
|
-
resource: (0,
|
|
1906
|
+
resource: (0, import_resources3.resourceFromAttributes)(resourceAttributes),
|
|
1859
1907
|
instrumentations: manualInstrumentations
|
|
1860
1908
|
});
|
|
1861
1909
|
this._sdk.start();
|