@brizz/sdk 0.1.9 → 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/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('session-123', async (session) => {
271
- // Add custom properties (optional)
272
- session.updateProperties({ userId: 'user-456', model: 'gpt-4' });
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
- const response = await openai.chat.completions.create({
275
- model: 'gpt-4',
276
- messages: [{ role: 'user', content: userQuery }],
277
- });
276
+ const response = await openai.chat.completions.create({
277
+ model: 'gpt-4',
278
+ messages: [{ role: 'user', content: userQuery }],
279
+ });
278
280
 
279
- return response;
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
- const sessionedWorkflow = withSessionId('session-123', processUserWorkflow);
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
@@ -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.9";
485
+ return "0.1.10";
486
486
  }
487
487
 
488
488
  // src/internal/log/processors/log-processor.ts
@@ -1478,7 +1478,7 @@ function getMetricsReader() {
1478
1478
  }
1479
1479
 
1480
1480
  // src/internal/trace/tracing.ts
1481
- var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
1481
+ var import_exporter_trace_otlp_proto = require("@opentelemetry/exporter-trace-otlp-proto");
1482
1482
 
1483
1483
  // src/internal/trace/processors/span-processor.ts
1484
1484
  var import_api4 = require("@opentelemetry/api");
@@ -1611,7 +1611,7 @@ var TracingModule = class _TracingModule {
1611
1611
  }
1612
1612
  const tracesUrl = config.baseUrl.replace(/\/$/, "") + "/v1/traces";
1613
1613
  logger.debug("Initializing default OTLP span exporter", { url: tracesUrl });
1614
- this.spanExporter = new import_exporter_trace_otlp_http.OTLPTraceExporter({
1614
+ this.spanExporter = new import_exporter_trace_otlp_proto.OTLPTraceExporter({
1615
1615
  url: tracesUrl,
1616
1616
  headers: config.headers
1617
1617
  });
@@ -1694,8 +1694,9 @@ function withProperties(properties, fn, thisArg) {
1694
1694
  );
1695
1695
  };
1696
1696
  }
1697
- function withSessionId(sessionId, fn, thisArg) {
1698
- return withProperties({ [SESSION_ID]: sessionId }, fn, thisArg);
1697
+ function withSessionId(sessionId, fn, thisArg, extraProperties) {
1698
+ const properties = { [SESSION_ID]: sessionId, ...extraProperties };
1699
+ return withProperties(properties, fn, thisArg);
1699
1700
  }
1700
1701
  function callWithSessionId(sessionId, fn, thisArg, ...args) {
1701
1702
  return callWithProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
@@ -1743,12 +1744,23 @@ var Session = class {
1743
1744
  }
1744
1745
  }
1745
1746
  };
1746
- function startSession(sessionId, callback) {
1747
+ function startSession(sessionId, callback, extraProperties) {
1747
1748
  const tracer = import_api5.trace.getTracer("@brizz/sdk");
1748
1749
  return tracer.startActiveSpan(SESSION_SPAN_NAME, (span) => {
1749
1750
  span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
1751
+ if (extraProperties) {
1752
+ for (const [key, value] of Object.entries(extraProperties)) {
1753
+ span.setAttribute(`${BRIZZ}.${key}`, value);
1754
+ }
1755
+ }
1750
1756
  const session = new Session(sessionId, span);
1751
- return callWithProperties({ [SESSION_ID]: sessionId }, () => {
1757
+ const contextProperties = { [SESSION_ID]: sessionId };
1758
+ if (extraProperties) {
1759
+ for (const [key, value] of Object.entries(extraProperties)) {
1760
+ contextProperties[key] = String(value);
1761
+ }
1762
+ }
1763
+ return callWithProperties(contextProperties, () => {
1752
1764
  try {
1753
1765
  const result = callback(session);
1754
1766
  if (result && typeof result.then === "function") {