@brizz/sdk 0.1.25 → 0.1.27
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/index.cjs +172 -56
- package/dist/index.js +154 -38
- package/dist/preload.cjs +59 -20
- package/dist/preload.js +52 -13
- package/package.json +5 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/preload.cjs.map +0 -1
- package/dist/preload.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -164,31 +164,9 @@ var init_logger = __esm({
|
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
-
// src/internal/semantic-conventions.ts
|
|
168
|
-
import { createContextKey } from "@opentelemetry/api";
|
|
169
|
-
var BRIZZ, PROPERTIES, SESSION_ID, PROPERTIES_CONTEXT_KEY, SESSION_OBJECT_CONTEXT_KEY, SESSION_INPUT, SESSION_OUTPUT, SESSION_INPUT_CONTEXT, SESSION_OUTPUT_CONTEXT, SESSION_SPAN_NAME, SESSION_TITLE_SPAN_NAME, SESSION_TITLE_GENERATION, SESSION_TITLE;
|
|
170
|
-
var init_semantic_conventions = __esm({
|
|
171
|
-
"src/internal/semantic-conventions.ts"() {
|
|
172
|
-
"use strict";
|
|
173
|
-
BRIZZ = "brizz";
|
|
174
|
-
PROPERTIES = "properties";
|
|
175
|
-
SESSION_ID = "session.id";
|
|
176
|
-
PROPERTIES_CONTEXT_KEY = createContextKey(PROPERTIES);
|
|
177
|
-
SESSION_OBJECT_CONTEXT_KEY = createContextKey("brizz.session.object");
|
|
178
|
-
SESSION_INPUT = "brizz.session.input";
|
|
179
|
-
SESSION_OUTPUT = "brizz.session.output";
|
|
180
|
-
SESSION_INPUT_CONTEXT = "brizz.session.input.context";
|
|
181
|
-
SESSION_OUTPUT_CONTEXT = "brizz.session.output.context";
|
|
182
|
-
SESSION_SPAN_NAME = "brizz.start_session";
|
|
183
|
-
SESSION_TITLE_SPAN_NAME = "brizz.session_title";
|
|
184
|
-
SESSION_TITLE_GENERATION = "session.title_generation";
|
|
185
|
-
SESSION_TITLE = "brizz.session.title";
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
167
|
// src/internal/instrumentation/mcp/semantic-conventions.ts
|
|
190
168
|
var MCP_TOOL_NAME, MCP_TOOL_ARGUMENTS, MCP_TOOL_RESULT, MCP_COMPONENT_TYPE, MCP_COMPONENT_TOOL, MCP_COMPONENT_TOOL_SCHEMA, MCP_TOOL_SCHEMA_PARAMETERS, MCP_TOOL_SCHEMA_OUTPUT, MCP_TOOL_DESCRIPTION, SPAN_NAME_TOOL_REGISTER, MCP_METHOD_NAME, MCP_REQUEST_ID, MCP_SESSION_ID, MCP_PROTOCOL_VERSION, MCP_RESOURCE_URI, RPC_SYSTEM, RPC_SYSTEM_MCP, RPC_RESPONSE_STATUS_CODE, GEN_AI_TOOL_NAME, GEN_AI_PROMPT_NAME, GEN_AI_OPERATION_NAME, GEN_AI_OPERATION_EXECUTE_TOOL, NETWORK_TRANSPORT, ERROR_TYPE, ERROR_TYPE_TOOL, JSONRPC_REQUEST_ID, SPAN_NAME_TOOLS_CALL, MAX_ATTRIBUTE_LENGTH, TRUNCATION_SUFFIX, METHOD_TOOLS_CALL, METHOD_TOOLS_LIST, METHOD_RESOURCES_READ, METHOD_PROMPTS_GET, METHOD_INITIALIZE;
|
|
191
|
-
var
|
|
169
|
+
var init_semantic_conventions = __esm({
|
|
192
170
|
"src/internal/instrumentation/mcp/semantic-conventions.ts"() {
|
|
193
171
|
"use strict";
|
|
194
172
|
MCP_TOOL_NAME = "mcp.tool.name";
|
|
@@ -283,7 +261,6 @@ function stampSchemaAttributes(span, toolName, transportSessionId, tool) {
|
|
|
283
261
|
span.setAttribute(RPC_SYSTEM, RPC_SYSTEM_MCP);
|
|
284
262
|
span.setAttribute(MCP_COMPONENT_TYPE, MCP_COMPONENT_TOOL_SCHEMA);
|
|
285
263
|
span.setAttribute(MCP_SESSION_ID, transportSessionId);
|
|
286
|
-
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, transportSessionId);
|
|
287
264
|
span.setAttribute(MCP_TOOL_NAME, toolName);
|
|
288
265
|
span.setAttribute(MCP_TOOL_SCHEMA_PARAMETERS, parameters);
|
|
289
266
|
span.setAttribute(MCP_TOOL_SCHEMA_OUTPUT, outputSchema);
|
|
@@ -307,11 +284,33 @@ var init_schemas = __esm({
|
|
|
307
284
|
"use strict";
|
|
308
285
|
init_logger();
|
|
309
286
|
init_semantic_conventions();
|
|
310
|
-
init_semantic_conventions2();
|
|
311
287
|
_MAX_SCHEMA_ATTR_BYTES = 4e3;
|
|
312
288
|
}
|
|
313
289
|
});
|
|
314
290
|
|
|
291
|
+
// src/internal/semantic-conventions.ts
|
|
292
|
+
import { createContextKey } from "@opentelemetry/api";
|
|
293
|
+
var BRIZZ, PROPERTIES, SESSION_ID, PROPERTIES_CONTEXT_KEY, SESSION_OBJECT_CONTEXT_KEY, SESSION_INPUT, SESSION_OUTPUT, SESSION_INPUT_CONTEXT, SESSION_OUTPUT_CONTEXT, SESSION_SPAN_NAME, SESSION_TITLE_SPAN_NAME, SESSION_TITLE_GENERATION, SESSION_TITLE, INTERRUPT_TOOLS;
|
|
294
|
+
var init_semantic_conventions2 = __esm({
|
|
295
|
+
"src/internal/semantic-conventions.ts"() {
|
|
296
|
+
"use strict";
|
|
297
|
+
BRIZZ = "brizz";
|
|
298
|
+
PROPERTIES = "properties";
|
|
299
|
+
SESSION_ID = "session.id";
|
|
300
|
+
PROPERTIES_CONTEXT_KEY = createContextKey(PROPERTIES);
|
|
301
|
+
SESSION_OBJECT_CONTEXT_KEY = createContextKey("brizz.session.object");
|
|
302
|
+
SESSION_INPUT = "brizz.session.input";
|
|
303
|
+
SESSION_OUTPUT = "brizz.session.output";
|
|
304
|
+
SESSION_INPUT_CONTEXT = "brizz.session.input.context";
|
|
305
|
+
SESSION_OUTPUT_CONTEXT = "brizz.session.output.context";
|
|
306
|
+
SESSION_SPAN_NAME = "brizz.start_session";
|
|
307
|
+
SESSION_TITLE_SPAN_NAME = "brizz.session_title";
|
|
308
|
+
SESSION_TITLE_GENERATION = "session.title_generation";
|
|
309
|
+
SESSION_TITLE = "brizz.session.title";
|
|
310
|
+
INTERRUPT_TOOLS = "brizz.internal.interrupt";
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
|
|
315
314
|
// src/internal/instrumentation/mcp/session.ts
|
|
316
315
|
import { context } from "@opentelemetry/api";
|
|
317
316
|
function stampAndPropagateSession(span, sessionId, baseContext = context.active()) {
|
|
@@ -343,7 +342,7 @@ var init_session = __esm({
|
|
|
343
342
|
"src/internal/instrumentation/mcp/session.ts"() {
|
|
344
343
|
"use strict";
|
|
345
344
|
init_logger();
|
|
346
|
-
|
|
345
|
+
init_semantic_conventions2();
|
|
347
346
|
}
|
|
348
347
|
});
|
|
349
348
|
|
|
@@ -540,7 +539,7 @@ function normalizeTransport(ctorName) {
|
|
|
540
539
|
var init_attributes = __esm({
|
|
541
540
|
"src/internal/instrumentation/mcp/patches/attributes.ts"() {
|
|
542
541
|
"use strict";
|
|
543
|
-
|
|
542
|
+
init_semantic_conventions();
|
|
544
543
|
}
|
|
545
544
|
});
|
|
546
545
|
|
|
@@ -765,7 +764,7 @@ var init_protocol = __esm({
|
|
|
765
764
|
"use strict";
|
|
766
765
|
init_logger();
|
|
767
766
|
init_schemas();
|
|
768
|
-
|
|
767
|
+
init_semantic_conventions();
|
|
769
768
|
init_session();
|
|
770
769
|
init_attributes();
|
|
771
770
|
PATCHED_FLAG = /* @__PURE__ */ Symbol("brizz.mcp.protocol-patched");
|
|
@@ -774,7 +773,7 @@ var init_protocol = __esm({
|
|
|
774
773
|
|
|
775
774
|
// src/internal/version.ts
|
|
776
775
|
function getSDKVersion() {
|
|
777
|
-
return "0.1.
|
|
776
|
+
return "0.1.27";
|
|
778
777
|
}
|
|
779
778
|
var init_version = __esm({
|
|
780
779
|
"src/internal/version.ts"() {
|
|
@@ -956,6 +955,100 @@ var init_mcp = __esm({
|
|
|
956
955
|
}
|
|
957
956
|
});
|
|
958
957
|
|
|
958
|
+
// src/internal/instrumentation/vercel-ai/interrupt.ts
|
|
959
|
+
var interrupt_exports = {};
|
|
960
|
+
__export(interrupt_exports, {
|
|
961
|
+
InterruptPropagator: () => InterruptPropagator,
|
|
962
|
+
_resetInterruptState: () => _resetInterruptState,
|
|
963
|
+
createInterruptIntegration: () => createInterruptIntegration
|
|
964
|
+
});
|
|
965
|
+
import { trace as trace3 } from "@opentelemetry/api";
|
|
966
|
+
function isInnerLLMSpan(span) {
|
|
967
|
+
if (INNER_OPERATION_IDS.has(span.name)) {
|
|
968
|
+
return true;
|
|
969
|
+
}
|
|
970
|
+
const opId = span.attributes["ai.operationId"];
|
|
971
|
+
return typeof opId === "string" && INNER_OPERATION_IDS.has(opId);
|
|
972
|
+
}
|
|
973
|
+
function setPending(parentSpanId, value) {
|
|
974
|
+
pendingByParentSpanId.set(parentSpanId, value);
|
|
975
|
+
while (pendingByParentSpanId.size > MAX_PENDING_ENTRIES) {
|
|
976
|
+
const oldest = pendingByParentSpanId.keys().next().value;
|
|
977
|
+
if (oldest === void 0) {
|
|
978
|
+
break;
|
|
979
|
+
}
|
|
980
|
+
pendingByParentSpanId.delete(oldest);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
function extractInterruptTools(tools) {
|
|
984
|
+
if (!tools || typeof tools !== "object") {
|
|
985
|
+
return [];
|
|
986
|
+
}
|
|
987
|
+
return Object.entries(tools).filter(
|
|
988
|
+
([, t]) => !!t && typeof t === "object" && t.needsApproval
|
|
989
|
+
).map(([name]) => name);
|
|
990
|
+
}
|
|
991
|
+
function createInterruptIntegration() {
|
|
992
|
+
const onStepStart = (event) => {
|
|
993
|
+
const names = extractInterruptTools(event.tools);
|
|
994
|
+
if (names.length === 0) {
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
const value = JSON.stringify(names);
|
|
998
|
+
const span = trace3.getActiveSpan();
|
|
999
|
+
if (!span) {
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
span.setAttribute(INTERRUPT_TOOLS, value);
|
|
1003
|
+
setPending(span.spanContext().spanId, value);
|
|
1004
|
+
};
|
|
1005
|
+
return {
|
|
1006
|
+
onStepStart
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
function _resetInterruptState() {
|
|
1010
|
+
if (process.env["NODE_ENV"] !== "test") {
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
pendingByParentSpanId.clear();
|
|
1014
|
+
}
|
|
1015
|
+
var INNER_OPERATION_IDS, MAX_PENDING_ENTRIES, pendingByParentSpanId, InterruptPropagator;
|
|
1016
|
+
var init_interrupt = __esm({
|
|
1017
|
+
"src/internal/instrumentation/vercel-ai/interrupt.ts"() {
|
|
1018
|
+
"use strict";
|
|
1019
|
+
init_semantic_conventions2();
|
|
1020
|
+
INNER_OPERATION_IDS = /* @__PURE__ */ new Set([
|
|
1021
|
+
"ai.generateText.doGenerate",
|
|
1022
|
+
"ai.streamText.doStream"
|
|
1023
|
+
]);
|
|
1024
|
+
MAX_PENDING_ENTRIES = 1024;
|
|
1025
|
+
pendingByParentSpanId = /* @__PURE__ */ new Map();
|
|
1026
|
+
InterruptPropagator = class {
|
|
1027
|
+
onStart(span, _parentContext) {
|
|
1028
|
+
if (!isInnerLLMSpan(span)) {
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
const parentSpanId = span.parentSpanContext?.spanId;
|
|
1032
|
+
if (!parentSpanId) {
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
const value = pendingByParentSpanId.get(parentSpanId);
|
|
1036
|
+
if (!value) {
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
span.setAttribute(INTERRUPT_TOOLS, value);
|
|
1040
|
+
pendingByParentSpanId.delete(parentSpanId);
|
|
1041
|
+
}
|
|
1042
|
+
onEnd() {
|
|
1043
|
+
}
|
|
1044
|
+
async shutdown() {
|
|
1045
|
+
}
|
|
1046
|
+
async forceFlush() {
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
|
|
959
1052
|
// src/internal/instrumentation/auto-init.ts
|
|
960
1053
|
init_logger();
|
|
961
1054
|
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
|
|
@@ -1036,6 +1129,26 @@ function loadMCPInstrumentation() {
|
|
|
1036
1129
|
}
|
|
1037
1130
|
})();
|
|
1038
1131
|
}
|
|
1132
|
+
function loadVercelAIInterruptIntegration() {
|
|
1133
|
+
void (async () => {
|
|
1134
|
+
try {
|
|
1135
|
+
const ai = await import("ai");
|
|
1136
|
+
if (typeof ai.registerTelemetryIntegration !== "function") {
|
|
1137
|
+
logger.debug(
|
|
1138
|
+
"AI SDK present but lacks registerTelemetryIntegration (needs ai@>=6); skipping interrupt bridge"
|
|
1139
|
+
);
|
|
1140
|
+
return;
|
|
1141
|
+
}
|
|
1142
|
+
const { createInterruptIntegration: createInterruptIntegration2 } = await Promise.resolve().then(() => (init_interrupt(), interrupt_exports));
|
|
1143
|
+
ai.registerTelemetryIntegration(createInterruptIntegration2());
|
|
1144
|
+
logger.debug("Auto-loaded Vercel AI interrupt bridge");
|
|
1145
|
+
} catch (error) {
|
|
1146
|
+
logger.debug(
|
|
1147
|
+
`Vercel AI interrupt bridge not loaded (install ai@>=6 if you want HITL attribution): ${String(error)}`
|
|
1148
|
+
);
|
|
1149
|
+
}
|
|
1150
|
+
})();
|
|
1151
|
+
}
|
|
1039
1152
|
function autoInitializeInstrumentations() {
|
|
1040
1153
|
if (autoInstrumentationsLoaded) {
|
|
1041
1154
|
return;
|
|
@@ -1044,6 +1157,7 @@ function autoInitializeInstrumentations() {
|
|
|
1044
1157
|
const nodeInstrumentations = loadNodeAutoInstrumentations();
|
|
1045
1158
|
const genAIInstrumentations = loadGenAIInstrumentations();
|
|
1046
1159
|
loadMCPInstrumentation();
|
|
1160
|
+
loadVercelAIInterruptIntegration();
|
|
1047
1161
|
autoInstrumentationsLoaded = true;
|
|
1048
1162
|
logger.info(
|
|
1049
1163
|
`Auto-initialization complete: ${nodeInstrumentations.length} node + ${genAIInstrumentations.length} GenAI instrumentations`
|
|
@@ -1358,6 +1472,9 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
1358
1472
|
}
|
|
1359
1473
|
};
|
|
1360
1474
|
|
|
1475
|
+
// src/internal/sdk.ts
|
|
1476
|
+
init_interrupt();
|
|
1477
|
+
|
|
1361
1478
|
// src/internal/log/logging.ts
|
|
1362
1479
|
import { SeverityNumber } from "@opentelemetry/api-logs";
|
|
1363
1480
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
@@ -1782,7 +1899,7 @@ function maskAttributes(attributes, rules, outputOriginalValue = false) {
|
|
|
1782
1899
|
}
|
|
1783
1900
|
|
|
1784
1901
|
// src/internal/log/processors/log-processor.ts
|
|
1785
|
-
|
|
1902
|
+
init_semantic_conventions2();
|
|
1786
1903
|
var DEFAULT_LOG_MASKING_RULES = [
|
|
1787
1904
|
{
|
|
1788
1905
|
mode: "partial",
|
|
@@ -2227,7 +2344,7 @@ import {
|
|
|
2227
2344
|
BatchSpanProcessor,
|
|
2228
2345
|
SimpleSpanProcessor
|
|
2229
2346
|
} from "@opentelemetry/sdk-trace-base";
|
|
2230
|
-
|
|
2347
|
+
init_semantic_conventions2();
|
|
2231
2348
|
function applyContextAttributes(span) {
|
|
2232
2349
|
const sessionProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
2233
2350
|
if (sessionProperties) {
|
|
@@ -2415,10 +2532,10 @@ function getSpanProcessor() {
|
|
|
2415
2532
|
}
|
|
2416
2533
|
|
|
2417
2534
|
// src/internal/trace/session.ts
|
|
2418
|
-
|
|
2419
|
-
import { context as context5, trace as
|
|
2535
|
+
init_semantic_conventions2();
|
|
2536
|
+
import { context as context5, trace as trace4, SpanStatusCode as SpanStatusCode3 } from "@opentelemetry/api";
|
|
2420
2537
|
function setCurrentSpanCustomProperties(properties) {
|
|
2421
|
-
const current =
|
|
2538
|
+
const current = trace4.getActiveSpan();
|
|
2422
2539
|
if (!current || !current.isRecording()) {
|
|
2423
2540
|
return;
|
|
2424
2541
|
}
|
|
@@ -2538,7 +2655,7 @@ function getActiveSession() {
|
|
|
2538
2655
|
function startSession(sessionId, callback, extraProperties, options) {
|
|
2539
2656
|
const isTitle = options?.mode === "title";
|
|
2540
2657
|
const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
|
|
2541
|
-
const tracer =
|
|
2658
|
+
const tracer = trace4.getTracer("@brizz/sdk");
|
|
2542
2659
|
return tracer.startActiveSpan(spanName, (span) => {
|
|
2543
2660
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
2544
2661
|
if (extraProperties) {
|
|
@@ -2586,7 +2703,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
2586
2703
|
}
|
|
2587
2704
|
function startSessionTitle(callback, options) {
|
|
2588
2705
|
const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
|
|
2589
|
-
const tracer =
|
|
2706
|
+
const tracer = trace4.getTracer("@brizz/sdk");
|
|
2590
2707
|
return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
|
|
2591
2708
|
if (resolvedSessionId) {
|
|
2592
2709
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
|
|
@@ -2706,7 +2823,7 @@ var _Brizz = class __Brizz {
|
|
|
2706
2823
|
resourceAttributes["service.version"] = resolvedConfig.appVersion;
|
|
2707
2824
|
}
|
|
2708
2825
|
this._sdk = new NodeSDK({
|
|
2709
|
-
spanProcessors: resolvedConfig.disableSpanExporter ? [] : [getSpanProcessor()],
|
|
2826
|
+
spanProcessors: resolvedConfig.disableSpanExporter ? [] : [new InterruptPropagator(), getSpanProcessor()],
|
|
2710
2827
|
metricReader: getMetricsReader(),
|
|
2711
2828
|
resource: resourceFromAttributes3(resourceAttributes),
|
|
2712
2829
|
instrumentations: manualInstrumentations
|
|
@@ -2901,4 +3018,3 @@ export {
|
|
|
2901
3018
|
withProperties,
|
|
2902
3019
|
withSessionId
|
|
2903
3020
|
};
|
|
2904
|
-
//# sourceMappingURL=index.js.map
|
package/dist/preload.cjs
CHANGED
|
@@ -350,15 +350,7 @@ var import_instrumentation = require("@opentelemetry/instrumentation");
|
|
|
350
350
|
var import_api6 = require("@opentelemetry/api");
|
|
351
351
|
|
|
352
352
|
// src/internal/instrumentation/mcp/schemas.ts
|
|
353
|
-
var import_api3 = require("@opentelemetry/api");
|
|
354
|
-
|
|
355
|
-
// src/internal/semantic-conventions.ts
|
|
356
353
|
var import_api2 = require("@opentelemetry/api");
|
|
357
|
-
var BRIZZ = "brizz";
|
|
358
|
-
var PROPERTIES = "properties";
|
|
359
|
-
var SESSION_ID = "session.id";
|
|
360
|
-
var PROPERTIES_CONTEXT_KEY = (0, import_api2.createContextKey)(PROPERTIES);
|
|
361
|
-
var SESSION_OBJECT_CONTEXT_KEY = (0, import_api2.createContextKey)("brizz.session.object");
|
|
362
354
|
|
|
363
355
|
// src/internal/instrumentation/mcp/semantic-conventions.ts
|
|
364
356
|
var MCP_TOOL_NAME = "mcp.tool.name";
|
|
@@ -428,11 +420,11 @@ function emitSchemaSpansFromListResponse(result, transportSessionId, tracer) {
|
|
|
428
420
|
continue;
|
|
429
421
|
}
|
|
430
422
|
const span = tracer.startSpan(`${SPAN_NAME_TOOL_REGISTER} ${name}`, {
|
|
431
|
-
kind:
|
|
423
|
+
kind: import_api2.SpanKind.INTERNAL
|
|
432
424
|
});
|
|
433
425
|
try {
|
|
434
426
|
stampSchemaAttributes(span, name, transportSessionId, tool);
|
|
435
|
-
span.setStatus({ code:
|
|
427
|
+
span.setStatus({ code: import_api2.SpanStatusCode.OK });
|
|
436
428
|
} finally {
|
|
437
429
|
span.end();
|
|
438
430
|
}
|
|
@@ -451,7 +443,6 @@ function stampSchemaAttributes(span, toolName, transportSessionId, tool) {
|
|
|
451
443
|
span.setAttribute(RPC_SYSTEM, RPC_SYSTEM_MCP);
|
|
452
444
|
span.setAttribute(MCP_COMPONENT_TYPE, MCP_COMPONENT_TOOL_SCHEMA);
|
|
453
445
|
span.setAttribute(MCP_SESSION_ID, transportSessionId);
|
|
454
|
-
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, transportSessionId);
|
|
455
446
|
span.setAttribute(MCP_TOOL_NAME, toolName);
|
|
456
447
|
span.setAttribute(MCP_TOOL_SCHEMA_PARAMETERS, parameters);
|
|
457
448
|
span.setAttribute(MCP_TOOL_SCHEMA_OUTPUT, outputSchema);
|
|
@@ -472,6 +463,17 @@ function extractTools(result) {
|
|
|
472
463
|
|
|
473
464
|
// src/internal/instrumentation/mcp/session.ts
|
|
474
465
|
var import_api4 = require("@opentelemetry/api");
|
|
466
|
+
|
|
467
|
+
// src/internal/semantic-conventions.ts
|
|
468
|
+
var import_api3 = require("@opentelemetry/api");
|
|
469
|
+
var BRIZZ = "brizz";
|
|
470
|
+
var PROPERTIES = "properties";
|
|
471
|
+
var SESSION_ID = "session.id";
|
|
472
|
+
var PROPERTIES_CONTEXT_KEY = (0, import_api3.createContextKey)(PROPERTIES);
|
|
473
|
+
var SESSION_OBJECT_CONTEXT_KEY = (0, import_api3.createContextKey)("brizz.session.object");
|
|
474
|
+
var INTERRUPT_TOOLS = "brizz.internal.interrupt";
|
|
475
|
+
|
|
476
|
+
// src/internal/instrumentation/mcp/session.ts
|
|
475
477
|
function stampAndPropagateSession(span, sessionId, baseContext = import_api4.context.active()) {
|
|
476
478
|
if (!sessionId) {
|
|
477
479
|
return { context: baseContext, sessionId: null };
|
|
@@ -907,7 +909,7 @@ function safeEnd(span) {
|
|
|
907
909
|
|
|
908
910
|
// src/internal/version.ts
|
|
909
911
|
function getSDKVersion() {
|
|
910
|
-
return "0.1.
|
|
912
|
+
return "0.1.27";
|
|
911
913
|
}
|
|
912
914
|
|
|
913
915
|
// src/internal/instrumentation/mcp/version.ts
|
|
@@ -1165,6 +1167,44 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
1165
1167
|
}
|
|
1166
1168
|
};
|
|
1167
1169
|
|
|
1170
|
+
// src/internal/instrumentation/vercel-ai/interrupt.ts
|
|
1171
|
+
var import_api8 = require("@opentelemetry/api");
|
|
1172
|
+
var INNER_OPERATION_IDS = /* @__PURE__ */ new Set([
|
|
1173
|
+
"ai.generateText.doGenerate",
|
|
1174
|
+
"ai.streamText.doStream"
|
|
1175
|
+
]);
|
|
1176
|
+
function isInnerLLMSpan(span) {
|
|
1177
|
+
if (INNER_OPERATION_IDS.has(span.name)) {
|
|
1178
|
+
return true;
|
|
1179
|
+
}
|
|
1180
|
+
const opId = span.attributes["ai.operationId"];
|
|
1181
|
+
return typeof opId === "string" && INNER_OPERATION_IDS.has(opId);
|
|
1182
|
+
}
|
|
1183
|
+
var pendingByParentSpanId = /* @__PURE__ */ new Map();
|
|
1184
|
+
var InterruptPropagator = class {
|
|
1185
|
+
onStart(span, _parentContext) {
|
|
1186
|
+
if (!isInnerLLMSpan(span)) {
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1189
|
+
const parentSpanId = span.parentSpanContext?.spanId;
|
|
1190
|
+
if (!parentSpanId) {
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
const value = pendingByParentSpanId.get(parentSpanId);
|
|
1194
|
+
if (!value) {
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
span.setAttribute(INTERRUPT_TOOLS, value);
|
|
1198
|
+
pendingByParentSpanId.delete(parentSpanId);
|
|
1199
|
+
}
|
|
1200
|
+
onEnd() {
|
|
1201
|
+
}
|
|
1202
|
+
async shutdown() {
|
|
1203
|
+
}
|
|
1204
|
+
async forceFlush() {
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1168
1208
|
// src/internal/log/logging.ts
|
|
1169
1209
|
var import_api_logs = require("@opentelemetry/api-logs");
|
|
1170
1210
|
var import_exporter_logs_otlp_http = require("@opentelemetry/exporter-logs-otlp-http");
|
|
@@ -1172,7 +1212,7 @@ var import_resources = require("@opentelemetry/resources");
|
|
|
1172
1212
|
var import_sdk_logs2 = require("@opentelemetry/sdk-logs");
|
|
1173
1213
|
|
|
1174
1214
|
// src/internal/log/processors/log-processor.ts
|
|
1175
|
-
var
|
|
1215
|
+
var import_api9 = require("@opentelemetry/api");
|
|
1176
1216
|
var import_sdk_logs = require("@opentelemetry/sdk-logs");
|
|
1177
1217
|
|
|
1178
1218
|
// src/internal/masking/patterns.ts
|
|
@@ -1601,7 +1641,7 @@ var BrizzSimpleLogRecordProcessor = class extends import_sdk_logs.SimpleLogRecor
|
|
|
1601
1641
|
if (maskingConfig) {
|
|
1602
1642
|
maskLog(logRecord, maskingConfig);
|
|
1603
1643
|
}
|
|
1604
|
-
const associationProperties =
|
|
1644
|
+
const associationProperties = import_api9.context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1605
1645
|
if (associationProperties) {
|
|
1606
1646
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1607
1647
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -1621,7 +1661,7 @@ var BrizzBatchLogRecordProcessor = class extends import_sdk_logs.BatchLogRecordP
|
|
|
1621
1661
|
if (maskingConfig) {
|
|
1622
1662
|
maskLog(logRecord, maskingConfig);
|
|
1623
1663
|
}
|
|
1624
|
-
const associationProperties =
|
|
1664
|
+
const associationProperties = import_api9.context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1625
1665
|
if (associationProperties) {
|
|
1626
1666
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1627
1667
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2008,10 +2048,10 @@ var BrizzSpanExporter = class {
|
|
|
2008
2048
|
};
|
|
2009
2049
|
|
|
2010
2050
|
// src/internal/trace/processors/span-processor.ts
|
|
2011
|
-
var
|
|
2051
|
+
var import_api10 = require("@opentelemetry/api");
|
|
2012
2052
|
var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
2013
2053
|
function applyContextAttributes(span) {
|
|
2014
|
-
const sessionProperties =
|
|
2054
|
+
const sessionProperties = import_api10.context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
2015
2055
|
if (sessionProperties) {
|
|
2016
2056
|
for (const [key, value] of Object.entries(sessionProperties)) {
|
|
2017
2057
|
span.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2194,7 +2234,7 @@ function getSpanProcessor() {
|
|
|
2194
2234
|
}
|
|
2195
2235
|
|
|
2196
2236
|
// src/internal/trace/session.ts
|
|
2197
|
-
var
|
|
2237
|
+
var import_api11 = require("@opentelemetry/api");
|
|
2198
2238
|
|
|
2199
2239
|
// src/internal/sdk.ts
|
|
2200
2240
|
var _Brizz = class __Brizz {
|
|
@@ -2279,7 +2319,7 @@ var _Brizz = class __Brizz {
|
|
|
2279
2319
|
resourceAttributes["service.version"] = resolvedConfig.appVersion;
|
|
2280
2320
|
}
|
|
2281
2321
|
this._sdk = new import_sdk_node.NodeSDK({
|
|
2282
|
-
spanProcessors: resolvedConfig.disableSpanExporter ? [] : [getSpanProcessor()],
|
|
2322
|
+
spanProcessors: resolvedConfig.disableSpanExporter ? [] : [new InterruptPropagator(), getSpanProcessor()],
|
|
2283
2323
|
metricReader: getMetricsReader(),
|
|
2284
2324
|
resource: (0, import_resources3.resourceFromAttributes)(resourceAttributes),
|
|
2285
2325
|
instrumentations: manualInstrumentations
|
|
@@ -2543,4 +2583,3 @@ try {
|
|
|
2543
2583
|
} catch (error) {
|
|
2544
2584
|
logger.warn("Failed to auto-initialize SDK:", { error });
|
|
2545
2585
|
}
|
|
2546
|
-
//# sourceMappingURL=preload.cjs.map
|
package/dist/preload.js
CHANGED
|
@@ -335,14 +335,6 @@ import { context as context2, propagation, SpanKind as SpanKind2, trace } from "
|
|
|
335
335
|
// src/internal/instrumentation/mcp/schemas.ts
|
|
336
336
|
import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
|
|
337
337
|
|
|
338
|
-
// src/internal/semantic-conventions.ts
|
|
339
|
-
import { createContextKey } from "@opentelemetry/api";
|
|
340
|
-
var BRIZZ = "brizz";
|
|
341
|
-
var PROPERTIES = "properties";
|
|
342
|
-
var SESSION_ID = "session.id";
|
|
343
|
-
var PROPERTIES_CONTEXT_KEY = createContextKey(PROPERTIES);
|
|
344
|
-
var SESSION_OBJECT_CONTEXT_KEY = createContextKey("brizz.session.object");
|
|
345
|
-
|
|
346
338
|
// src/internal/instrumentation/mcp/semantic-conventions.ts
|
|
347
339
|
var MCP_TOOL_NAME = "mcp.tool.name";
|
|
348
340
|
var MCP_TOOL_ARGUMENTS = "mcp.tool.arguments";
|
|
@@ -434,7 +426,6 @@ function stampSchemaAttributes(span, toolName, transportSessionId, tool) {
|
|
|
434
426
|
span.setAttribute(RPC_SYSTEM, RPC_SYSTEM_MCP);
|
|
435
427
|
span.setAttribute(MCP_COMPONENT_TYPE, MCP_COMPONENT_TOOL_SCHEMA);
|
|
436
428
|
span.setAttribute(MCP_SESSION_ID, transportSessionId);
|
|
437
|
-
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, transportSessionId);
|
|
438
429
|
span.setAttribute(MCP_TOOL_NAME, toolName);
|
|
439
430
|
span.setAttribute(MCP_TOOL_SCHEMA_PARAMETERS, parameters);
|
|
440
431
|
span.setAttribute(MCP_TOOL_SCHEMA_OUTPUT, outputSchema);
|
|
@@ -455,6 +446,17 @@ function extractTools(result) {
|
|
|
455
446
|
|
|
456
447
|
// src/internal/instrumentation/mcp/session.ts
|
|
457
448
|
import { context } from "@opentelemetry/api";
|
|
449
|
+
|
|
450
|
+
// src/internal/semantic-conventions.ts
|
|
451
|
+
import { createContextKey } from "@opentelemetry/api";
|
|
452
|
+
var BRIZZ = "brizz";
|
|
453
|
+
var PROPERTIES = "properties";
|
|
454
|
+
var SESSION_ID = "session.id";
|
|
455
|
+
var PROPERTIES_CONTEXT_KEY = createContextKey(PROPERTIES);
|
|
456
|
+
var SESSION_OBJECT_CONTEXT_KEY = createContextKey("brizz.session.object");
|
|
457
|
+
var INTERRUPT_TOOLS = "brizz.internal.interrupt";
|
|
458
|
+
|
|
459
|
+
// src/internal/instrumentation/mcp/session.ts
|
|
458
460
|
function stampAndPropagateSession(span, sessionId, baseContext = context.active()) {
|
|
459
461
|
if (!sessionId) {
|
|
460
462
|
return { context: baseContext, sessionId: null };
|
|
@@ -890,7 +892,7 @@ function safeEnd(span) {
|
|
|
890
892
|
|
|
891
893
|
// src/internal/version.ts
|
|
892
894
|
function getSDKVersion() {
|
|
893
|
-
return "0.1.
|
|
895
|
+
return "0.1.27";
|
|
894
896
|
}
|
|
895
897
|
|
|
896
898
|
// src/internal/instrumentation/mcp/version.ts
|
|
@@ -1148,6 +1150,44 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
|
|
|
1148
1150
|
}
|
|
1149
1151
|
};
|
|
1150
1152
|
|
|
1153
|
+
// src/internal/instrumentation/vercel-ai/interrupt.ts
|
|
1154
|
+
import { trace as trace3 } from "@opentelemetry/api";
|
|
1155
|
+
var INNER_OPERATION_IDS = /* @__PURE__ */ new Set([
|
|
1156
|
+
"ai.generateText.doGenerate",
|
|
1157
|
+
"ai.streamText.doStream"
|
|
1158
|
+
]);
|
|
1159
|
+
function isInnerLLMSpan(span) {
|
|
1160
|
+
if (INNER_OPERATION_IDS.has(span.name)) {
|
|
1161
|
+
return true;
|
|
1162
|
+
}
|
|
1163
|
+
const opId = span.attributes["ai.operationId"];
|
|
1164
|
+
return typeof opId === "string" && INNER_OPERATION_IDS.has(opId);
|
|
1165
|
+
}
|
|
1166
|
+
var pendingByParentSpanId = /* @__PURE__ */ new Map();
|
|
1167
|
+
var InterruptPropagator = class {
|
|
1168
|
+
onStart(span, _parentContext) {
|
|
1169
|
+
if (!isInnerLLMSpan(span)) {
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
const parentSpanId = span.parentSpanContext?.spanId;
|
|
1173
|
+
if (!parentSpanId) {
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
const value = pendingByParentSpanId.get(parentSpanId);
|
|
1177
|
+
if (!value) {
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
span.setAttribute(INTERRUPT_TOOLS, value);
|
|
1181
|
+
pendingByParentSpanId.delete(parentSpanId);
|
|
1182
|
+
}
|
|
1183
|
+
onEnd() {
|
|
1184
|
+
}
|
|
1185
|
+
async shutdown() {
|
|
1186
|
+
}
|
|
1187
|
+
async forceFlush() {
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
|
|
1151
1191
|
// src/internal/log/logging.ts
|
|
1152
1192
|
import { SeverityNumber } from "@opentelemetry/api-logs";
|
|
1153
1193
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
@@ -2182,7 +2222,7 @@ function getSpanProcessor() {
|
|
|
2182
2222
|
}
|
|
2183
2223
|
|
|
2184
2224
|
// src/internal/trace/session.ts
|
|
2185
|
-
import { context as context5, trace as
|
|
2225
|
+
import { context as context5, trace as trace4, SpanStatusCode as SpanStatusCode3 } from "@opentelemetry/api";
|
|
2186
2226
|
|
|
2187
2227
|
// src/internal/sdk.ts
|
|
2188
2228
|
var _Brizz = class __Brizz {
|
|
@@ -2267,7 +2307,7 @@ var _Brizz = class __Brizz {
|
|
|
2267
2307
|
resourceAttributes["service.version"] = resolvedConfig.appVersion;
|
|
2268
2308
|
}
|
|
2269
2309
|
this._sdk = new NodeSDK({
|
|
2270
|
-
spanProcessors: resolvedConfig.disableSpanExporter ? [] : [getSpanProcessor()],
|
|
2310
|
+
spanProcessors: resolvedConfig.disableSpanExporter ? [] : [new InterruptPropagator(), getSpanProcessor()],
|
|
2271
2311
|
metricReader: getMetricsReader(),
|
|
2272
2312
|
resource: resourceFromAttributes3(resourceAttributes),
|
|
2273
2313
|
instrumentations: manualInstrumentations
|
|
@@ -2530,4 +2570,3 @@ try {
|
|
|
2530
2570
|
} catch (error) {
|
|
2531
2571
|
logger.warn("Failed to auto-initialize SDK:", { error });
|
|
2532
2572
|
}
|
|
2533
|
-
//# sourceMappingURL=preload.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brizz/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "OpenTelemetry-based observability SDK for AI applications",
|
|
6
6
|
"keywords": [
|
|
@@ -114,12 +114,16 @@
|
|
|
114
114
|
},
|
|
115
115
|
"peerDependencies": {
|
|
116
116
|
"@langchain/core": "^0.3.0 || ^1.0.0",
|
|
117
|
+
"ai": "*",
|
|
117
118
|
"typescript": ">=5.0.0"
|
|
118
119
|
},
|
|
119
120
|
"peerDependenciesMeta": {
|
|
120
121
|
"@langchain/core": {
|
|
121
122
|
"optional": true
|
|
122
123
|
},
|
|
124
|
+
"ai": {
|
|
125
|
+
"optional": true
|
|
126
|
+
},
|
|
123
127
|
"typescript": {
|
|
124
128
|
"optional": true
|
|
125
129
|
}
|