@brizz/sdk 0.1.20 → 0.1.22

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.js CHANGED
@@ -1,131 +1,22 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
1
3
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
4
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
5
  }) : x)(function(x) {
4
6
  if (typeof require !== "undefined") return require.apply(this, arguments);
5
7
  throw Error('Dynamic require of "' + x + '" is not supported');
6
8
  });
7
-
8
- // src/internal/instrumentation/auto-init.ts
9
- import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
10
- import { registerInstrumentations } from "@opentelemetry/instrumentation";
11
- import { AnthropicInstrumentation } from "@traceloop/instrumentation-anthropic";
12
- import { BedrockInstrumentation } from "@traceloop/instrumentation-bedrock";
13
- import { ChromaDBInstrumentation } from "@traceloop/instrumentation-chromadb";
14
- import { CohereInstrumentation } from "@traceloop/instrumentation-cohere";
15
- import { LlamaIndexInstrumentation } from "@traceloop/instrumentation-llamaindex";
16
- import { OpenAIInstrumentation } from "@traceloop/instrumentation-openai";
17
- import { PineconeInstrumentation } from "@traceloop/instrumentation-pinecone";
18
- import { QdrantInstrumentation } from "@traceloop/instrumentation-qdrant";
19
- import { TogetherInstrumentation } from "@traceloop/instrumentation-together";
20
- import { VertexAIInstrumentation } from "@traceloop/instrumentation-vertexai";
9
+ var __esm = (fn, res) => function __init() {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ };
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
21
16
 
22
17
  // src/internal/logger.ts
23
18
  import { DiagLogLevel } from "@opentelemetry/api";
24
19
  import pino from "pino";
25
- var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
26
- LogLevel2[LogLevel2["NONE"] = 0] = "NONE";
27
- LogLevel2[LogLevel2["ERROR"] = 1] = "ERROR";
28
- LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
29
- LogLevel2[LogLevel2["INFO"] = 3] = "INFO";
30
- LogLevel2[LogLevel2["DEBUG"] = 4] = "DEBUG";
31
- return LogLevel2;
32
- })(LogLevel || {});
33
- var DEFAULT_LOG_LEVEL = 2 /* WARN */;
34
- var PinoLogger = class {
35
- _level = DEFAULT_LOG_LEVEL;
36
- _pinoLogger = null;
37
- constructor() {
38
- const envLevel = this.getLogLevelFromEnv();
39
- this._level = envLevel;
40
- }
41
- /**
42
- * Lazy initialization of Pino logger to ensure it's created AFTER Jest spies
43
- * are set up during tests. This prevents the pino-pretty transport from
44
- * bypassing stdout/stderr spies.
45
- */
46
- ensurePinoLogger() {
47
- if (!this._pinoLogger) {
48
- this._pinoLogger = pino({
49
- name: "Brizz",
50
- level: this.logLevelToPino(this._level),
51
- // Disable transport in test environment to allow proper spy capture
52
- transport: this.isProduction() || this.isTest() ? void 0 : {
53
- target: "pino-pretty",
54
- options: {
55
- singleLine: true,
56
- colorize: true,
57
- translateTime: "HH:MM:ss",
58
- ignore: "pid,hostname",
59
- messageFormat: "[{name}] {msg}"
60
- }
61
- }
62
- });
63
- }
64
- return this._pinoLogger;
65
- }
66
- isProduction() {
67
- return process.env["NODE_ENV"] === "production";
68
- }
69
- isTest() {
70
- return process.env["NODE_ENV"] === "test";
71
- }
72
- getLogLevelFromEnv() {
73
- const envLevel = process.env["BRIZZ_LOG_LEVEL"];
74
- return envLevel ? parseLogLevel(envLevel) : DEFAULT_LOG_LEVEL;
75
- }
76
- logLevelToPino(level) {
77
- switch (level) {
78
- case 4 /* DEBUG */:
79
- return "debug";
80
- case 3 /* INFO */:
81
- return "info";
82
- case 2 /* WARN */:
83
- return "warn";
84
- case 1 /* ERROR */:
85
- return "error";
86
- default:
87
- return "silent";
88
- }
89
- }
90
- formatMeta(meta) {
91
- if (meta.length === 0) {
92
- return {};
93
- }
94
- if (meta.length === 1 && typeof meta[0] === "object" && meta[0] !== null) {
95
- return meta[0];
96
- }
97
- return { metadata: meta };
98
- }
99
- setLevel(level) {
100
- this._level = level;
101
- if (this._pinoLogger) {
102
- this._pinoLogger.level = this.logLevelToPino(level);
103
- }
104
- }
105
- getLevel() {
106
- return this._level;
107
- }
108
- debug = (msg, ...meta) => {
109
- if (this._level >= 4 /* DEBUG */) {
110
- this.ensurePinoLogger().debug(this.formatMeta(meta), msg);
111
- }
112
- };
113
- info = (msg, ...meta) => {
114
- if (this._level >= 3 /* INFO */) {
115
- this.ensurePinoLogger().info(this.formatMeta(meta), msg);
116
- }
117
- };
118
- warn = (msg, ...meta) => {
119
- if (this._level >= 2 /* WARN */) {
120
- this.ensurePinoLogger().warn(this.formatMeta(meta), msg);
121
- }
122
- };
123
- error = (msg, ...meta) => {
124
- if (this._level >= 1 /* ERROR */) {
125
- this.ensurePinoLogger().error(this.formatMeta(meta), msg);
126
- }
127
- };
128
- };
129
20
  function parseLogLevel(level) {
130
21
  if (!level) {
131
22
  return DEFAULT_LOG_LEVEL;
@@ -154,7 +45,6 @@ function parseLogLevel(level) {
154
45
  }
155
46
  }
156
47
  }
