@brizz/sdk 0.1.52 → 0.1.53
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/dist/{chunk-2T7OEV33.cjs → chunk-STTOBCTP.cjs} +1 -1
- package/dist/{chunk-W7VSQ4KQ.js → chunk-XV3ZJO5K.js} +1 -1
- package/dist/index.cjs +304 -73
- package/dist/index.js +284 -53
- package/dist/{mcp-TOZFTC5Y.js → mcp-DBLN5ZBE.js} +1 -1
- package/dist/{mcp-MVZSP5NE.cjs → mcp-KH5LOG5H.cjs} +11 -11
- package/dist/types/cjs/internal/instrumentation/registry.d.ts +1 -0
- package/dist/types/cjs/internal/instrumentation/typesafe.d.ts +34 -0
- package/dist/types/esm/internal/instrumentation/registry.d.ts +1 -0
- package/dist/types/esm/internal/instrumentation/typesafe.d.ts +34 -0
- package/package.json +9 -3
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
configure,
|
|
7
7
|
getSDKVersion
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-XV3ZJO5K.js";
|
|
9
9
|
import {
|
|
10
10
|
DEFAULT_LOG_LEVEL,
|
|
11
11
|
LogLevel,
|
|
@@ -426,6 +426,217 @@ function attachRunToIteration(stream, run) {
|
|
|
426
426
|
return iterable;
|
|
427
427
|
}
|
|
428
428
|
|
|
429
|
+
// src/internal/instrumentation/typesafe.ts
|
|
430
|
+
import { createRequire as createRequire2 } from "module";
|
|
431
|
+
import { SpanKind, SpanStatusCode as SpanStatusCode2, context as context2, trace as trace2 } from "@opentelemetry/api";
|
|
432
|
+
import {
|
|
433
|
+
InstrumentationBase as InstrumentationBase2,
|
|
434
|
+
InstrumentationNodeModuleDefinition as InstrumentationNodeModuleDefinition2
|
|
435
|
+
} from "@opentelemetry/instrumentation";
|
|
436
|
+
var INSTRUMENTATION_NAME2 = "@brizz/sdk/typesafe";
|
|
437
|
+
var MODULE_NAME2 = "@typesafe-ai/sdk";
|
|
438
|
+
var SUPPORTED_VERSIONS2 = [">=0.5.7 <1"];
|
|
439
|
+
var SPAN_NAME = "typesafe.system_one";
|
|
440
|
+
var PROVIDER_NAME = "typesafe";
|
|
441
|
+
var OPERATION_NAME = "classify";
|
|
442
|
+
var ATTR_OPERATION_NAME = "gen_ai.operation.name";
|
|
443
|
+
var ATTR_PROVIDER_NAME = "gen_ai.provider.name";
|
|
444
|
+
var ATTR_REQUEST_MODEL = "gen_ai.request.model";
|
|
445
|
+
var ATTR_RESPONSE_MODEL = "gen_ai.response.model";
|
|
446
|
+
var ATTR_INPUT_TOKENS = "gen_ai.usage.input_tokens";
|
|
447
|
+
var ATTR_OUTPUT_TOKENS = "gen_ai.usage.output_tokens";
|
|
448
|
+
var ATTR_INPUT_MESSAGES = "gen_ai.input.messages";
|
|
449
|
+
var ATTR_QUESTIONS = "typesafe.questions";
|
|
450
|
+
var ATTR_ANSWERS = "typesafe.answers";
|
|
451
|
+
var PATCHED_FLAG2 = /* @__PURE__ */ Symbol.for("brizz.typesafe.patched");
|
|
452
|
+
var TypeSafeInstrumentation = class extends InstrumentationBase2 {
|
|
453
|
+
constructor(config = {}) {
|
|
454
|
+
super(INSTRUMENTATION_NAME2, getSDKVersion(), config);
|
|
455
|
+
}
|
|
456
|
+
init() {
|
|
457
|
+
return [
|
|
458
|
+
new InstrumentationNodeModuleDefinition2(
|
|
459
|
+
MODULE_NAME2,
|
|
460
|
+
SUPPORTED_VERSIONS2,
|
|
461
|
+
(moduleExports) => {
|
|
462
|
+
this.manuallyInstrument(moduleExports);
|
|
463
|
+
return moduleExports;
|
|
464
|
+
},
|
|
465
|
+
(moduleExports) => moduleExports
|
|
466
|
+
)
|
|
467
|
+
];
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Patch a `@typesafe-ai/sdk` module the caller already imported. The
|
|
471
|
+
* module-load hook above only fires for CommonJS requires, so an ESM or
|
|
472
|
+
* bundled consumer reaches the instrumentation through here — from
|
|
473
|
+
* `patchInstalledTypeSafe`, or `instrumentModules: { typesafe }`.
|
|
474
|
+
*/
|
|
475
|
+
manuallyInstrument(moduleExports) {
|
|
476
|
+
const client = moduleExports?.TypeSafeClient;
|
|
477
|
+
if (typeof client !== "function" || !client.prototype) {
|
|
478
|
+
logger.debug("Brizz TypeSafe: module does not expose TypeSafeClient \u2014 skipping patch");
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
if (patchSystemOne(client.prototype, () => this.tracer)) {
|
|
482
|
+
logger.debug("Brizz TypeSafe: patched TypeSafeClient.systemOne");
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
function patchInstalledTypeSafe() {
|
|
487
|
+
let requireFromSdk;
|
|
488
|
+
let version;
|
|
489
|
+
try {
|
|
490
|
+
requireFromSdk = createRequire2(import.meta.url);
|
|
491
|
+
version = requireFromSdk(`${MODULE_NAME2}/package.json`).version;
|
|
492
|
+
} catch (error) {
|
|
493
|
+
logger.debug(`TypeSafe not resolved, not patched: ${String(error)}`);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (!isSupportedVersion2(version)) {
|
|
497
|
+
logger.debug(`TypeSafe ${version} is outside ${SUPPORTED_VERSIONS2.join(" ")}, not patched`);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
let instrumentation;
|
|
501
|
+
try {
|
|
502
|
+
instrumentation = new TypeSafeInstrumentation({ enabled: false });
|
|
503
|
+
} catch (error) {
|
|
504
|
+
logger.debug(`TypeSafe instrumentation not constructed: ${String(error)}`);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
try {
|
|
508
|
+
const loaded = requireFromSdk.cache[requireFromSdk.resolve(MODULE_NAME2)];
|
|
509
|
+
if (loaded) {
|
|
510
|
+
instrumentation.manuallyInstrument(loaded.exports);
|
|
511
|
+
}
|
|
512
|
+
} catch (error) {
|
|
513
|
+
logger.debug(`TypeSafe CJS build not patched: ${String(error)}`);
|
|
514
|
+
}
|
|
515
|
+
void (async () => {
|
|
516
|
+
try {
|
|
517
|
+
instrumentation.manuallyInstrument(await import("@typesafe-ai/sdk"));
|
|
518
|
+
} catch (error) {
|
|
519
|
+
logger.debug(`TypeSafe not patched: ${String(error)}`);
|
|
520
|
+
}
|
|
521
|
+
})();
|
|
522
|
+
}
|
|
523
|
+
function isSupportedVersion2(version) {
|
|
524
|
+
const [major, minor, patch] = version.split(".").map((part) => Number.parseInt(part, 10));
|
|
525
|
+
if ([major, minor, patch].some((part) => part === void 0 || Number.isNaN(part))) {
|
|
526
|
+
return false;
|
|
527
|
+
}
|
|
528
|
+
return major === 0 && (minor > 5 || minor === 5 && patch >= 7);
|
|
529
|
+
}
|
|
530
|
+
function patchSystemOne(proto, getTracer) {
|
|
531
|
+
const target = proto;
|
|
532
|
+
const original = proto.systemOne;
|
|
533
|
+
if (target[PATCHED_FLAG2] || typeof original !== "function") {
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
proto.systemOne = function brizzSystemOne(request, ...rest) {
|
|
537
|
+
const span = startSpan(getTracer, request);
|
|
538
|
+
if (!span) {
|
|
539
|
+
return original.call(this, request, ...rest);
|
|
540
|
+
}
|
|
541
|
+
let pending;
|
|
542
|
+
try {
|
|
543
|
+
pending = context2.with(
|
|
544
|
+
trace2.setSpan(context2.active(), span),
|
|
545
|
+
() => original.call(this, request, ...rest)
|
|
546
|
+
);
|
|
547
|
+
} catch (error) {
|
|
548
|
+
endSpan(span, error);
|
|
549
|
+
throw error;
|
|
550
|
+
}
|
|
551
|
+
return observe(pending, span);
|
|
552
|
+
};
|
|
553
|
+
target[PATCHED_FLAG2] = true;
|
|
554
|
+
return true;
|
|
555
|
+
}
|
|
556
|
+
function observe(pending, span) {
|
|
557
|
+
const onError = (error) => endSpan(span, error);
|
|
558
|
+
try {
|
|
559
|
+
if (typeof pending?.asResponse === "function") {
|
|
560
|
+
pending.asResponse().then((response) => {
|
|
561
|
+
if (typeof response?.clone !== "function") {
|
|
562
|
+
endSpan(span);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
response.clone().json().then((body) => {
|
|
566
|
+
recordResult(span, body);
|
|
567
|
+
endSpan(span);
|
|
568
|
+
}, onError);
|
|
569
|
+
}, onError);
|
|
570
|
+
return pending;
|
|
571
|
+
}
|
|
572
|
+
if (typeof pending?.then === "function") {
|
|
573
|
+
pending.then((result) => {
|
|
574
|
+
recordResult(span, result);
|
|
575
|
+
endSpan(span);
|
|
576
|
+
}, onError);
|
|
577
|
+
return pending;
|
|
578
|
+
}
|
|
579
|
+
} catch (error) {
|
|
580
|
+
logger.debug(`Brizz TypeSafe: could not observe the call: ${String(error)}`);
|
|
581
|
+
}
|
|
582
|
+
endSpan(span);
|
|
583
|
+
return pending;
|
|
584
|
+
}
|
|
585
|
+
function startSpan(getTracer, request) {
|
|
586
|
+
try {
|
|
587
|
+
const model = typeof request?.model === "string" && request.model !== "" ? request.model : void 0;
|
|
588
|
+
const attributes = {
|
|
589
|
+
[ATTR_OPERATION_NAME]: OPERATION_NAME,
|
|
590
|
+
[ATTR_PROVIDER_NAME]: PROVIDER_NAME,
|
|
591
|
+
[ATTR_INPUT_MESSAGES]: JSON.stringify([
|
|
592
|
+
{ role: "user", parts: [{ type: "text", content: text(request?.state) }] }
|
|
593
|
+
])
|
|
594
|
+
};
|
|
595
|
+
if (model) {
|
|
596
|
+
attributes[ATTR_REQUEST_MODEL] = model;
|
|
597
|
+
}
|
|
598
|
+
if (request?.questions !== void 0) {
|
|
599
|
+
attributes[ATTR_QUESTIONS] = JSON.stringify(request.questions);
|
|
600
|
+
}
|
|
601
|
+
return getTracer().startSpan(SPAN_NAME, { kind: SpanKind.CLIENT, attributes });
|
|
602
|
+
} catch (error) {
|
|
603
|
+
logger.debug(`Brizz TypeSafe: could not start span: ${String(error)}`);
|
|
604
|
+
return void 0;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
function recordResult(span, result) {
|
|
608
|
+
try {
|
|
609
|
+
const { model, usage, answers } = result ?? {};
|
|
610
|
+
if (typeof model === "string" && model) {
|
|
611
|
+
span.setAttribute(ATTR_RESPONSE_MODEL, model);
|
|
612
|
+
}
|
|
613
|
+
if (typeof usage?.input_tokens === "number") {
|
|
614
|
+
span.setAttribute(ATTR_INPUT_TOKENS, usage.input_tokens);
|
|
615
|
+
}
|
|
616
|
+
if (typeof usage?.output_tokens === "number") {
|
|
617
|
+
span.setAttribute(ATTR_OUTPUT_TOKENS, usage.output_tokens);
|
|
618
|
+
}
|
|
619
|
+
if (answers !== void 0) {
|
|
620
|
+
span.setAttribute(ATTR_ANSWERS, JSON.stringify(answers));
|
|
621
|
+
}
|
|
622
|
+
} catch (error) {
|
|
623
|
+
logger.debug(`Brizz TypeSafe: could not record the answers: ${String(error)}`);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
function endSpan(span, error) {
|
|
627
|
+
if (!span.isRecording()) {
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
if (error !== void 0) {
|
|
631
|
+
span.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
632
|
+
span.setStatus({ code: SpanStatusCode2.ERROR, message: String(error) });
|
|
633
|
+
}
|
|
634
|
+
span.end();
|
|
635
|
+
}
|
|
636
|
+
function text(value) {
|
|
637
|
+
return typeof value === "string" ? value : JSON.stringify(value) ?? "";
|
|
638
|
+
}
|
|
639
|
+
|
|
429
640
|
// src/internal/instrumentation/auto-init.ts
|
|
430
641
|
var exceptionLogger = (error) => {
|
|
431
642
|
logger.error(`Exception in instrumentation: ${String(error)}`);
|
|
@@ -468,7 +679,7 @@ function loadGenAIInstrumentations() {
|
|
|
468
679
|
function loadMCPInstrumentation() {
|
|
469
680
|
void (async () => {
|
|
470
681
|
try {
|
|
471
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
682
|
+
const { MCPInstrumentation } = await import("./mcp-DBLN5ZBE.js");
|
|
472
683
|
const mcp = new MCPInstrumentation({ exceptionLogger });
|
|
473
684
|
registerInstrumentations({ instrumentations: [mcp] });
|
|
474
685
|
logger.debug("Auto-loaded MCP instrumentation");
|
|
@@ -487,6 +698,14 @@ function loadLangGraphInstrumentation() {
|
|
|
487
698
|
logger.debug(`LangGraph instrumentation not loaded: ${String(error)}`);
|
|
488
699
|
}
|
|
489
700
|
}
|
|
701
|
+
function loadTypeSafeInstrumentation() {
|
|
702
|
+
try {
|
|
703
|
+
registerInstrumentations({ instrumentations: [new TypeSafeInstrumentation()] });
|
|
704
|
+
logger.debug("Auto-loaded TypeSafe instrumentation");
|
|
705
|
+
} catch (error) {
|
|
706
|
+
logger.debug(`TypeSafe instrumentation not loaded: ${String(error)}`);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
490
709
|
function loadVertexAIInstrumentation() {
|
|
491
710
|
void (async () => {
|
|
492
711
|
try {
|
|
@@ -565,6 +784,7 @@ function autoInitializeInstrumentations() {
|
|
|
565
784
|
const genAIInstrumentations = loadGenAIInstrumentations();
|
|
566
785
|
loadMCPInstrumentation();
|
|
567
786
|
loadLangGraphInstrumentation();
|
|
787
|
+
loadTypeSafeInstrumentation();
|
|
568
788
|
loadVertexAIInstrumentation();
|
|
569
789
|
loadGoogleGenAIInstrumentation();
|
|
570
790
|
loadVercelAITelemetry();
|
|
@@ -743,8 +963,8 @@ import { QdrantInstrumentation as QdrantInstrumentation2 } from "@traceloop/inst
|
|
|
743
963
|
import { TogetherInstrumentation as TogetherInstrumentation2 } from "@traceloop/instrumentation-together";
|
|
744
964
|
|
|
745
965
|
// src/internal/instrumentation/langchain.ts
|
|
746
|
-
import { createRequire as
|
|
747
|
-
import { context as
|
|
966
|
+
import { createRequire as createRequire3 } from "module";
|
|
967
|
+
import { context as context3 } from "@opentelemetry/api";
|
|
748
968
|
var SCOPE_NAME = "@arizeai/openinference-instrumentation-langchain";
|
|
749
969
|
var PATCHED_MARKER = /* @__PURE__ */ Symbol.for("brizz.langchain.callbackManagerPatched");
|
|
750
970
|
var OMITTED_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -757,7 +977,7 @@ var TOOL_CALL_ID_METADATA_KEY = "brizz_tool_call_id";
|
|
|
757
977
|
var TOOL_ID = "tool.id";
|
|
758
978
|
var TOOL_CALL_ID_ARG = 7;
|
|
759
979
|
function runMetadataFromContext() {
|
|
760
|
-
const bag =
|
|
980
|
+
const bag = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
761
981
|
if (!bag) {
|
|
762
982
|
return void 0;
|
|
763
983
|
}
|
|
@@ -829,7 +1049,7 @@ function patchInstalledCallbackManager() {
|
|
|
829
1049
|
logger.debug(`LangChain callback manager not patched: ${String(error)}`);
|
|
830
1050
|
}
|
|
831
1051
|
try {
|
|
832
|
-
const requireFromSdk =
|
|
1052
|
+
const requireFromSdk = createRequire3(import.meta.url);
|
|
833
1053
|
patchCallbackManagerModule(requireFromSdk("@langchain/core/callbacks/manager"));
|
|
834
1054
|
} catch (error) {
|
|
835
1055
|
logger.debug(`LangChain CJS callback manager not patched: ${String(error)}`);
|
|
@@ -961,6 +1181,14 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
961
1181
|
logger.error(`Failed to apply LangGraph instrumentation: ${String(error)}`);
|
|
962
1182
|
}
|
|
963
1183
|
}
|
|
1184
|
+
if (this.manualModules?.typesafe) {
|
|
1185
|
+
try {
|
|
1186
|
+
new TypeSafeInstrumentation().manuallyInstrument(this.manualModules.typesafe);
|
|
1187
|
+
logger.debug("Manual instrumentation enabled for TypeSafe");
|
|
1188
|
+
} catch (error) {
|
|
1189
|
+
logger.error(`Failed to apply TypeSafe instrumentation: ${String(error)}`);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
964
1192
|
if (this.manualModules?.google_vertexai) {
|
|
965
1193
|
const vertexModule = this.manualModules.google_vertexai;
|
|
966
1194
|
void (async () => {
|
|
@@ -995,7 +1223,7 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
995
1223
|
const mcpModules = this.manualModules.mcp;
|
|
996
1224
|
void (async () => {
|
|
997
1225
|
try {
|
|
998
|
-
const { MCPInstrumentation } = await import("./mcp-
|
|
1226
|
+
const { MCPInstrumentation } = await import("./mcp-DBLN5ZBE.js");
|
|
999
1227
|
const instrumentation = new MCPInstrumentation({ exceptionLogger: exceptionLogger2 });
|
|
1000
1228
|
instrumentation.manuallyInstrument(mcpModules);
|
|
1001
1229
|
logger.debug("Manual instrumentation enabled for MCP");
|
|
@@ -1038,9 +1266,9 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
|
1038
1266
|
import { LoggerProvider } from "@opentelemetry/sdk-logs";
|
|
1039
1267
|
|
|
1040
1268
|
// src/internal/trace/session.ts
|
|
1041
|
-
import { context as
|
|
1269
|
+
import { context as context4, isSpanContextValid, trace as trace3, SpanStatusCode as SpanStatusCode3 } from "@opentelemetry/api";
|
|
1042
1270
|
function setCurrentSpanCustomProperties(properties) {
|
|
1043
|
-
const current =
|
|
1271
|
+
const current = trace3.getActiveSpan();
|
|
1044
1272
|
if (!current || !current.isRecording()) {
|
|
1045
1273
|
return;
|
|
1046
1274
|
}
|
|
@@ -1052,11 +1280,11 @@ function setCurrentSpanCustomProperties(properties) {
|
|
|
1052
1280
|
}
|
|
1053
1281
|
}
|
|
1054
1282
|
function callWithProperties(properties, fn, thisArg, ...args) {
|
|
1055
|
-
const base =
|
|
1283
|
+
const base = context4.active();
|
|
1056
1284
|
const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
|
|
1057
1285
|
const merged = prev ? { ...prev, ...properties } : properties;
|
|
1058
1286
|
const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
|
|
1059
|
-
return
|
|
1287
|
+
return context4.with(next, fn, thisArg, ...args);
|
|
1060
1288
|
}
|
|
1061
1289
|
function withProperties(properties, fn, thisArg) {
|
|
1062
1290
|
return function wrapped(...args) {
|
|
@@ -1068,9 +1296,9 @@ function withProperties(properties, fn, thisArg) {
|
|
|
1068
1296
|
);
|
|
1069
1297
|
};
|
|
1070
1298
|
}
|
|
1071
|
-
function propagatePropertiesImperatively(properties, base =
|
|
1299
|
+
function propagatePropertiesImperatively(properties, base = context4.active()) {
|
|
1072
1300
|
try {
|
|
1073
|
-
const manager =
|
|
1301
|
+
const manager = context4;
|
|
1074
1302
|
const mgr = manager._getContextManager?.();
|
|
1075
1303
|
const store = mgr?._asyncLocalStorage;
|
|
1076
1304
|
if (!store || typeof store.enterWith !== "function") {
|
|
@@ -1173,7 +1401,7 @@ function withServiceName(name, fn, thisArg) {
|
|
|
1173
1401
|
return withProperties(serviceNameProperties(name), fn, thisArg);
|
|
1174
1402
|
}
|
|
1175
1403
|
function resolveServiceNameFromContext() {
|
|
1176
|
-
const props =
|
|
1404
|
+
const props = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1177
1405
|
return props?.[SERVICE_NAME];
|
|
1178
1406
|
}
|
|
1179
1407
|
function userProperties(user) {
|
|
@@ -1240,7 +1468,7 @@ function withMessageId(id, fn, thisArg) {
|
|
|
1240
1468
|
return withProperties({ [MESSAGE_ID]: id }, fn, thisArg);
|
|
1241
1469
|
}
|
|
1242
1470
|
function inheritedMuteTools() {
|
|
1243
|
-
const properties =
|
|
1471
|
+
const properties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1244
1472
|
return properties?.[MUTE_TOOLS];
|
|
1245
1473
|
}
|
|
1246
1474
|
function muteProperties(options) {
|
|
@@ -1300,9 +1528,9 @@ var Session = class {
|
|
|
1300
1528
|
* @param text - Text to append (null becomes a null/"hide marker")
|
|
1301
1529
|
* @param context - Optional per-turn context bag to attach to this turn
|
|
1302
1530
|
*/
|
|
1303
|
-
setInput(
|
|
1304
|
-
this.inputs.push(
|
|
1305
|
-
this.inputContexts.push(
|
|
1531
|
+
setInput(text2, context8) {
|
|
1532
|
+
this.inputs.push(text2);
|
|
1533
|
+
this.inputContexts.push(context8 ?? {});
|
|
1306
1534
|
this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
|
|
1307
1535
|
this.span.setAttribute(SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
|
|
1308
1536
|
}
|
|
@@ -1316,9 +1544,9 @@ var Session = class {
|
|
|
1316
1544
|
* @param text - Text to append (null becomes a null/"hide marker")
|
|
1317
1545
|
* @param context - Optional per-turn context bag to attach to this turn
|
|
1318
1546
|
*/
|
|
1319
|
-
setOutput(
|
|
1320
|
-
this.outputs.push(
|
|
1321
|
-
this.outputContexts.push(
|
|
1547
|
+
setOutput(text2, context8) {
|
|
1548
|
+
this.outputs.push(text2);
|
|
1549
|
+
this.outputContexts.push(context8 ?? {});
|
|
1322
1550
|
this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
|
|
1323
1551
|
this.span.setAttribute(SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
|
|
1324
1552
|
}
|
|
@@ -1421,18 +1649,18 @@ var SessionTitle = class {
|
|
|
1421
1649
|
}
|
|
1422
1650
|
};
|
|
1423
1651
|
function getActiveSession() {
|
|
1424
|
-
return
|
|
1652
|
+
return context4.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
|
|
1425
1653
|
}
|
|
1426
1654
|
function resolveSessionIdFromContext() {
|
|
1427
1655
|
const active = getActiveSession();
|
|
1428
1656
|
if (active) {
|
|
1429
1657
|
return active.sessionId;
|
|
1430
1658
|
}
|
|
1431
|
-
const props =
|
|
1659
|
+
const props = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1432
1660
|
return props?.[SESSION_ID];
|
|
1433
1661
|
}
|
|
1434
1662
|
function resolveMessageIdFromContext() {
|
|
1435
|
-
const props =
|
|
1663
|
+
const props = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1436
1664
|
return props?.[MESSAGE_ID];
|
|
1437
1665
|
}
|
|
1438
1666
|
function emitExternalLink(sessionId, url, title, linkType) {
|
|
@@ -1614,14 +1842,14 @@ function recordMetricImpl(options) {
|
|
|
1614
1842
|
);
|
|
1615
1843
|
continue;
|
|
1616
1844
|
}
|
|
1617
|
-
let
|
|
1618
|
-
if (
|
|
1845
|
+
let text2 = typeof attrValue === "string" ? attrValue : String(attrValue);
|
|
1846
|
+
if (text2.length > METRIC_ATTRIBUTE_VALUE_MAX_LEN) {
|
|
1619
1847
|
logger.warn(
|
|
1620
1848
|
`recordMetric(${name}) attribute ${JSON.stringify(normalizedKey)} exceeds ${METRIC_ATTRIBUTE_VALUE_MAX_LEN} characters; truncated.`
|
|
1621
1849
|
);
|
|
1622
|
-
|
|
1850
|
+
text2 = text2.slice(0, METRIC_ATTRIBUTE_VALUE_MAX_LEN);
|
|
1623
1851
|
}
|
|
1624
|
-
eventAttributes[`${METRIC_ATTRIBUTE_PREFIX}${normalizedKey}`] =
|
|
1852
|
+
eventAttributes[`${METRIC_ATTRIBUTE_PREFIX}${normalizedKey}`] = text2;
|
|
1625
1853
|
accepted += 1;
|
|
1626
1854
|
}
|
|
1627
1855
|
}
|
|
@@ -1630,7 +1858,7 @@ function recordMetricImpl(options) {
|
|
|
1630
1858
|
eventAttributes[METRIC_TRACE_ID] = traceId;
|
|
1631
1859
|
}
|
|
1632
1860
|
if (scope === METRIC_SCOPE_TRACE && traceId === void 0) {
|
|
1633
|
-
const spanContext =
|
|
1861
|
+
const spanContext = trace3.getActiveSpan()?.spanContext();
|
|
1634
1862
|
if (!spanContext || !isSpanContextValid(spanContext)) {
|
|
1635
1863
|
logger.warn(
|
|
1636
1864
|
`recordMetric(${name}) called with scope 'trace' but no trace; metric dropped. Pass options.traceId, or call inside the span of the trace being scored.`
|
|
@@ -1646,7 +1874,7 @@ function recordMetricImpl(options) {
|
|
|
1646
1874
|
);
|
|
1647
1875
|
return;
|
|
1648
1876
|
}
|
|
1649
|
-
const base =
|
|
1877
|
+
const base = context4.active();
|
|
1650
1878
|
const ambient = base.getValue(PROPERTIES_CONTEXT_KEY);
|
|
1651
1879
|
const properties = { ...ambient };
|
|
1652
1880
|
if (sessionId === void 0) {
|
|
@@ -1659,7 +1887,7 @@ function recordMetricImpl(options) {
|
|
|
1659
1887
|
properties[SERVICE_NAME] = options.serviceName;
|
|
1660
1888
|
}
|
|
1661
1889
|
try {
|
|
1662
|
-
|
|
1890
|
+
context4.with(
|
|
1663
1891
|
base.setValue(PROPERTIES_CONTEXT_KEY, properties),
|
|
1664
1892
|
() => emitEvent(METRIC_EVENT_NAME, eventAttributes)
|
|
1665
1893
|
);
|
|
@@ -1670,7 +1898,7 @@ function recordMetricImpl(options) {
|
|
|
1670
1898
|
function startSession(sessionId, callback, extraProperties, options) {
|
|
1671
1899
|
const isTitle = options?.mode === "title";
|
|
1672
1900
|
const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
|
|
1673
|
-
const tracer =
|
|
1901
|
+
const tracer = trace3.getTracer("@brizz/sdk");
|
|
1674
1902
|
return tracer.startActiveSpan(spanName, (span) => {
|
|
1675
1903
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
1676
1904
|
if (extraProperties) {
|
|
@@ -1689,8 +1917,8 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1689
1917
|
}
|
|
1690
1918
|
}
|
|
1691
1919
|
return callWithProperties(contextProperties, () => {
|
|
1692
|
-
const sessionCtx =
|
|
1693
|
-
return
|
|
1920
|
+
const sessionCtx = context4.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
|
|
1921
|
+
return context4.with(sessionCtx, () => {
|
|
1694
1922
|
try {
|
|
1695
1923
|
const result = callback(session);
|
|
1696
1924
|
if (result && typeof result.then === "function") {
|
|
@@ -1699,7 +1927,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1699
1927
|
return value;
|
|
1700
1928
|
}).catch((error) => {
|
|
1701
1929
|
span.recordException(error);
|
|
1702
|
-
span.setStatus({ code:
|
|
1930
|
+
span.setStatus({ code: SpanStatusCode3.ERROR });
|
|
1703
1931
|
span.end();
|
|
1704
1932
|
throw error;
|
|
1705
1933
|
});
|
|
@@ -1708,7 +1936,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1708
1936
|
return result;
|
|
1709
1937
|
} catch (error) {
|
|
1710
1938
|
span.recordException(error);
|
|
1711
|
-
span.setStatus({ code:
|
|
1939
|
+
span.setStatus({ code: SpanStatusCode3.ERROR });
|
|
1712
1940
|
span.end();
|
|
1713
1941
|
throw error;
|
|
1714
1942
|
}
|
|
@@ -1718,7 +1946,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
1718
1946
|
}
|
|
1719
1947
|
function startSessionTitle(callback, options) {
|
|
1720
1948
|
const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
|
|
1721
|
-
const tracer =
|
|
1949
|
+
const tracer = trace3.getTracer("@brizz/sdk");
|
|
1722
1950
|
return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
|
|
1723
1951
|
if (resolvedSessionId) {
|
|
1724
1952
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
|
|
@@ -1737,7 +1965,7 @@ function startSessionTitle(callback, options) {
|
|
|
1737
1965
|
return value;
|
|
1738
1966
|
}).catch((error) => {
|
|
1739
1967
|
span.recordException(error);
|
|
1740
|
-
span.setStatus({ code:
|
|
1968
|
+
span.setStatus({ code: SpanStatusCode3.ERROR });
|
|
1741
1969
|
span.end();
|
|
1742
1970
|
throw error;
|
|
1743
1971
|
});
|
|
@@ -1746,7 +1974,7 @@ function startSessionTitle(callback, options) {
|
|
|
1746
1974
|
return result;
|
|
1747
1975
|
} catch (error) {
|
|
1748
1976
|
span.recordException(error);
|
|
1749
|
-
span.setStatus({ code:
|
|
1977
|
+
span.setStatus({ code: SpanStatusCode3.ERROR });
|
|
1750
1978
|
span.end();
|
|
1751
1979
|
throw error;
|
|
1752
1980
|
}
|
|
@@ -1755,7 +1983,7 @@ function startSessionTitle(callback, options) {
|
|
|
1755
1983
|
}
|
|
1756
1984
|
|
|
1757
1985
|
// src/internal/log/processors/log-processor.ts
|
|
1758
|
-
import { context as
|
|
1986
|
+
import { context as context5 } from "@opentelemetry/api";
|
|
1759
1987
|
import { BatchLogRecordProcessor, SimpleLogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
1760
1988
|
|
|
1761
1989
|
// src/internal/masking/patterns.ts
|
|
@@ -2139,10 +2367,12 @@ function maskValue(value, rule) {
|
|
|
2139
2367
|
return maskStringByPatternBasedRule(value, rule);
|
|
2140
2368
|
}
|
|
2141
2369
|
if (typeof value === "boolean" || typeof value === "number") {
|
|
2142
|
-
|
|
2370
|
+
const masked = maskStringByPatternBasedRule(String(value), rule);
|
|
2371
|
+
return masked === String(value) ? value : masked;
|
|
2143
2372
|
}
|
|
2144
2373
|
if (Array.isArray(value)) {
|
|
2145
|
-
|
|
2374
|
+
const masked = value.map((v) => maskStringByPatternBasedRule(String(v), rule));
|
|
2375
|
+
return masked.every((m, i) => m === String(value[i])) ? value : masked;
|
|
2146
2376
|
}
|
|
2147
2377
|
if (value !== null && typeof value === "object") {
|
|
2148
2378
|
const result = {};
|
|
@@ -2193,7 +2423,7 @@ var BrizzSimpleLogRecordProcessor = class extends SimpleLogRecordProcessor {
|
|
|
2193
2423
|
if (maskingConfig) {
|
|
2194
2424
|
maskLog(logRecord, maskingConfig);
|
|
2195
2425
|
}
|
|
2196
|
-
const associationProperties =
|
|
2426
|
+
const associationProperties = context5.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
2197
2427
|
if (associationProperties) {
|
|
2198
2428
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
2199
2429
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2213,7 +2443,7 @@ var BrizzBatchLogRecordProcessor = class extends BatchLogRecordProcessor {
|
|
|
2213
2443
|
if (maskingConfig) {
|
|
2214
2444
|
maskLog(logRecord, maskingConfig);
|
|
2215
2445
|
}
|
|
2216
|
-
const associationProperties =
|
|
2446
|
+
const associationProperties = context5.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
2217
2447
|
if (associationProperties) {
|
|
2218
2448
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
2219
2449
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2700,13 +2930,13 @@ var BrizzSpanExporter = class {
|
|
|
2700
2930
|
};
|
|
2701
2931
|
|
|
2702
2932
|
// src/internal/trace/processors/span-processor.ts
|
|
2703
|
-
import { context as
|
|
2933
|
+
import { context as context6 } from "@opentelemetry/api";
|
|
2704
2934
|
import {
|
|
2705
2935
|
BatchSpanProcessor,
|
|
2706
2936
|
SimpleSpanProcessor
|
|
2707
2937
|
} from "@opentelemetry/sdk-trace-base";
|
|
2708
2938
|
function applyContextAttributes(span) {
|
|
2709
|
-
const sessionProperties =
|
|
2939
|
+
const sessionProperties = context6.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
2710
2940
|
if (sessionProperties) {
|
|
2711
2941
|
for (const [key, value] of Object.entries(sessionProperties)) {
|
|
2712
2942
|
span.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2789,8 +3019,8 @@ function maskReadableSpan(span, config) {
|
|
|
2789
3019
|
masked = maskAttributes(masked, config.rules);
|
|
2790
3020
|
}
|
|
2791
3021
|
if (!config.disableDefaultRules) {
|
|
2792
|
-
const
|
|
2793
|
-
Object.assign(masked, maskAttributes(
|
|
3022
|
+
const text2 = Object.fromEntries(Object.entries(masked).filter(([k]) => isText(attrs[k])));
|
|
3023
|
+
Object.assign(masked, maskAttributes(text2, DEFAULT_MASKING_RULES));
|
|
2794
3024
|
}
|
|
2795
3025
|
const maskedEntries = Object.entries(masked);
|
|
2796
3026
|
for (const [k, v] of maskedEntries) {
|
|
@@ -2923,12 +3153,12 @@ function getSpanProcessor() {
|
|
|
2923
3153
|
|
|
2924
3154
|
// src/internal/trace/agent.ts
|
|
2925
3155
|
import { randomUUID } from "crypto";
|
|
2926
|
-
import { context as
|
|
3156
|
+
import { context as context7, propagation } from "@opentelemetry/api";
|
|
2927
3157
|
function newInstanceId() {
|
|
2928
3158
|
return randomUUID().replaceAll("-", "").slice(0, 8);
|
|
2929
3159
|
}
|
|
2930
3160
|
function activeProperties() {
|
|
2931
|
-
return
|
|
3161
|
+
return context7.active().getValue(PROPERTIES_CONTEXT_KEY) ?? {};
|
|
2932
3162
|
}
|
|
2933
3163
|
function encodeToken(agent) {
|
|
2934
3164
|
const payload = {
|
|
@@ -2943,7 +3173,7 @@ function encodeToken(agent) {
|
|
|
2943
3173
|
function currentTraceparent() {
|
|
2944
3174
|
const carrier = {};
|
|
2945
3175
|
try {
|
|
2946
|
-
propagation.inject(
|
|
3176
|
+
propagation.inject(context7.active(), carrier);
|
|
2947
3177
|
} catch {
|
|
2948
3178
|
}
|
|
2949
3179
|
return carrier["traceparent"] ?? "";
|
|
@@ -2987,7 +3217,7 @@ function resolveAgent(agent) {
|
|
|
2987
3217
|
let parentId;
|
|
2988
3218
|
let name;
|
|
2989
3219
|
let sessionId = "";
|
|
2990
|
-
let parentContext =
|
|
3220
|
+
let parentContext = context7.active();
|
|
2991
3221
|
if (options.token === void 0) {
|
|
2992
3222
|
id = options.id || newInstanceId();
|
|
2993
3223
|
parentId = options.parentId || activeProperties()[AGENT_ID] || "";
|
|
@@ -3024,7 +3254,7 @@ function startAgent(agent, callback) {
|
|
|
3024
3254
|
return callback(unreadableAgent(agent));
|
|
3025
3255
|
}
|
|
3026
3256
|
const { id, parentId, name, properties, parentContext } = resolved;
|
|
3027
|
-
return
|
|
3257
|
+
return context7.with(
|
|
3028
3258
|
parentContext,
|
|
3029
3259
|
() => callWithProperties(properties, () => callback(agentHandle(id, parentId, name)))
|
|
3030
3260
|
);
|
|
@@ -3080,6 +3310,7 @@ var _Brizz = class __Brizz {
|
|
|
3080
3310
|
configure(resolveMcpSessionTracking(options.mcpSessionTracking));
|
|
3081
3311
|
patchInstalledCallbackManager();
|
|
3082
3312
|
patchInstalledLangGraph();
|
|
3313
|
+
patchInstalledTypeSafe();
|
|
3083
3314
|
if (options.instrumentModules && Object.keys(options.instrumentModules).length > 0) {
|
|
3084
3315
|
registry.setManualModules(options.instrumentModules);
|
|
3085
3316
|
}
|