@brizz/sdk 0.1.13 → 0.1.15
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 +20 -0
- package/dist/index.cjs +45 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +44 -32
- package/dist/index.js.map +1 -1
- package/dist/preload.cjs +15 -10
- package/dist/preload.cjs.map +1 -1
- package/dist/preload.js +15 -10
- package/dist/preload.js.map +1 -1
- package/package.json +31 -29
package/README.md
CHANGED
|
@@ -313,6 +313,26 @@ await startSession('session-456', async (session) => {
|
|
|
313
313
|
});
|
|
314
314
|
```
|
|
315
315
|
|
|
316
|
+
### Accessing the Active Session
|
|
317
|
+
|
|
318
|
+
Use `getActiveSession()` to retrieve the current session from anywhere within a `startSession` scope — no need to pass the session object through your call stack:
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
import { startSession, getActiveSession } from '@brizz/sdk';
|
|
322
|
+
|
|
323
|
+
function deepHelper() {
|
|
324
|
+
const session = getActiveSession();
|
|
325
|
+
session?.updateProperties({ step: 'helper' });
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
await startSession('session-123', async () => {
|
|
329
|
+
deepHelper(); // accesses session without it being passed as a parameter
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// Outside a session, returns undefined
|
|
333
|
+
getActiveSession(); // undefined
|
|
334
|
+
```
|
|
335
|
+
|
|
316
336
|
### Function Wrapper Pattern
|
|
317
337
|
|
|
318
338
|
For simpler cases where you just need to tag traces with a session ID:
|
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(src_exports, {
|
|
|
39
39
|
callWithSessionId: () => callWithSessionId,
|
|
40
40
|
detectRuntime: () => detectRuntime,
|
|
41
41
|
emitEvent: () => emitEvent,
|
|
42
|
+
getActiveSession: () => getActiveSession,
|
|
42
43
|
getLogLevel: () => getLogLevel,
|
|
43
44
|
getMetricsExporter: () => getMetricsExporter,
|
|
44
45
|
getMetricsReader: () => getMetricsReader,
|
|
@@ -368,7 +369,6 @@ var BRIZZ_SDK_LANGUAGE = "brizz.sdk.language";
|
|
|
368
369
|
var SDK_LANGUAGE = "typescript";
|
|
369
370
|
|
|
370
371
|
// src/internal/instrumentation/registry.ts
|
|
371
|
-
var import_openinference_instrumentation_langchain = require("@arizeai/openinference-instrumentation-langchain");
|
|
372
372
|
var import_instrumentation_anthropic2 = require("@traceloop/instrumentation-anthropic");
|
|
373
373
|
var import_instrumentation_bedrock2 = require("@traceloop/instrumentation-bedrock");
|
|
374
374
|
var import_instrumentation_chromadb2 = require("@traceloop/instrumentation-chromadb");
|
|
@@ -469,14 +469,19 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
469
469
|
}
|
|
470
470
|
}
|
|
471
471
|
if (this.manualModules?.langchain?.callbackManagerModule) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
472
|
+
const callbackManagerModule = this.manualModules.langchain.callbackManagerModule;
|
|
473
|
+
void (async () => {
|
|
474
|
+
try {
|
|
475
|
+
const { LangChainInstrumentation } = await import("@arizeai/openinference-instrumentation-langchain");
|
|
476
|
+
const lcInst = new LangChainInstrumentation();
|
|
477
|
+
lcInst.manuallyInstrument(callbackManagerModule);
|
|
478
|
+
logger.debug("Manual instrumentation enabled for LangChain");
|
|
479
|
+
} catch (error) {
|
|
480
|
+
logger.error(
|
|
481
|
+
`Failed to load LangChain instrumentation. Ensure @langchain/core is installed: ${String(error)}`
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
})();
|
|
480
485
|
}
|
|
481
486
|
}
|
|
482
487
|
};
|
|
@@ -489,7 +494,7 @@ var import_sdk_logs2 = require("@opentelemetry/sdk-logs");
|
|
|
489
494
|
|
|
490
495
|
// src/internal/version.ts
|
|
491
496
|
function getSDKVersion() {
|
|
492
|
-
return "0.1.
|
|
497
|
+
return "0.1.15";
|
|
493
498
|
}
|
|
494
499
|
|
|
495
500
|
// src/internal/log/processors/log-processor.ts
|
|
@@ -1126,6 +1131,7 @@ var BRIZZ = "brizz";
|
|
|
1126
1131
|
var PROPERTIES = "properties";
|
|
1127
1132
|
var SESSION_ID = "session.id";
|
|
1128
1133
|
var PROPERTIES_CONTEXT_KEY = (0, import_api2.createContextKey)(PROPERTIES);
|
|
1134
|
+
var SESSION_OBJECT_CONTEXT_KEY = (0, import_api2.createContextKey)("brizz.session.object");
|
|
1129
1135
|
var SESSION_INPUT = "brizz.session.input";
|
|
1130
1136
|
var SESSION_OUTPUT = "brizz.session.output";
|
|
1131
1137
|
var SESSION_SPAN_NAME = "brizz.start_session";
|
|
@@ -1758,7 +1764,7 @@ var Session = class {
|
|
|
1758
1764
|
* Use when you need to track specific input data that differs from what's sent to the LLM.
|
|
1759
1765
|
* Multiple calls accumulate in an array.
|
|
1760
1766
|
*
|
|
1761
|
-
* @param text - Text to append to session input
|
|
1767
|
+
* @param text - Text to append to session input, or null to append null
|
|
1762
1768
|
*/
|
|
1763
1769
|
setInput(text) {
|
|
1764
1770
|
this.inputs.push(text);
|
|
@@ -1769,7 +1775,7 @@ var Session = class {
|
|
|
1769
1775
|
* Use when you need to track specific output data that differs from what's received from the LLM.
|
|
1770
1776
|
* Multiple calls accumulate in an array.
|
|
1771
1777
|
*
|
|
1772
|
-
* @param text - Text to append to session output
|
|
1778
|
+
* @param text - Text to append to session output, or null to append null
|
|
1773
1779
|
*/
|
|
1774
1780
|
setOutput(text) {
|
|
1775
1781
|
this.outputs.push(text);
|
|
@@ -1787,6 +1793,9 @@ var Session = class {
|
|
|
1787
1793
|
}
|
|
1788
1794
|
}
|
|
1789
1795
|
};
|
|
1796
|
+
function getActiveSession() {
|
|
1797
|
+
return import_api5.context.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
|
|
1798
|
+
}
|
|
1790
1799
|
function startSession(sessionId, callback, extraProperties) {
|
|
1791
1800
|
const tracer = import_api5.trace.getTracer("@brizz/sdk");
|
|
1792
1801
|
return tracer.startActiveSpan(SESSION_SPAN_NAME, (span) => {
|
|
@@ -1804,27 +1813,30 @@ function startSession(sessionId, callback, extraProperties) {
|
|
|
1804
1813
|
}
|
|
1805
1814
|
}
|
|
1806
1815
|
return callWithProperties(contextProperties, () => {
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
return value
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1816
|
+
const sessionCtx = import_api5.context.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
|
|
1817
|
+
return import_api5.context.with(sessionCtx, () => {
|
|
1818
|
+
try {
|
|
1819
|
+
const result = callback(session);
|
|
1820
|
+
if (result && typeof result.then === "function") {
|
|
1821
|
+
return result.then((value) => {
|
|
1822
|
+
span.end();
|
|
1823
|
+
return value;
|
|
1824
|
+
}).catch((error) => {
|
|
1825
|
+
span.recordException(error);
|
|
1826
|
+
span.setStatus({ code: import_api5.SpanStatusCode.ERROR });
|
|
1827
|
+
span.end();
|
|
1828
|
+
throw error;
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
span.end();
|
|
1832
|
+
return result;
|
|
1833
|
+
} catch (error) {
|
|
1834
|
+
span.recordException(error);
|
|
1835
|
+
span.setStatus({ code: import_api5.SpanStatusCode.ERROR });
|
|
1836
|
+
span.end();
|
|
1837
|
+
throw error;
|
|
1819
1838
|
}
|
|
1820
|
-
|
|
1821
|
-
return result;
|
|
1822
|
-
} catch (error) {
|
|
1823
|
-
span.recordException(error);
|
|
1824
|
-
span.setStatus({ code: import_api5.SpanStatusCode.ERROR });
|
|
1825
|
-
span.end();
|
|
1826
|
-
throw error;
|
|
1827
|
-
}
|
|
1839
|
+
});
|
|
1828
1840
|
});
|
|
1829
1841
|
});
|
|
1830
1842
|
}
|
|
@@ -2084,6 +2096,7 @@ var init_exports = {};
|
|
|
2084
2096
|
callWithSessionId,
|
|
2085
2097
|
detectRuntime,
|
|
2086
2098
|
emitEvent,
|
|
2099
|
+
getActiveSession,
|
|
2087
2100
|
getLogLevel,
|
|
2088
2101
|
getMetricsExporter,
|
|
2089
2102
|
getMetricsReader,
|