157
- var logger = new PinoLogger();
158
48
  function setLogLevel(level) {
159
49
  const resolvedLevel = typeof level === "string" ? parseLogLevel(level) : level;
160
50
  logger.setLevel(resolvedLevel);
@@ -162,8 +52,813 @@ function setLogLevel(level) {
162
52
  function getLogLevel() {
163
53
  return logger.getLevel();
164
54
  }
55
+ var LogLevel, DEFAULT_LOG_LEVEL, PinoLogger, logger;
56
+ var init_logger = __esm({
57
+ "src/internal/logger.ts"() {
58
+ "use strict";
59
+ LogLevel = /* @__PURE__ */ ((LogLevel2) => {
60
+ LogLevel2[LogLevel2["NONE"] = 0] = "NONE";
61
+ LogLevel2[LogLevel2["ERROR"] = 1] = "ERROR";
62
+ LogLevel2[LogLevel2["WARN"] = 2] = "WARN";
63
+ LogLevel2[LogLevel2["INFO"] = 3] = "INFO";
64
+ LogLevel2[LogLevel2["DEBUG"] = 4] = "DEBUG";
65
+ return LogLevel2;
66
+ })(LogLevel || {});
67
+ DEFAULT_LOG_LEVEL = 2 /* WARN */;
68
+ PinoLogger = class {
69
+ _level = DEFAULT_LOG_LEVEL;
70
+ _pinoLogger = null;
71
+ constructor() {
72
+ const envLevel = this.getLogLevelFromEnv();
73
+ this._level = envLevel;
74
+ }
75
+ /**
76
+ * Lazy initialization of Pino logger to ensure it's created AFTER Jest spies
77
+ * are set up during tests. This prevents the pino-pretty transport from
78
+ * bypassing stdout/stderr spies.
79
+ */
80
+ ensurePinoLogger() {
81
+ if (!this._pinoLogger) {
82
+ this._pinoLogger = pino({
83
+ name: "Brizz",
84
+ level: this.logLevelToPino(this._level),
85
+ // Disable transport in test environment to allow proper spy capture
86
+ transport: this.isProduction() || this.isTest() ? void 0 : {
87
+ target: "pino-pretty",
88
+ options: {
89
+ singleLine: true,
90
+ colorize: true,
91
+ translateTime: "HH:MM:ss",
92
+ ignore: "pid,hostname",
93
+ messageFormat: "[{name}] {msg}"
94
+ }
95
+ }
96
+ });
97
+ }
98
+ return this._pinoLogger;
99
+ }
100
+ isProduction() {
101
+ return process.env["NODE_ENV"] === "production";
102
+ }
103
+ isTest() {
104
+ return process.env["NODE_ENV"] === "test";
105
+ }
106
+ getLogLevelFromEnv() {
107
+ const envLevel = process.env["BRIZZ_LOG_LEVEL"];
108
+ return envLevel ? parseLogLevel(envLevel) : DEFAULT_LOG_LEVEL;
109
+ }
110
+ logLevelToPino(level) {
111
+ switch (level) {
112
+ case 4 /* DEBUG */:
113
+ return "debug";
114
+ case 3 /* INFO */:
115
+ return "info";
116
+ case 2 /* WARN */:
117
+ return "warn";
118
+ case 1 /* ERROR */:
119
+ return "error";
120
+ default:
121
+ return "silent";
122
+ }
123
+ }
124
+ formatMeta(meta) {
125
+ if (meta.length === 0) {
126
+ return {};
127
+ }
128
+ if (meta.length === 1 && typeof meta[0] === "object" && meta[0] !== null) {
129
+ return meta[0];
130
+ }
131
+ return { metadata: meta };
132
+ }
133
+ setLevel(level) {
134
+ this._level = level;
135
+ if (this._pinoLogger) {
136
+ this._pinoLogger.level = this.logLevelToPino(level);
137
+ }
138
+ }
139
+ getLevel() {
140
+ return this._level;
141
+ }
142
+ debug = (msg, ...meta) => {
143
+ if (this._level >= 4 /* DEBUG */) {
144
+ this.ensurePinoLogger().debug(this.formatMeta(meta), msg);
145
+ }
146
+ };
147
+ info = (msg, ...meta) => {
148
+ if (this._level >= 3 /* INFO */) {
149
+ this.ensurePinoLogger().info(this.formatMeta(meta), msg);
150
+ }
151
+ };
152
+ warn = (msg, ...meta) => {
153
+ if (this._level >= 2 /* WARN */) {
154
+ this.ensurePinoLogger().warn(this.formatMeta(meta), msg);
155
+ }
156
+ };
157
+ error = (msg, ...meta) => {
158
+ if (this._level >= 1 /* ERROR */) {
159
+ this.ensurePinoLogger().error(this.formatMeta(meta), msg);
160
+ }
161
+ };
162
+ };
163
+ logger = new PinoLogger();
164
+ }
165
+ });
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
+ // src/internal/instrumentation/mcp/session.ts
190
+ import { context } from "@opentelemetry/api";
191
+ function stampAndPropagateSession(span, sessionId, baseContext = context.active()) {
192
+ if (!sessionId) {
193
+ return { context: baseContext, sessionId: null };
194
+ }
195
+ if (span.isRecording()) {
196
+ try {
197
+ span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
198
+ } catch (error) {
199
+ logger.warn(
200
+ `Brizz MCP: failed to stamp session id on span: ${String(error)}`
201
+ );
202
+ }
203
+ }
204
+ try {
205
+ const prev = baseContext.getValue(PROPERTIES_CONTEXT_KEY);
206
+ const merged = prev ? { ...prev, [SESSION_ID]: sessionId } : { [SESSION_ID]: sessionId };
207
+ return {
208
+ context: baseContext.setValue(PROPERTIES_CONTEXT_KEY, merged),
209
+ sessionId
210
+ };
211
+ } catch (error) {
212
+ logger.warn(`Brizz MCP: failed to attach session context: ${String(error)}`);
213
+ return { context: baseContext, sessionId };
214
+ }
215
+ }
216
+ var init_session = __esm({
217
+ "src/internal/instrumentation/mcp/session.ts"() {
218
+ "use strict";
219
+ init_logger();
220
+ init_semantic_conventions();
221
+ }
222
+ });
223
+
224
+ // src/internal/instrumentation/mcp/semantic-conventions.ts
225
+ var MCP_TOOL_NAME, MCP_TOOL_ARGUMENTS, MCP_TOOL_RESULT, MCP_COMPONENT_TYPE, MCP_COMPONENT_TOOL, 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_RESOURCES_READ, METHOD_PROMPTS_GET, METHOD_INITIALIZE;
226
+ var init_semantic_conventions2 = __esm({
227
+ "src/internal/instrumentation/mcp/semantic-conventions.ts"() {
228
+ "use strict";
229
+ MCP_TOOL_NAME = "mcp.tool.name";
230
+ MCP_TOOL_ARGUMENTS = "mcp.tool.arguments";
231
+ MCP_TOOL_RESULT = "mcp.tool.result";
232
+ MCP_COMPONENT_TYPE = "mcp.component.type";
233
+ MCP_COMPONENT_TOOL = "tool";
234
+ MCP_METHOD_NAME = "mcp.method.name";
235
+ MCP_REQUEST_ID = "mcp.request.id";
236
+ MCP_SESSION_ID = "mcp.session.id";
237
+ MCP_PROTOCOL_VERSION = "mcp.protocol.version";
238
+ MCP_RESOURCE_URI = "mcp.resource.uri";
239
+ RPC_SYSTEM = "rpc.system";
240
+ RPC_SYSTEM_MCP = "mcp";
241
+ RPC_RESPONSE_STATUS_CODE = "rpc.response.status_code";
242
+ GEN_AI_TOOL_NAME = "gen_ai.tool.name";
243
+ GEN_AI_PROMPT_NAME = "gen_ai.prompt.name";
244
+ GEN_AI_OPERATION_NAME = "gen_ai.operation.name";
245
+ GEN_AI_OPERATION_EXECUTE_TOOL = "execute_tool";
246
+ NETWORK_TRANSPORT = "network.transport";
247
+ ERROR_TYPE = "error.type";
248
+ ERROR_TYPE_TOOL = "tool_error";
249
+ JSONRPC_REQUEST_ID = "jsonrpc.request.id";
250
+ SPAN_NAME_TOOLS_CALL = "tools/call";
251
+ MAX_ATTRIBUTE_LENGTH = 32 * 1024;
252
+ TRUNCATION_SUFFIX = "\u2026(truncated)";
253
+ METHOD_TOOLS_CALL = "tools/call";
254
+ METHOD_RESOURCES_READ = "resources/read";
255
+ METHOD_PROMPTS_GET = "prompts/get";
256
+ METHOD_INITIALIZE = "initialize";
257
+ }
258
+ });
259
+
260
+ // src/internal/instrumentation/mcp/patches/attributes.ts
261
+ import { SpanStatusCode } from "@opentelemetry/api";
262
+ function deriveSpanName(method, params) {
263
+ try {
264
+ if (method === METHOD_TOOLS_CALL) {
265
+ const name = typeof params?.["name"] === "string" ? params["name"] : "";
266
+ return name ? `${SPAN_NAME_TOOLS_CALL} ${name}` : SPAN_NAME_TOOLS_CALL;
267
+ }
268
+ if (method === METHOD_RESOURCES_READ) {
269
+ const uri = typeof params?.["uri"] === "string" ? params["uri"] : "";
270
+ return uri ? `${METHOD_RESOURCES_READ} ${uri}` : METHOD_RESOURCES_READ;
271
+ }
272
+ if (method === METHOD_PROMPTS_GET) {
273
+ const name = typeof params?.["name"] === "string" ? params["name"] : "";
274
+ return name ? `${METHOD_PROMPTS_GET} ${name}` : METHOD_PROMPTS_GET;
275
+ }
276
+ return method;
277
+ } catch {
278
+ return method || "mcp";
279
+ }
280
+ }
281
+ function applyBaseAttributes(span, request) {
282
+ span.setAttribute(RPC_SYSTEM, RPC_SYSTEM_MCP);
283
+ if (request.method) {
284
+ span.setAttribute(MCP_METHOD_NAME, request.method);
285
+ }
286
+ if (request.id !== void 0 && request.id !== null) {
287
+ const id = String(request.id);
288
+ span.setAttribute(MCP_REQUEST_ID, id);
289
+ span.setAttribute(JSONRPC_REQUEST_ID, id);
290
+ }
291
+ }
292
+ function applyClientRequestAttributes(span, request, transportName) {
293
+ applyBaseAttributes(span, request);
294
+ applyMethodSpecificRequestAttributes(span, request);
295
+ if (transportName) {
296
+ const transport = normalizeTransport(transportName);
297
+ if (transport) {
298
+ span.setAttribute(NETWORK_TRANSPORT, transport);
299
+ }
300
+ }
301
+ }
302
+ function applyServerRequestAttributes(span, request, protocol) {
303
+ applyBaseAttributes(span, request);
304
+ applyMethodSpecificRequestAttributes(span, request);
305
+ if (request.method === METHOD_TOOLS_CALL) {
306
+ const args = request.params?.["arguments"];
307
+ if (args !== void 0) {
308
+ span.setAttribute(MCP_TOOL_ARGUMENTS, serializeForAttribute(args));
309
+ }
310
+ }
311
+ const sessionId = protocol.sessionId ?? protocol._transport?.sessionId;
312
+ if (sessionId) {
313
+ span.setAttribute(MCP_SESSION_ID, String(sessionId));
314
+ }
315
+ }
316
+ function applyMethodSpecificRequestAttributes(span, request) {
317
+ const params = request.params ?? {};
318
+ switch (request.method) {
319
+ case METHOD_TOOLS_CALL: {
320
+ const name = typeof params["name"] === "string" ? params["name"] : "";
321
+ if (name) {
322
+ span.setAttribute(MCP_TOOL_NAME, name);
323
+ span.setAttribute(GEN_AI_TOOL_NAME, name);
324
+ }
325
+ span.setAttribute(MCP_COMPONENT_TYPE, MCP_COMPONENT_TOOL);
326
+ span.setAttribute(GEN_AI_OPERATION_NAME, GEN_AI_OPERATION_EXECUTE_TOOL);
327
+ break;
328
+ }
329
+ case METHOD_RESOURCES_READ: {
330
+ const uri = typeof params["uri"] === "string" ? params["uri"] : "";
331
+ if (uri) {
332
+ span.setAttribute(MCP_RESOURCE_URI, uri);
333
+ }
334
+ break;
335
+ }
336
+ case METHOD_PROMPTS_GET: {
337
+ const name = typeof params["name"] === "string" ? params["name"] : "";
338
+ if (name) {
339
+ span.setAttribute(GEN_AI_PROMPT_NAME, name);
340
+ }
341
+ break;
342
+ }
343
+ default:
344
+ break;
345
+ }
346
+ }
347
+ function applyResultAttributes(span, method, result) {
348
+ if (method === METHOD_INITIALIZE && result && typeof result === "object") {
349
+ const protocolVersion = result["protocolVersion"];
350
+ if (typeof protocolVersion === "string") {
351
+ span.setAttribute(MCP_PROTOCOL_VERSION, protocolVersion);
352
+ }
353
+ return;
354
+ }
355
+ if (method !== METHOD_TOOLS_CALL) {
356
+ return;
357
+ }
358
+ const obj = result && typeof result === "object" ? result : null;
359
+ const content = obj?.["content"] ?? result;
360
+ span.setAttribute(MCP_TOOL_RESULT, serializeForAttribute(content));
361
+ if (obj && obj["isError"] === true) {
362
+ span.setAttribute(ERROR_TYPE, ERROR_TYPE_TOOL);
363
+ const message = extractToolErrorMessage(obj);
364
+ span.setStatus({ code: SpanStatusCode.ERROR, message });
365
+ }
366
+ }
367
+ function applyErrorAttributes(span, err) {
368
+ const error = err;
369
+ const code = error?.code;
370
+ if (typeof code === "number") {
371
+ span.setAttribute(RPC_RESPONSE_STATUS_CODE, code);
372
+ span.setAttribute(ERROR_TYPE, String(code));
373
+ } else if (error?.name === "AbortError") {
374
+ span.setAttribute(ERROR_TYPE, "cancelled");
375
+ } else if (error?.name === "TimeoutError") {
376
+ span.setAttribute(ERROR_TYPE, "timeout");
377
+ } else {
378
+ span.setAttribute(
379
+ ERROR_TYPE,
380
+ error?.constructor?.name || error?.name || "Error"
381
+ );
382
+ }
383
+ try {
384
+ span.recordException(error);
385
+ } catch {
386
+ }
387
+ span.setStatus({
388
+ code: SpanStatusCode.ERROR,
389
+ message: typeof error?.message === "string" ? error.message : void 0
390
+ });
391
+ }
392
+ function serializeForAttribute(value) {
393
+ const raw = rawSerialize(value);
394
+ if (raw.length <= MAX_ATTRIBUTE_LENGTH) {
395
+ return raw;
396
+ }
397
+ return raw.slice(0, MAX_ATTRIBUTE_LENGTH - TRUNCATION_SUFFIX.length) + TRUNCATION_SUFFIX;
398
+ }
399
+ function rawSerialize(value) {
400
+ if (value === null || value === void 0) {
401
+ return "";
402
+ }
403
+ if (typeof value === "string") {
404
+ return value;
405
+ }
406
+ try {
407
+ return JSON.stringify(value);
408
+ } catch {
409
+ try {
410
+ if (value === null || value === void 0) {
411
+ return "";
412
+ }
413
+ const tag = Object.prototype.toString.call(value);
414
+ return typeof value.toString === "function" ? (
415
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
416
+ String(value)
417
+ ) : tag;
418
+ } catch {
419
+ return "";
420
+ }
421
+ }
422
+ }
423
+ function extractToolErrorMessage(result) {
424
+ const content = result["content"];
425
+ if (Array.isArray(content)) {
426
+ for (const item of content) {
427
+ if (item && typeof item === "object") {
428
+ const text = item["text"];
429
+ if (typeof text === "string") {
430
+ return text;
431
+ }
432
+ }
433
+ }
434
+ }
435
+ return void 0;
436
+ }
437
+ function normalizeTransport(ctorName) {
438
+ const name = ctorName.toLowerCase();
439
+ if (name.includes("stdio")) {
440
+ return "stdio";
441
+ }
442
+ if (name.includes("sse")) {
443
+ return "sse";
444
+ }
445
+ if (name.includes("streamablehttp") || name.includes("http")) {
446
+ return "http";
447
+ }
448
+ return null;
449
+ }
450
+ var init_attributes = __esm({
451
+ "src/internal/instrumentation/mcp/patches/attributes.ts"() {
452
+ "use strict";
453
+ init_semantic_conventions2();
454
+ }
455
+ });
456
+
457
+ // src/internal/instrumentation/mcp/patches/protocol.ts
458
+ import { context as context2, propagation, SpanKind, trace } from "@opentelemetry/api";
459
+ function patchProtocolPrototype(prototype, tracer) {
460
+ if (!prototype || typeof prototype !== "object") {
461
+ return false;
462
+ }
463
+ const proto = prototype;
464
+ if (proto[PATCHED_FLAG]) {
465
+ logger.debug("Brizz MCP: Protocol.prototype already patched, skipping");
466
+ return false;
467
+ }
468
+ const originalRequest = proto["request"];
469
+ const originalOnRequest = proto["_onrequest"];
470
+ if (typeof originalRequest === "function") {
471
+ proto["request"] = wrapRequest(originalRequest, tracer);
472
+ } else {
473
+ logger.debug(
474
+ "Brizz MCP: Protocol.prototype.request missing \u2014 skipping CLIENT patch"
475
+ );
476
+ }
477
+ if (typeof originalOnRequest === "function") {
478
+ proto["_onrequest"] = wrapOnRequest(
479
+ originalOnRequest,
480
+ tracer
481
+ );
482
+ } else {
483
+ logger.debug(
484
+ "Brizz MCP: Protocol.prototype._onrequest missing \u2014 skipping SERVER patch"
485
+ );
486
+ }
487
+ proto[PATCHED_FLAG] = true;
488
+ return true;
489
+ }
490
+ function wrapRequest(original, tracer) {
491
+ return function wrappedRequest(...args) {
492
+ const request = args[0];
493
+ if (!request || typeof request !== "object" || !request.method) {
494
+ return original.apply(this, args);
495
+ }
496
+ const span = safeStartClientSpan(tracer, request, this);
497
+ if (!span) {
498
+ return original.apply(this, args);
499
+ }
500
+ return executeAroundSpan(span, request.method, () => {
501
+ const ctx = trace.setSpan(context2.active(), span);
502
+ return context2.with(ctx, () => original.apply(this, args));
503
+ });
504
+ };
505
+ }
506
+ function wrapOnRequest(original, tracer) {
507
+ return function wrappedOnRequest(...args) {
508
+ const request = args[0];
509
+ if (!request || typeof request !== "object" || !request.method) {
510
+ return original.apply(this, args);
511
+ }
512
+ const handlers = this._requestHandlers;
513
+ if (!handlers || typeof handlers.get !== "function") {
514
+ return original.apply(this, args);
515
+ }
516
+ const method = request.method;
517
+ const handler = handlers.get(method) ?? this.fallbackRequestHandler;
518
+ if (!handler) {
519
+ return original.apply(this, args);
520
+ }
521
+ const started = safeStartServerSpan(tracer, request, this);
522
+ if (!started) {
523
+ return original.apply(this, args);
524
+ }
525
+ const { span, spanCtx } = started;
526
+ const wrappedHandler = (req, extra) => context2.with(spanCtx, () => executeHandler(span, method, handler, req, extra));
527
+ const hadEntry = handlers.has(method);
528
+ const prev = handlers.get(method);
529
+ handlers.set(method, wrappedHandler);
530
+ const usedFallback = !hadEntry && this.fallbackRequestHandler === handler;
531
+ const fallbackPrev = usedFallback ? this.fallbackRequestHandler : void 0;
532
+ if (usedFallback) {
533
+ this.fallbackRequestHandler = wrappedHandler;
534
+ }
535
+ try {
536
+ return original.apply(this, args);
537
+ } finally {
538
+ if (hadEntry) {
539
+ handlers.set(method, prev);
540
+ } else {
541
+ handlers.delete(method);
542
+ }
543
+ if (usedFallback) {
544
+ this.fallbackRequestHandler = fallbackPrev;
545
+ }
546
+ }
547
+ };
548
+ }
549
+ function executeAroundSpan(span, method, run) {
550
+ let result;
551
+ try {
552
+ result = run();
553
+ } catch (error) {
554
+ safeApplyErrorAttributes(span, error);
555
+ safeEnd(span);
556
+ throw error;
557
+ }
558
+ if (!isThenable(result)) {
559
+ safeApplyResultAttributes(span, method, result);
560
+ safeEnd(span);
561
+ return result;
562
+ }
563
+ return result.then(
564
+ (value) => {
565
+ safeApplyResultAttributes(span, method, value);
566
+ safeEnd(span);
567
+ return value;
568
+ },
569
+ (error) => {
570
+ safeApplyErrorAttributes(span, error);
571
+ safeEnd(span);
572
+ throw error;
573
+ }
574
+ );
575
+ }
576
+ function executeHandler(span, method, handler, req, extra) {
577
+ return executeAroundSpan(span, method, () => handler(req, extra));
578
+ }
579
+ function safeStartClientSpan(tracer, request, protocol) {
580
+ try {
581
+ const spanName = deriveSpanName(request.method, request.params);
582
+ const span = tracer.startSpan(spanName, { kind: SpanKind.CLIENT });
583
+ applyClientRequestAttributes(
584
+ span,
585
+ request,
586
+ protocol._transport?.constructor?.name
587
+ );
588
+ return span;
589
+ } catch (error) {
590
+ logger.debug(`Brizz MCP: failed to open CLIENT span: ${String(error)}`);
591
+ return null;
592
+ }
593
+ }
594
+ function safeStartServerSpan(tracer, request, protocol) {
595
+ try {
596
+ const parentCtx = extractParentContext(request);
597
+ const spanName = deriveSpanName(request.method, request.params);
598
+ const span = tracer.startSpan(
599
+ spanName,
600
+ { kind: SpanKind.SERVER },
601
+ parentCtx
602
+ );
603
+ applyServerRequestAttributes(span, request, protocol);
604
+ const sessionId = protocol.sessionId ?? protocol._transport?.sessionId;
605
+ const { context: sessCtx } = stampAndPropagateSession(span, sessionId, parentCtx);
606
+ return { span, spanCtx: trace.setSpan(sessCtx, span) };
607
+ } catch (error) {
608
+ logger.debug(`Brizz MCP: failed to open SERVER span: ${String(error)}`);
609
+ return null;
610
+ }
611
+ }
612
+ function extractParentContext(request) {
613
+ try {
614
+ const meta = request.params?._meta;
615
+ if (meta && typeof meta === "object") {
616
+ return propagation.extract(context2.active(), meta);
617
+ }
618
+ } catch (error) {
619
+ logger.debug(
620
+ `Brizz MCP: failed to extract parent context from _meta: ${String(error)}`
621
+ );
622
+ }
623
+ return context2.active();
624
+ }
625
+ function isThenable(value) {
626
+ return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
627
+ }
628
+ function safeApplyResultAttributes(span, method, value) {
629
+ try {
630
+ applyResultAttributes(span, method, value);
631
+ } catch (error) {
632
+ logger.debug(
633
+ `Brizz MCP: failed to apply result attributes: ${String(error)}`
634
+ );
635
+ }
636
+ }
637
+ function safeApplyErrorAttributes(span, err) {
638
+ try {
639
+ applyErrorAttributes(span, err);
640
+ } catch (error) {
641
+ logger.debug(
642
+ `Brizz MCP: failed to apply error attributes: ${String(error)}`
643
+ );
644
+ }
645
+ }
646
+ function safeEnd(span) {
647
+ try {
648
+ span.end();
649
+ } catch (error) {
650
+ logger.debug(`Brizz MCP: failed to end span: ${String(error)}`);
651
+ }
652
+ }
653
+ var PATCHED_FLAG;
654
+ var init_protocol = __esm({
655
+ "src/internal/instrumentation/mcp/patches/protocol.ts"() {
656
+ "use strict";
657
+ init_logger();
658
+ init_session();
659
+ init_attributes();
660
+ PATCHED_FLAG = /* @__PURE__ */ Symbol("brizz.mcp.protocol-patched");
661
+ }
662
+ });
663
+
664
+ // src/internal/version.ts
665
+ function getSDKVersion() {
666
+ return "0.1.22";
667
+ }
668
+ var init_version = __esm({
669
+ "src/internal/version.ts"() {
670
+ "use strict";
671
+ }
672
+ });
673
+
674
+ // src/internal/instrumentation/mcp/version.ts
675
+ var INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION;
676
+ var init_version2 = __esm({
677
+ "src/internal/instrumentation/mcp/version.ts"() {
678
+ "use strict";
679
+ init_version();
680
+ INSTRUMENTATION_NAME = "@brizz/sdk/mcp";
681
+ INSTRUMENTATION_VERSION = getSDKVersion();
682
+ }
683
+ });
684
+
685
+ // src/internal/instrumentation/mcp/instrumentation.ts
686
+ import { MCPInstrumentation as BaseMCPInstrumentation } from "@arizeai/openinference-instrumentation-mcp";
687
+ import { trace as trace2 } from "@opentelemetry/api";
688
+ import { InstrumentationNodeModuleDefinition } from "@opentelemetry/instrumentation";
689
+ function isMCPInstrumentation(value) {
690
+ return !!value && typeof value === "object" && typeof value.instrumentationName === "string";
691
+ }
692
+ var PROTOCOL_MODULE_NAME, PROTOCOL_SUPPORTED_VERSIONS, MCPInstrumentation;
693
+ var init_instrumentation = __esm({
694
+ "src/internal/instrumentation/mcp/instrumentation.ts"() {
695
+ "use strict";
696
+ init_logger();
697
+ init_protocol();
698
+ init_version2();
699
+ PROTOCOL_MODULE_NAME = "@modelcontextprotocol/sdk/shared/protocol.js";
700
+ PROTOCOL_SUPPORTED_VERSIONS = [">=1.0.0 <2"];
701
+ MCPInstrumentation = class extends BaseMCPInstrumentation {
702
+ /**
703
+ * Dedicated Brizz-named tracer for our SERVER + CLIENT spans.
704
+ *
705
+ * Why a separate tracer from the parent class's one: Arize's inherited
706
+ * transport patches don't emit spans (they only inject propagation
707
+ * headers), so using our own tracer here keeps Brizz spans attributed to
708
+ * `@brizz/sdk/mcp` in the dashboard. The parent's `tracer` is a
709
+ * `protected get` (no setter), so fighting it with assignment is the
710
+ * wrong tool.
711
+ */
712
+ brizzTracer;
713
+ constructor(_config) {
714
+ super({ instrumentationConfig: _config?.instrumentationConfig });
715
+ this.brizzTracer = trace2.getTracer(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION);
716
+ }
717
+ /**
718
+ * Extend `super.init()` with our protocol-layer module definition.
719
+ *
720
+ * Arize's `init()` returns definitions for the six transport modules
721
+ * (SSE client/server, stdio client/server, streamable-HTTP client/server)
722
+ * whose `send`/`start` methods get patched for W3C trace-context
723
+ * injection. We append one more: `@modelcontextprotocol/sdk/shared/protocol.js`
724
+ * where our patches open SERVER/CLIENT spans around the handler + outgoing
725
+ * request. If `super.init()` throws (unlikely but possible across Arize
726
+ * versions), we gracefully degrade to protocol-only instrumentation.
727
+ *
728
+ * The cast at the end satisfies the parent's strongly-typed generic
729
+ * without leaking the cast into call sites.
730
+ */
731
+ init() {
732
+ let base;
733
+ try {
734
+ base = super.init() ?? [];
735
+ } catch (error) {
736
+ logger.warn(
737
+ `Brizz MCP: base Arize init() failed \u2014 transport context propagation disabled: ${String(error)}`
738
+ );
739
+ base = [];
740
+ }
741
+ const baseArr = Array.isArray(base) ? base : [base];
742
+ const brizzDef = new InstrumentationNodeModuleDefinition(
743
+ PROTOCOL_MODULE_NAME,
744
+ PROTOCOL_SUPPORTED_VERSIONS,
745
+ (module2) => {
746
+ this.patchProtocolModule(module2);
747
+ return module2;
748
+ },
749
+ (module2) => {
750
+ this.unpatchProtocolModule(module2);
751
+ return module2;
752
+ }
753
+ );
754
+ return [...baseArr, brizzDef];
755
+ }
756
+ /**
757
+ * Manually instrument MCP modules for Next.js/Webpack where the
758
+ * auto-instrumentation module-load hook doesn't fire.
759
+ *
760
+ * Forwards the six transport module fields to the inherited Arize
761
+ * `manuallyInstrument(...)` (context propagation) and applies our
762
+ * protocol patch if `protocolModule` is provided (SERVER/CLIENT spans).
763
+ * Both legs are try/catch-guarded — a failure in one shouldn't prevent
764
+ * the other from taking effect.
765
+ */
766
+ manuallyInstrument(modules) {
767
+ const {
768
+ clientSSEModule,
769
+ serverSSEModule,
770
+ clientStdioModule,
771
+ serverStdioModule,
772
+ clientStreamableHTTPModule,
773
+ serverStreamableHTTPModule,
774
+ protocolModule
775
+ } = modules;
776
+ try {
777
+ super.manuallyInstrument({
778
+ clientSSEModule,
779
+ serverSSEModule,
780
+ clientStdioModule,
781
+ serverStdioModule,
782
+ clientStreamableHTTPModule,
783
+ serverStreamableHTTPModule
784
+ });
785
+ } catch (error) {
786
+ logger.warn(`Brizz MCP: Arize manuallyInstrument(...) failed: ${String(error)}`);
787
+ }
788
+ if (protocolModule) {
789
+ try {
790
+ this.patchProtocolModule(protocolModule);
791
+ } catch (error) {
792
+ logger.warn(
793
+ `Brizz MCP: failed to manually patch Protocol module: ${String(error)}`
794
+ );
795
+ }
796
+ }
797
+ }
798
+ /**
799
+ * Apply the SERVER + CLIENT patch to a loaded `protocol.js` module. Shared
800
+ * by both the automatic module-load callback in `init()` and the manual
801
+ * `manuallyInstrument(...)` path above so there's exactly one place that
802
+ * calls `patchProtocolPrototype`.
803
+ */
804
+ patchProtocolModule(module2) {
805
+ const proto = module2?.Protocol?.prototype;
806
+ if (!proto) {
807
+ logger.debug(
808
+ "Brizz MCP: module does not expose Protocol.prototype \u2014 skipping protocol patches"
809
+ );
810
+ return;
811
+ }
812
+ const ok = patchProtocolPrototype(proto, this.brizzTracer);
813
+ if (ok) {
814
+ logger.debug("Brizz MCP: patched Protocol.prototype for SERVER+CLIENT spans");
815
+ }
816
+ }
817
+ /**
818
+ * Unpatch is intentionally a no-op.
819
+ *
820
+ * `patchProtocolPrototype` wraps methods in place and sets a PATCHED_FLAG
821
+ * Symbol on the prototype to prevent double-patching. Restoring the
822
+ * originals would require us to hold references across module unloads,
823
+ * which isn't a pattern we need — instrumentation rarely gets torn down
824
+ * at runtime, and a process reload is the canonical way to detach.
825
+ */
826
+ unpatchProtocolModule(_module) {
827
+ logger.debug(
828
+ "Brizz MCP: unpatch is a no-op \u2014 reload the process to cleanly detach"
829
+ );
830
+ }
831
+ };
832
+ }
833
+ });
834
+
835
+ // src/internal/instrumentation/mcp/index.ts
836
+ var mcp_exports = {};
837
+ __export(mcp_exports, {
838
+ MCPInstrumentation: () => MCPInstrumentation,
839
+ isMCPInstrumentation: () => isMCPInstrumentation
840
+ });
841
+ var init_mcp = __esm({
842
+ "src/internal/instrumentation/mcp/index.ts"() {
843
+ "use strict";
844
+ init_instrumentation();
845
+ }
846
+ });
165
847
 
166
848
  // src/internal/instrumentation/auto-init.ts
849
+ init_logger();
850
+ import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
851
+ import { registerInstrumentations } from "@opentelemetry/instrumentation";
852
+ import { AnthropicInstrumentation } from "@traceloop/instrumentation-anthropic";
853
+ import { BedrockInstrumentation } from "@traceloop/instrumentation-bedrock";
854
+ import { ChromaDBInstrumentation } from "@traceloop/instrumentation-chromadb";
855
+ import { CohereInstrumentation } from "@traceloop/instrumentation-cohere";
856
+ import { LlamaIndexInstrumentation } from "@traceloop/instrumentation-llamaindex";
857
+ import { OpenAIInstrumentation } from "@traceloop/instrumentation-openai";
858
+ import { PineconeInstrumentation } from "@traceloop/instrumentation-pinecone";
859
+ import { QdrantInstrumentation } from "@traceloop/instrumentation-qdrant";
860
+ import { TogetherInstrumentation } from "@traceloop/instrumentation-together";
861
+ import { VertexAIInstrumentation } from "@traceloop/instrumentation-vertexai";
167
862
  var autoInstrumentationsLoaded = false;
168
863
  var exceptionLogger = (error) => {
169
864
  logger.error(`Exception in instrumentation: ${String(error)}`);
@@ -216,6 +911,20 @@ function loadGenAIInstrumentations() {
216
911
  }
217
912
  return instrumentations;
218
913
  }
914
+ function loadMCPInstrumentation() {
915
+ void (async () => {
916
+ try {
917
+ const { MCPInstrumentation: MCPInstrumentation2 } = await Promise.resolve().then(() => (init_mcp(), mcp_exports));
918
+ const mcp = new MCPInstrumentation2({ exceptionLogger });
919
+ registerInstrumentations({ instrumentations: [mcp] });
920
+ logger.debug("Auto-loaded MCP instrumentation");
921
+ } catch (error) {
922
+ logger.debug(
923
+ `MCP instrumentation not loaded (install @modelcontextprotocol/sdk and @arizeai/openinference-instrumentation-mcp if you want MCP support): ${String(error)}`
924
+ );
925
+ }
926
+ })();
927
+ }
219
928
  function autoInitializeInstrumentations() {
220
929
  if (autoInstrumentationsLoaded) {
221
930
  return;
@@ -223,6 +932,7 @@ function autoInitializeInstrumentations() {
223
932
  try {
224
933
  const nodeInstrumentations = loadNodeAutoInstrumentations();
225
934
  const genAIInstrumentations = loadGenAIInstrumentations();
935
+ loadMCPInstrumentation();
226
936
  autoInstrumentationsLoaded = true;
227
937
  logger.info(
228
938
  `Auto-initialization complete: ${nodeInstrumentations.length} node + ${genAIInstrumentations.length} GenAI instrumentations`
@@ -239,6 +949,7 @@ import { resourceFromAttributes as resourceFromAttributes3 } from "@opentelemetr
239
949
  import { NodeSDK } from "@opentelemetry/sdk-node";
240
950
 
241
951
  // src/internal/config.ts
952
+ init_logger();
242
953
  function resolveConfig(options) {
243
954
  const envLogLevel = process.env["BRIZZ_LOG_LEVEL"] || options.logLevel?.toString() || DEFAULT_LOG_LEVEL.toString();
244
955
  let resolvedLogLevel;
@@ -327,6 +1038,8 @@ var BRIZZ_SDK_LANGUAGE = "brizz.sdk.language";
327
1038
  var SDK_LANGUAGE = "typescript";
328
1039
 
329
1040
  // src/internal/instrumentation/registry.ts
1041
+ init_logger();
1042
+ init_mcp();
330
1043
  import { AnthropicInstrumentation as AnthropicInstrumentation2 } from "@traceloop/instrumentation-anthropic";
331
1044
  import { BedrockInstrumentation as BedrockInstrumentation2 } from "@traceloop/instrumentation-bedrock";
332
1045
  import { ChromaDBInstrumentation as ChromaDBInstrumentation2 } from "@traceloop/instrumentation-chromadb";
@@ -441,6 +1154,14 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
441
1154
  }
442
1155
  })();
443
1156
  }
1157
+ if (this.manualModules?.mcp) {
1158
+ try {
1159
+ new MCPInstrumentation({ exceptionLogger: exceptionLogger2 }).manuallyInstrument(this.manualModules.mcp);
1160
+ logger.debug("Manual instrumentation enabled for MCP");
1161
+ } catch (error) {
1162
+ logger.error(`Failed to apply MCP instrumentation: ${String(error)}`);
1163
+ }
1164
+ }
444
1165
  }
445
1166
  };
446
1167
 
@@ -451,14 +1172,12 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
451
1172
  import {
452
1173
  LoggerProvider
453
1174
  } from "@opentelemetry/sdk-logs";
454
-
455
- // src/internal/version.ts
456
- function getSDKVersion() {
457
- return "0.1.20";
458
- }
1175
+ init_logger();
1176
+ init_version();
459
1177
 
460
1178
  // src/internal/log/processors/log-processor.ts
461
- import { context } from "@opentelemetry/api";
1179
+ init_logger();
1180
+ import { context as context3 } from "@opentelemetry/api";
462
1181
  import { BatchLogRecordProcessor, SimpleLogRecordProcessor } from "@opentelemetry/sdk-logs";
463
1182
 
464
1183
  // src/internal/masking/patterns.ts
@@ -870,6 +1589,7 @@ var DEFAULT_PII_PATTERNS = [
870
1589
  ];
871
1590
 
872
1591
  // src/internal/masking/utils.ts
1592
+ init_logger();
873
1593
  function isValidPatternName(name) {
874
1594
  return /^[a-zA-Z0-9_]+$/.test(name);
875
1595
  }
@@ -1085,23 +1805,8 @@ function maskAttributes(attributes, rules, outputOriginalValue = false) {
1085
1805
  return maskedAttributes;
1086
1806
  }
1087
1807
 
1088
- // src/internal/semantic-conventions.ts
1089
- import { createContextKey } from "@opentelemetry/api";
1090
- var BRIZZ = "brizz";
1091
- var PROPERTIES = "properties";
1092
- var SESSION_ID = "session.id";
1093
- var PROPERTIES_CONTEXT_KEY = createContextKey(PROPERTIES);
1094
- var SESSION_OBJECT_CONTEXT_KEY = createContextKey("brizz.session.object");
1095
- var SESSION_INPUT = "brizz.session.input";
1096
- var SESSION_OUTPUT = "brizz.session.output";
1097
- var SESSION_INPUT_CONTEXT = "brizz.session.input.context";
1098
- var SESSION_OUTPUT_CONTEXT = "brizz.session.output.context";
1099
- var SESSION_SPAN_NAME = "brizz.start_session";
1100
- var SESSION_TITLE_SPAN_NAME = "brizz.session_title";
1101
- var SESSION_TITLE_GENERATION = "session.title_generation";
1102
- var SESSION_TITLE = "brizz.session.title";
1103
-
1104
1808
  // src/internal/log/processors/log-processor.ts
1809
+ init_semantic_conventions();
1105
1810
  var DEFAULT_LOG_MASKING_RULES = [
1106
1811
  {
1107
1812
  mode: "partial",
@@ -1120,7 +1825,7 @@ var BrizzSimpleLogRecordProcessor = class extends SimpleLogRecordProcessor {
1120
1825
  if (maskingConfig) {
1121
1826
  maskLog(logRecord, maskingConfig);
1122
1827
  }
1123
- const associationProperties = context.active().getValue(PROPERTIES_CONTEXT_KEY);
1828
+ const associationProperties = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
1124
1829
  if (associationProperties) {
1125
1830
  for (const [key, value] of Object.entries(associationProperties)) {
1126
1831
  logRecord.setAttribute(`${BRIZZ}.${key}`, value);
@@ -1140,7 +1845,7 @@ var BrizzBatchLogRecordProcessor = class extends BatchLogRecordProcessor {
1140
1845
  if (maskingConfig) {
1141
1846
  maskLog(logRecord, maskingConfig);
1142
1847
  }
1143
- const associationProperties = context.active().getValue(PROPERTIES_CONTEXT_KEY);
1848
+ const associationProperties = context3.active().getValue(PROPERTIES_CONTEXT_KEY);
1144
1849
  if (associationProperties) {
1145
1850
  for (const [key, value] of Object.entries(associationProperties)) {
1146
1851
  logRecord.setAttribute(`${BRIZZ}.${key}`, value);
@@ -1359,7 +2064,11 @@ function emitEvent(name, attributes, body, severityNumber = SeverityNumber.INFO)
1359
2064
  return LoggingModule.getInstance().emitEvent(name, attributes, body, severityNumber);
1360
2065
  }
1361
2066
 
2067
+ // src/internal/sdk.ts
2068
+ init_logger();
2069
+
1362
2070
  // src/internal/metric/metrics.ts
2071
+ init_logger();
1363
2072
  import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
1364
2073
  import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
1365
2074
  var MetricsModule = class _MetricsModule {
@@ -1462,11 +2171,14 @@ function getMetricsReader() {
1462
2171
  }
1463
2172
 
1464
2173
  // src/internal/trace/tracing.ts
2174
+ init_logger();
1465
2175
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
1466
2176
 
1467
2177
  // src/internal/trace/exporters/span-exporter.ts
1468
2178
  import { ExportResultCode } from "@opentelemetry/core";
1469
2179
  import { resourceFromAttributes as resourceFromAttributes2 } from "@opentelemetry/resources";
2180
+ init_logger();
2181
+ init_version();
1470
2182
  var BrizzSpanExporter = class {
1471
2183
  _delegate;
1472
2184
  _brizzResource;
@@ -1533,13 +2245,15 @@ var BrizzSpanExporter = class {
1533
2245
  };
1534
2246
 
1535
2247
  // src/internal/trace/processors/span-processor.ts
1536
- import { context as context2 } from "@opentelemetry/api";
2248
+ init_logger();
2249
+ import { context as context4 } from "@opentelemetry/api";
1537
2250
  import {
1538
2251
  BatchSpanProcessor,
1539
2252
  SimpleSpanProcessor
1540
2253
  } from "@opentelemetry/sdk-trace-base";
2254
+ init_semantic_conventions();
1541
2255
  function applyContextAttributes(span) {
1542
- const sessionProperties = context2.active().getValue(PROPERTIES_CONTEXT_KEY);
2256
+ const sessionProperties = context4.active().getValue(PROPERTIES_CONTEXT_KEY);
1543
2257
  if (sessionProperties) {
1544
2258
  for (const [key, value] of Object.entries(sessionProperties)) {
1545
2259
  span.setAttribute(`${BRIZZ}.${key}`, value);
@@ -1739,13 +2453,26 @@ function getSpanProcessor() {
1739
2453
  }
1740
2454
 
1741
2455
  // src/internal/trace/session.ts
1742
- import { context as context3, trace, SpanStatusCode } from "@opentelemetry/api";
2456
+ init_semantic_conventions();
2457
+ import { context as context5, trace as trace3, SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
2458
+ function setCurrentSpanCustomProperties(properties) {
2459
+ const current = trace3.getActiveSpan();
2460
+ if (!current || !current.isRecording()) {
2461
+ return;
2462
+ }
2463
+ for (const [key, value] of Object.entries(properties)) {
2464
+ try {
2465
+ current.setAttribute(`${BRIZZ}.${key}`, value);
2466
+ } catch {
2467
+ }
2468
+ }
2469
+ }
1743
2470
  function callWithProperties(properties, fn, thisArg, ...args) {
1744
- const base = context3.active();
2471
+ const base = context5.active();
1745
2472
  const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
1746
2473
  const merged = prev ? { ...prev, ...properties } : properties;
1747
2474
  const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
1748
- return context3.with(next, fn, thisArg, ...args);
2475
+ return context5.with(next, fn, thisArg, ...args);
1749
2476
  }
1750
2477
  function withProperties(properties, fn, thisArg) {
1751
2478
  return function wrapped(...args) {
@@ -1787,9 +2514,9 @@ var Session = class {
1787
2514
  * @param text - Text to append (null becomes a null/"hide marker")
1788
2515
  * @param context - Optional per-turn context bag to attach to this turn
1789
2516
  */
1790
- setInput(text, context4) {
2517
+ setInput(text, context6) {
1791
2518
  this.inputs.push(text);
1792
- this.inputContexts.push(context4 ?? {});
2519
+ this.inputContexts.push(context6 ?? {});
1793
2520
  this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
1794
2521
  this.span.setAttribute(SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
1795
2522
  }
@@ -1803,9 +2530,9 @@ var Session = class {
1803
2530
  * @param text - Text to append (null becomes a null/"hide marker")
1804
2531
  * @param context - Optional per-turn context bag to attach to this turn
1805
2532
  */
1806
- setOutput(text, context4) {
2533
+ setOutput(text, context6) {
1807
2534
  this.outputs.push(text);
1808
- this.outputContexts.push(context4 ?? {});
2535
+ this.outputContexts.push(context6 ?? {});
1809
2536
  this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
1810
2537
  this.span.setAttribute(SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
1811
2538
  }
@@ -1844,12 +2571,12 @@ var SessionTitle = class {
1844
2571
  }
1845
2572
  };
1846
2573
  function getActiveSession() {
1847
- return context3.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
2574
+ return context5.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
1848
2575
  }
1849
2576
  function startSession(sessionId, callback, extraProperties, options) {
1850
2577
  const isTitle = options?.mode === "title";
1851
2578
  const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
1852
- const tracer = trace.getTracer("@brizz/sdk");
2579
+ const tracer = trace3.getTracer("@brizz/sdk");
1853
2580
  return tracer.startActiveSpan(spanName, (span) => {
1854
2581
  span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
1855
2582
  if (extraProperties) {
@@ -1868,8 +2595,8 @@ function startSession(sessionId, callback, extraProperties, options) {
1868
2595
  }
1869
2596
  }
1870
2597
  return callWithProperties(contextProperties, () => {
1871
- const sessionCtx = context3.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
1872
- return context3.with(sessionCtx, () => {
2598
+ const sessionCtx = context5.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
2599
+ return context5.with(sessionCtx, () => {
1873
2600
  try {
1874
2601
  const result = callback(session);
1875
2602
  if (result && typeof result.then === "function") {
@@ -1878,7 +2605,7 @@ function startSession(sessionId, callback, extraProperties, options) {
1878
2605
  return value;
1879
2606
  }).catch((error) => {
1880
2607
  span.recordException(error);
1881
- span.setStatus({ code: SpanStatusCode.ERROR });
2608
+ span.setStatus({ code: SpanStatusCode2.ERROR });
1882
2609
  span.end();
1883
2610
  throw error;
1884
2611
  });
@@ -1887,7 +2614,7 @@ function startSession(sessionId, callback, extraProperties, options) {
1887
2614
  return result;
1888
2615
  } catch (error) {
1889
2616
  span.recordException(error);
1890
- span.setStatus({ code: SpanStatusCode.ERROR });
2617
+ span.setStatus({ code: SpanStatusCode2.ERROR });
1891
2618
  span.end();
1892
2619
  throw error;
1893
2620
  }
@@ -1897,7 +2624,7 @@ function startSession(sessionId, callback, extraProperties, options) {
1897
2624
  }
1898
2625
  function startSessionTitle(callback, options) {
1899
2626
  const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
1900
- const tracer = trace.getTracer("@brizz/sdk");
2627
+ const tracer = trace3.getTracer("@brizz/sdk");
1901
2628
  return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
1902
2629
  if (resolvedSessionId) {
1903
2630
  span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
@@ -1916,7 +2643,7 @@ function startSessionTitle(callback, options) {
1916
2643
  return value;
1917
2644
  }).catch((error) => {
1918
2645
  span.recordException(error);
1919
- span.setStatus({ code: SpanStatusCode.ERROR });
2646
+ span.setStatus({ code: SpanStatusCode2.ERROR });
1920
2647
  span.end();
1921
2648
  throw error;
1922
2649
  });
@@ -1925,7 +2652,7 @@ function startSessionTitle(callback, options) {
1925
2652
  return result;
1926
2653
  } catch (error) {
1927
2654
  span.recordException(error);
1928
- span.setStatus({ code: SpanStatusCode.ERROR });
2655
+ span.setStatus({ code: SpanStatusCode2.ERROR });
1929
2656
  span.end();
1930
2657
  throw error;
1931
2658
  }
@@ -1934,6 +2661,7 @@ function startSessionTitle(callback, options) {
1934
2661
  }
1935
2662
 
1936
2663
  // src/internal/sdk.ts
2664
+ init_version();
1937
2665
  var _Brizz = class __Brizz {
1938
2666
  static instance = null;
1939
2667
  /** Flag indicating if SDK initialization has completed successfully */
@@ -2131,9 +2859,11 @@ var _Brizz = class __Brizz {
2131
2859
  var Brizz = new _Brizz();
2132
2860
 
2133
2861
  // src/index.ts
2862
+ init_logger();
2134
2863
  import { SeverityNumber as SeverityNumber2 } from "@opentelemetry/api-logs";
2135
2864
 
2136
2865
  // src/node/runtime.ts
2866
+ init_logger();
2137
2867
  function detectRuntime() {
2138
2868
  const [major, minor] = process.versions.node.split(".").map(Number);
2139
2869
  const noNodeJSGlobals = typeof __filename === "undefined" && typeof __dirname === "undefined";
@@ -2202,6 +2932,7 @@ export {
2202
2932
  logger,
2203
2933
  maskAttributes,
2204
2934
  maskValue,
2935
+ setCurrentSpanCustomProperties,
2205
2936
  setLogLevel,
2206
2937
  startSession,
2207
2938
  startSessionTitle,