@brizz/sdk 0.1.22 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -25
- package/dist/index.cjs +307 -348
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +277 -318
- package/dist/preload.cjs +282 -330
- package/dist/preload.js +265 -313
- package/package.json +3 -3
- 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.cjs
CHANGED
|
@@ -180,17 +180,141 @@ var init_logger = __esm({
|
|
|
180
180
|
}
|
|
181
181
|
});
|
|
182
182
|
|
|
183
|
-
// src/internal/semantic-conventions.ts
|
|
184
|
-
var
|
|
183
|
+
// src/internal/instrumentation/mcp/semantic-conventions.ts
|
|
184
|
+
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;
|
|
185
185
|
var init_semantic_conventions = __esm({
|
|
186
|
-
"src/internal/semantic-conventions.ts"() {
|
|
186
|
+
"src/internal/instrumentation/mcp/semantic-conventions.ts"() {
|
|
187
|
+
"use strict";
|
|
188
|
+
MCP_TOOL_NAME = "mcp.tool.name";
|
|
189
|
+
MCP_TOOL_ARGUMENTS = "mcp.tool.arguments";
|
|
190
|
+
MCP_TOOL_RESULT = "mcp.tool.result";
|
|
191
|
+
MCP_COMPONENT_TYPE = "mcp.component.type";
|
|
192
|
+
MCP_COMPONENT_TOOL = "tool";
|
|
193
|
+
MCP_COMPONENT_TOOL_SCHEMA = "tool_schema";
|
|
194
|
+
MCP_TOOL_SCHEMA_PARAMETERS = "mcp.tool.schema.parameters";
|
|
195
|
+
MCP_TOOL_SCHEMA_OUTPUT = "mcp.tool.schema.output";
|
|
196
|
+
MCP_TOOL_DESCRIPTION = "mcp.tool.description";
|
|
197
|
+
SPAN_NAME_TOOL_REGISTER = "mcp.tool.register";
|
|
198
|
+
MCP_METHOD_NAME = "mcp.method.name";
|
|
199
|
+
MCP_REQUEST_ID = "mcp.request.id";
|
|
200
|
+
MCP_SESSION_ID = "mcp.session.id";
|
|
201
|
+
MCP_PROTOCOL_VERSION = "mcp.protocol.version";
|
|
202
|
+
MCP_RESOURCE_URI = "mcp.resource.uri";
|
|
203
|
+
RPC_SYSTEM = "rpc.system";
|
|
204
|
+
RPC_SYSTEM_MCP = "mcp";
|
|
205
|
+
RPC_RESPONSE_STATUS_CODE = "rpc.response.status_code";
|
|
206
|
+
GEN_AI_TOOL_NAME = "gen_ai.tool.name";
|
|
207
|
+
GEN_AI_PROMPT_NAME = "gen_ai.prompt.name";
|
|
208
|
+
GEN_AI_OPERATION_NAME = "gen_ai.operation.name";
|
|
209
|
+
GEN_AI_OPERATION_EXECUTE_TOOL = "execute_tool";
|
|
210
|
+
NETWORK_TRANSPORT = "network.transport";
|
|
211
|
+
ERROR_TYPE = "error.type";
|
|
212
|
+
ERROR_TYPE_TOOL = "tool_error";
|
|
213
|
+
JSONRPC_REQUEST_ID = "jsonrpc.request.id";
|
|
214
|
+
SPAN_NAME_TOOLS_CALL = "tools/call";
|
|
215
|
+
MAX_ATTRIBUTE_LENGTH = 32 * 1024;
|
|
216
|
+
TRUNCATION_SUFFIX = "\u2026(truncated)";
|
|
217
|
+
METHOD_TOOLS_CALL = "tools/call";
|
|
218
|
+
METHOD_TOOLS_LIST = "tools/list";
|
|
219
|
+
METHOD_RESOURCES_READ = "resources/read";
|
|
220
|
+
METHOD_PROMPTS_GET = "prompts/get";
|
|
221
|
+
METHOD_INITIALIZE = "initialize";
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// src/internal/instrumentation/mcp/schemas.ts
|
|
226
|
+
function truncateSchemaAttr(value) {
|
|
227
|
+
if (value.length <= _MAX_SCHEMA_ATTR_BYTES) {
|
|
228
|
+
return value;
|
|
229
|
+
}
|
|
230
|
+
return `{"_truncated":true,"original_length":${value.length}}`;
|
|
231
|
+
}
|
|
232
|
+
function safeStringify(value) {
|
|
233
|
+
if (value === null || value === void 0) {
|
|
234
|
+
return "";
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
return JSON.stringify(value);
|
|
238
|
+
} catch {
|
|
239
|
+
return "";
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function emitSchemaSpansFromListResponse(result, transportSessionId, tracer) {
|
|
243
|
+
if (!transportSessionId) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const tools = extractTools(result);
|
|
247
|
+
if (tools === void 0) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
for (const tool of tools) {
|
|
251
|
+
const name = typeof tool.name === "string" ? tool.name : void 0;
|
|
252
|
+
if (!name) {
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
const span = tracer.startSpan(`${SPAN_NAME_TOOL_REGISTER} ${name}`, {
|
|
256
|
+
kind: import_api2.SpanKind.INTERNAL
|
|
257
|
+
});
|
|
258
|
+
try {
|
|
259
|
+
stampSchemaAttributes(span, name, transportSessionId, tool);
|
|
260
|
+
span.setStatus({ code: import_api2.SpanStatusCode.OK });
|
|
261
|
+
} finally {
|
|
262
|
+
span.end();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function stampSchemaAttributes(span, toolName, transportSessionId, tool) {
|
|
267
|
+
if (!span.isRecording()) {
|
|
268
|
+
logger.warn(
|
|
269
|
+
`Brizz MCP: schema span is not recording; dropping attributes for ${toolName}`
|
|
270
|
+
);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const description = typeof tool.description === "string" ? tool.description : "";
|
|
274
|
+
const parameters = truncateSchemaAttr(safeStringify(tool.inputSchema));
|
|
275
|
+
const outputSchema = tool.outputSchema !== void 0 && tool.outputSchema !== null ? truncateSchemaAttr(safeStringify(tool.outputSchema)) : "";
|
|
276
|
+
span.setAttribute(RPC_SYSTEM, RPC_SYSTEM_MCP);
|
|
277
|
+
span.setAttribute(MCP_COMPONENT_TYPE, MCP_COMPONENT_TOOL_SCHEMA);
|
|
278
|
+
span.setAttribute(MCP_SESSION_ID, transportSessionId);
|
|
279
|
+
span.setAttribute(MCP_TOOL_NAME, toolName);
|
|
280
|
+
span.setAttribute(MCP_TOOL_SCHEMA_PARAMETERS, parameters);
|
|
281
|
+
span.setAttribute(MCP_TOOL_SCHEMA_OUTPUT, outputSchema);
|
|
282
|
+
span.setAttribute(MCP_TOOL_DESCRIPTION, description);
|
|
283
|
+
}
|
|
284
|
+
function extractTools(result) {
|
|
285
|
+
if (!result || typeof result !== "object") {
|
|
286
|
+
return void 0;
|
|
287
|
+
}
|
|
288
|
+
const tools = result.tools;
|
|
289
|
+
if (!Array.isArray(tools)) {
|
|
290
|
+
return void 0;
|
|
291
|
+
}
|
|
292
|
+
return tools.filter(
|
|
293
|
+
(t) => t !== null && typeof t === "object"
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
var import_api2, _MAX_SCHEMA_ATTR_BYTES;
|
|
297
|
+
var init_schemas = __esm({
|
|
298
|
+
"src/internal/instrumentation/mcp/schemas.ts"() {
|
|
187
299
|
"use strict";
|
|
188
300
|
import_api2 = require("@opentelemetry/api");
|
|
301
|
+
init_logger();
|
|
302
|
+
init_semantic_conventions();
|
|
303
|
+
_MAX_SCHEMA_ATTR_BYTES = 4e3;
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// src/internal/semantic-conventions.ts
|
|
308
|
+
var import_api3, 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;
|
|
309
|
+
var init_semantic_conventions2 = __esm({
|
|
310
|
+
"src/internal/semantic-conventions.ts"() {
|
|
311
|
+
"use strict";
|
|
312
|
+
import_api3 = require("@opentelemetry/api");
|
|
189
313
|
BRIZZ = "brizz";
|
|
190
314
|
PROPERTIES = "properties";
|
|
191
315
|
SESSION_ID = "session.id";
|
|
192
|
-
PROPERTIES_CONTEXT_KEY = (0,
|
|
193
|
-
SESSION_OBJECT_CONTEXT_KEY = (0,
|
|
316
|
+
PROPERTIES_CONTEXT_KEY = (0, import_api3.createContextKey)(PROPERTIES);
|
|
317
|
+
SESSION_OBJECT_CONTEXT_KEY = (0, import_api3.createContextKey)("brizz.session.object");
|
|
194
318
|
SESSION_INPUT = "brizz.session.input";
|
|
195
319
|
SESSION_OUTPUT = "brizz.session.output";
|
|
196
320
|
SESSION_INPUT_CONTEXT = "brizz.session.input.context";
|
|
@@ -203,7 +327,7 @@ var init_semantic_conventions = __esm({
|
|
|
203
327
|
});
|
|
204
328
|
|
|
205
329
|
// src/internal/instrumentation/mcp/session.ts
|
|
206
|
-
function stampAndPropagateSession(span, sessionId, baseContext =
|
|
330
|
+
function stampAndPropagateSession(span, sessionId, baseContext = import_api4.context.active()) {
|
|
207
331
|
if (!sessionId) {
|
|
208
332
|
return { context: baseContext, sessionId: null };
|
|
209
333
|
}
|
|
@@ -228,49 +352,13 @@ function stampAndPropagateSession(span, sessionId, baseContext = import_api3.con
|
|
|
228
352
|
return { context: baseContext, sessionId };
|
|
229
353
|
}
|
|
230
354
|
}
|
|
231
|
-
var
|
|
355
|
+
var import_api4;
|
|
232
356
|
var init_session = __esm({
|
|
233
357
|
"src/internal/instrumentation/mcp/session.ts"() {
|
|
234
358
|
"use strict";
|
|
235
|
-
|
|
359
|
+
import_api4 = require("@opentelemetry/api");
|
|
236
360
|
init_logger();
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// src/internal/instrumentation/mcp/semantic-conventions.ts
|
|
242
|
-
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;
|
|
243
|
-
var init_semantic_conventions2 = __esm({
|
|
244
|
-
"src/internal/instrumentation/mcp/semantic-conventions.ts"() {
|
|
245
|
-
"use strict";
|
|
246
|
-
MCP_TOOL_NAME = "mcp.tool.name";
|
|
247
|
-
MCP_TOOL_ARGUMENTS = "mcp.tool.arguments";
|
|
248
|
-
MCP_TOOL_RESULT = "mcp.tool.result";
|
|
249
|
-
MCP_COMPONENT_TYPE = "mcp.component.type";
|
|
250
|
-
MCP_COMPONENT_TOOL = "tool";
|
|
251
|
-
MCP_METHOD_NAME = "mcp.method.name";
|
|
252
|
-
MCP_REQUEST_ID = "mcp.request.id";
|
|
253
|
-
MCP_SESSION_ID = "mcp.session.id";
|
|
254
|
-
MCP_PROTOCOL_VERSION = "mcp.protocol.version";
|
|
255
|
-
MCP_RESOURCE_URI = "mcp.resource.uri";
|
|
256
|
-
RPC_SYSTEM = "rpc.system";
|
|
257
|
-
RPC_SYSTEM_MCP = "mcp";
|
|
258
|
-
RPC_RESPONSE_STATUS_CODE = "rpc.response.status_code";
|
|
259
|
-
GEN_AI_TOOL_NAME = "gen_ai.tool.name";
|
|
260
|
-
GEN_AI_PROMPT_NAME = "gen_ai.prompt.name";
|
|
261
|
-
GEN_AI_OPERATION_NAME = "gen_ai.operation.name";
|
|
262
|
-
GEN_AI_OPERATION_EXECUTE_TOOL = "execute_tool";
|
|
263
|
-
NETWORK_TRANSPORT = "network.transport";
|
|
264
|
-
ERROR_TYPE = "error.type";
|
|
265
|
-
ERROR_TYPE_TOOL = "tool_error";
|
|
266
|
-
JSONRPC_REQUEST_ID = "jsonrpc.request.id";
|
|
267
|
-
SPAN_NAME_TOOLS_CALL = "tools/call";
|
|
268
|
-
MAX_ATTRIBUTE_LENGTH = 32 * 1024;
|
|
269
|
-
TRUNCATION_SUFFIX = "\u2026(truncated)";
|
|
270
|
-
METHOD_TOOLS_CALL = "tools/call";
|
|
271
|
-
METHOD_RESOURCES_READ = "resources/read";
|
|
272
|
-
METHOD_PROMPTS_GET = "prompts/get";
|
|
273
|
-
METHOD_INITIALIZE = "initialize";
|
|
361
|
+
init_semantic_conventions2();
|
|
274
362
|
}
|
|
275
363
|
});
|
|
276
364
|
|
|
@@ -377,7 +465,7 @@ function applyResultAttributes(span, method, result) {
|
|
|
377
465
|
if (obj && obj["isError"] === true) {
|
|
378
466
|
span.setAttribute(ERROR_TYPE, ERROR_TYPE_TOOL);
|
|
379
467
|
const message = extractToolErrorMessage(obj);
|
|
380
|
-
span.setStatus({ code:
|
|
468
|
+
span.setStatus({ code: import_api5.SpanStatusCode.ERROR, message });
|
|
381
469
|
}
|
|
382
470
|
}
|
|
383
471
|
function applyErrorAttributes(span, err) {
|
|
@@ -401,7 +489,7 @@ function applyErrorAttributes(span, err) {
|
|
|
401
489
|
} catch {
|
|
402
490
|
}
|
|
403
491
|
span.setStatus({
|
|
404
|
-
code:
|
|
492
|
+
code: import_api5.SpanStatusCode.ERROR,
|
|
405
493
|
message: typeof error?.message === "string" ? error.message : void 0
|
|
406
494
|
});
|
|
407
495
|
}
|
|
@@ -463,12 +551,12 @@ function normalizeTransport(ctorName) {
|
|
|
463
551
|
}
|
|
464
552
|
return null;
|
|
465
553
|
}
|
|
466
|
-
var
|
|
554
|
+
var import_api5;
|
|
467
555
|
var init_attributes = __esm({
|
|
468
556
|
"src/internal/instrumentation/mcp/patches/attributes.ts"() {
|
|
469
557
|
"use strict";
|
|
470
|
-
|
|
471
|
-
|
|
558
|
+
import_api5 = require("@opentelemetry/api");
|
|
559
|
+
init_semantic_conventions();
|
|
472
560
|
}
|
|
473
561
|
});
|
|
474
562
|
|
|
@@ -515,8 +603,8 @@ function wrapRequest(original, tracer) {
|
|
|
515
603
|
return original.apply(this, args);
|
|
516
604
|
}
|
|
517
605
|
return executeAroundSpan(span, request.method, () => {
|
|
518
|
-
const ctx =
|
|
519
|
-
return
|
|
606
|
+
const ctx = import_api6.trace.setSpan(import_api6.context.active(), span);
|
|
607
|
+
return import_api6.context.with(ctx, () => original.apply(this, args));
|
|
520
608
|
});
|
|
521
609
|
};
|
|
522
610
|
}
|
|
@@ -540,7 +628,20 @@ function wrapOnRequest(original, tracer) {
|
|
|
540
628
|
return original.apply(this, args);
|
|
541
629
|
}
|
|
542
630
|
const { span, spanCtx } = started;
|
|
543
|
-
const
|
|
631
|
+
const transportSessionId = this.sessionId ?? this._transport?.sessionId;
|
|
632
|
+
const postResult = method === METHOD_TOOLS_LIST ? (result) => {
|
|
633
|
+
try {
|
|
634
|
+
emitSchemaSpansFromListResponse(result, transportSessionId, tracer);
|
|
635
|
+
} catch (error) {
|
|
636
|
+
logger.warn(
|
|
637
|
+
`Brizz MCP: failed to emit tools/list schema spans: ${String(error)}`
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
} : void 0;
|
|
641
|
+
const wrappedHandler = (req, extra) => import_api6.context.with(
|
|
642
|
+
spanCtx,
|
|
643
|
+
() => executeHandler(span, method, handler, req, extra, postResult)
|
|
644
|
+
);
|
|
544
645
|
const hadEntry = handlers.has(method);
|
|
545
646
|
const prev = handlers.get(method);
|
|
546
647
|
handlers.set(method, wrappedHandler);
|
|
@@ -563,7 +664,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
563
664
|
}
|
|
564
665
|
};
|
|
565
666
|
}
|
|
566
|
-
function executeAroundSpan(span, method, run) {
|
|
667
|
+
function executeAroundSpan(span, method, run, postResult) {
|
|
567
668
|
let result;
|
|
568
669
|
try {
|
|
569
670
|
result = run();
|
|
@@ -574,12 +675,18 @@ function executeAroundSpan(span, method, run) {
|
|
|
574
675
|
}
|
|
575
676
|
if (!isThenable(result)) {
|
|
576
677
|
safeApplyResultAttributes(span, method, result);
|
|
678
|
+
if (postResult) {
|
|
679
|
+
postResult(result);
|
|
680
|
+
}
|
|
577
681
|
safeEnd(span);
|
|
578
682
|
return result;
|
|
579
683
|
}
|
|
580
684
|
return result.then(
|
|
581
685
|
(value) => {
|
|
582
686
|
safeApplyResultAttributes(span, method, value);
|
|
687
|
+
if (postResult) {
|
|
688
|
+
postResult(value);
|
|
689
|
+
}
|
|
583
690
|
safeEnd(span);
|
|
584
691
|
return value;
|
|
585
692
|
},
|
|
@@ -590,13 +697,13 @@ function executeAroundSpan(span, method, run) {
|
|
|
590
697
|
}
|
|
591
698
|
);
|
|
592
699
|
}
|
|
593
|
-
function executeHandler(span, method, handler, req, extra) {
|
|
594
|
-
return executeAroundSpan(span, method, () => handler(req, extra));
|
|
700
|
+
function executeHandler(span, method, handler, req, extra, postResult) {
|
|
701
|
+
return executeAroundSpan(span, method, () => handler(req, extra), postResult);
|
|
595
702
|
}
|
|
596
703
|
function safeStartClientSpan(tracer, request, protocol) {
|
|
597
704
|
try {
|
|
598
705
|
const spanName = deriveSpanName(request.method, request.params);
|
|
599
|
-
const span = tracer.startSpan(spanName, { kind:
|
|
706
|
+
const span = tracer.startSpan(spanName, { kind: import_api6.SpanKind.CLIENT });
|
|
600
707
|
applyClientRequestAttributes(
|
|
601
708
|
span,
|
|
602
709
|
request,
|
|
@@ -614,13 +721,13 @@ function safeStartServerSpan(tracer, request, protocol) {
|
|
|
614
721
|
const spanName = deriveSpanName(request.method, request.params);
|
|
615
722
|
const span = tracer.startSpan(
|
|
616
723
|
spanName,
|
|
617
|
-
{ kind:
|
|
724
|
+
{ kind: import_api6.SpanKind.SERVER },
|
|
618
725
|
parentCtx
|
|
619
726
|
);
|
|
620
727
|
applyServerRequestAttributes(span, request, protocol);
|
|
621
728
|
const sessionId = protocol.sessionId ?? protocol._transport?.sessionId;
|
|
622
729
|
const { context: sessCtx } = stampAndPropagateSession(span, sessionId, parentCtx);
|
|
623
|
-
return { span, spanCtx:
|
|
730
|
+
return { span, spanCtx: import_api6.trace.setSpan(sessCtx, span) };
|
|
624
731
|
} catch (error) {
|
|
625
732
|
logger.debug(`Brizz MCP: failed to open SERVER span: ${String(error)}`);
|
|
626
733
|
return null;
|
|
@@ -630,14 +737,14 @@ function extractParentContext(request) {
|
|
|
630
737
|
try {
|
|
631
738
|
const meta = request.params?._meta;
|
|
632
739
|
if (meta && typeof meta === "object") {
|
|
633
|
-
return
|
|
740
|
+
return import_api6.propagation.extract(import_api6.context.active(), meta);
|
|
634
741
|
}
|
|
635
742
|
} catch (error) {
|
|
636
743
|
logger.debug(
|
|
637
744
|
`Brizz MCP: failed to extract parent context from _meta: ${String(error)}`
|
|
638
745
|
);
|
|
639
746
|
}
|
|
640
|
-
return
|
|
747
|
+
return import_api6.context.active();
|
|
641
748
|
}
|
|
642
749
|
function isThenable(value) {
|
|
643
750
|
return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
@@ -667,12 +774,14 @@ function safeEnd(span) {
|
|
|
667
774
|
logger.debug(`Brizz MCP: failed to end span: ${String(error)}`);
|
|
668
775
|
}
|
|
669
776
|
}
|
|
670
|
-
var
|
|
777
|
+
var import_api6, PATCHED_FLAG;
|
|
671
778
|
var init_protocol = __esm({
|
|
672
779
|
"src/internal/instrumentation/mcp/patches/protocol.ts"() {
|
|
673
780
|
"use strict";
|
|
674
|
-
|
|
781
|
+
import_api6 = require("@opentelemetry/api");
|
|
675
782
|
init_logger();
|
|
783
|
+
init_schemas();
|
|
784
|
+
init_semantic_conventions();
|
|
676
785
|
init_session();
|
|
677
786
|
init_attributes();
|
|
678
787
|
PATCHED_FLAG = /* @__PURE__ */ Symbol("brizz.mcp.protocol-patched");
|
|
@@ -681,7 +790,7 @@ var init_protocol = __esm({
|
|
|
681
790
|
|
|
682
791
|
// src/internal/version.ts
|
|
683
792
|
function getSDKVersion() {
|
|
684
|
-
return "0.1.
|
|
793
|
+
return "0.1.26";
|
|
685
794
|
}
|
|
686
795
|
var init_version = __esm({
|
|
687
796
|
"src/internal/version.ts"() {
|
|
@@ -704,12 +813,12 @@ var init_version2 = __esm({
|
|
|
704
813
|
function isMCPInstrumentation(value) {
|
|
705
814
|
return !!value && typeof value === "object" && typeof value.instrumentationName === "string";
|
|
706
815
|
}
|
|
707
|
-
var import_openinference_instrumentation_mcp,
|
|
816
|
+
var import_openinference_instrumentation_mcp, import_api7, import_instrumentation, PROTOCOL_MODULE_NAME, PROTOCOL_SUPPORTED_VERSIONS, MCPInstrumentation;
|
|
708
817
|
var init_instrumentation = __esm({
|
|
709
818
|
"src/internal/instrumentation/mcp/instrumentation.ts"() {
|
|
710
819
|
"use strict";
|
|
711
820
|
import_openinference_instrumentation_mcp = require("@arizeai/openinference-instrumentation-mcp");
|
|
712
|
-
|
|
821
|
+
import_api7 = require("@opentelemetry/api");
|
|
713
822
|
import_instrumentation = require("@opentelemetry/instrumentation");
|
|
714
823
|
init_logger();
|
|
715
824
|
init_protocol();
|
|
@@ -730,7 +839,7 @@ var init_instrumentation = __esm({
|
|
|
730
839
|
brizzTracer;
|
|
731
840
|
constructor(_config) {
|
|
732
841
|
super({ instrumentationConfig: _config?.instrumentationConfig });
|
|
733
|
-
this.brizzTracer =
|
|
842
|
+
this.brizzTracer = import_api7.trace.getTracer(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION);
|
|
734
843
|
}
|
|
735
844
|
/**
|
|
736
845
|
* Extend `super.init()` with our protocol-layer module definition.
|
|
@@ -998,6 +1107,38 @@ autoInitializeInstrumentations();
|
|
|
998
1107
|
var import_resources3 = require("@opentelemetry/resources");
|
|
999
1108
|
var import_sdk_node = require("@opentelemetry/sdk-node");
|
|
1000
1109
|
|
|
1110
|
+
// src/internal/dsn.ts
|
|
1111
|
+
var PLACEHOLDER_SERVICE = "<service-name>";
|
|
1112
|
+
var SERVICE_NAME_HEADER = "X-Brizz-Service-Name";
|
|
1113
|
+
function parseDSN(dsn) {
|
|
1114
|
+
let parsed;
|
|
1115
|
+
try {
|
|
1116
|
+
parsed = new globalThis.URL(dsn);
|
|
1117
|
+
} catch {
|
|
1118
|
+
return null;
|
|
1119
|
+
}
|
|
1120
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:" || !parsed.username || !parsed.host) {
|
|
1121
|
+
return null;
|
|
1122
|
+
}
|
|
1123
|
+
const scheme = parsed.protocol === "https:" ? "https" : "http";
|
|
1124
|
+
let service;
|
|
1125
|
+
try {
|
|
1126
|
+
service = decodeURIComponent(parsed.pathname.replace(/^\//, ""));
|
|
1127
|
+
} catch {
|
|
1128
|
+
return null;
|
|
1129
|
+
}
|
|
1130
|
+
if (service === "" || service === PLACEHOLDER_SERVICE) {
|
|
1131
|
+
return null;
|
|
1132
|
+
}
|
|
1133
|
+
return {
|
|
1134
|
+
scheme,
|
|
1135
|
+
host: parsed.host,
|
|
1136
|
+
bearer: decodeURIComponent(parsed.username),
|
|
1137
|
+
service,
|
|
1138
|
+
baseUrl: `${scheme}://${parsed.host}`
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1001
1142
|
// src/internal/config.ts
|
|
1002
1143
|
init_logger();
|
|
1003
1144
|
function resolveConfig(options) {
|
|
@@ -1025,6 +1166,7 @@ function resolveConfig(options) {
|
|
|
1025
1166
|
appName: options.appName,
|
|
1026
1167
|
baseUrl: options.baseUrl,
|
|
1027
1168
|
hasApiKey: !!options.apiKey,
|
|
1169
|
+
dsnProvided: !!(process.env["BRIZZ_DSN"] || options.dsn),
|
|
1028
1170
|
disableBatch: options.disableBatch,
|
|
1029
1171
|
logLevel: resolvedLogLevel,
|
|
1030
1172
|
headersCount: Object.keys(options.headers || {}).length,
|
|
@@ -1052,7 +1194,42 @@ function resolveConfig(options) {
|
|
|
1052
1194
|
logLevel: resolvedLogLevel,
|
|
1053
1195
|
masking: resolvedMasking
|
|
1054
1196
|
};
|
|
1055
|
-
|
|
1197
|
+
const dsnInput = process.env["BRIZZ_DSN"] || options.dsn;
|
|
1198
|
+
let parsedDSN = null;
|
|
1199
|
+
if (dsnInput) {
|
|
1200
|
+
const kwargConflicts = [];
|
|
1201
|
+
if (options.apiKey !== void 0) {
|
|
1202
|
+
kwargConflicts.push("apiKey");
|
|
1203
|
+
}
|
|
1204
|
+
if (options.baseUrl !== void 0) {
|
|
1205
|
+
kwargConflicts.push("baseUrl");
|
|
1206
|
+
}
|
|
1207
|
+
if (options.appName !== void 0) {
|
|
1208
|
+
kwargConflicts.push("appName");
|
|
1209
|
+
}
|
|
1210
|
+
if (kwargConflicts.length > 0) {
|
|
1211
|
+
throw new Error(
|
|
1212
|
+
`dsn cannot be combined with kwargs ${kwargConflicts.join(", ")}. The DSN bundles bearer, gateway URL, and service name \u2014 choose one configuration style.`
|
|
1213
|
+
);
|
|
1214
|
+
}
|
|
1215
|
+
const envConflicts = ["BRIZZ_API_KEY", "BRIZZ_BASE_URL", "BRIZZ_APP_NAME"].filter(
|
|
1216
|
+
(name) => process.env[name] !== void 0
|
|
1217
|
+
);
|
|
1218
|
+
if (envConflicts.length > 0) {
|
|
1219
|
+
logger.warn(
|
|
1220
|
+
`Ignoring ${envConflicts.join(", ")} \u2014 dsn / BRIZZ_DSN takes precedence.`
|
|
1221
|
+
);
|
|
1222
|
+
}
|
|
1223
|
+
resolvedConfig.apiKey = void 0;
|
|
1224
|
+
resolvedConfig.baseUrl = "https://telemetry.brizz.dev";
|
|
1225
|
+
resolvedConfig.appName = "unknown-app";
|
|
1226
|
+
parsedDSN = parseDSN(dsnInput);
|
|
1227
|
+
if (parsedDSN) {
|
|
1228
|
+
resolvedConfig.appName = parsedDSN.service;
|
|
1229
|
+
resolvedConfig.baseUrl = parsedDSN.baseUrl;
|
|
1230
|
+
resolvedConfig.apiKey = parsedDSN.bearer;
|
|
1231
|
+
}
|
|
1232
|
+
} else if (resolvedConfig.apiKey) {
|
|
1056
1233
|
resolvedConfig.headers["Authorization"] = `Bearer ${resolvedConfig.apiKey}`;
|
|
1057
1234
|
}
|
|
1058
1235
|
if (process.env["BRIZZ_HEADERS"]) {
|
|
@@ -1067,14 +1244,28 @@ function resolveConfig(options) {
|
|
|
1067
1244
|
throw new Error("Invalid JSON in BRIZZ_HEADERS environment variable", { cause: error });
|
|
1068
1245
|
}
|
|
1069
1246
|
}
|
|
1247
|
+
if (dsnInput) {
|
|
1248
|
+
const authHeaderKeys = /* @__PURE__ */ new Set(["authorization", SERVICE_NAME_HEADER.toLowerCase()]);
|
|
1249
|
+
resolvedConfig.headers = Object.fromEntries(
|
|
1250
|
+
Object.entries(resolvedConfig.headers).filter(
|
|
1251
|
+
([key]) => !authHeaderKeys.has(key.toLowerCase())
|
|
1252
|
+
)
|
|
1253
|
+
);
|
|
1254
|
+
if (parsedDSN) {
|
|
1255
|
+
resolvedConfig.headers["Authorization"] = `Bearer ${parsedDSN.bearer}`;
|
|
1256
|
+
resolvedConfig.headers[SERVICE_NAME_HEADER] = parsedDSN.service;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1070
1259
|
logger.debug("Configuration resolved with environment variables", {
|
|
1071
1260
|
appName: resolvedConfig.appName,
|
|
1072
1261
|
baseUrl: resolvedConfig.baseUrl,
|
|
1073
1262
|
hasApiKey: !!resolvedConfig.apiKey,
|
|
1263
|
+
dsnProvided: !!dsnInput,
|
|
1074
1264
|
disableBatch: resolvedConfig.disableBatch,
|
|
1075
1265
|
envOverrides: {
|
|
1076
1266
|
hasEnvApiKey: !!process.env["BRIZZ_API_KEY"],
|
|
1077
1267
|
hasEnvBaseUrl: !!process.env["BRIZZ_BASE_URL"],
|
|
1268
|
+
hasEnvDsn: !!process.env["BRIZZ_DSN"],
|
|
1078
1269
|
hasEnvBatch: !!process.env["BRIZZ_DISABLE_BATCH"],
|
|
1079
1270
|
hasEnvHeaders: !!process.env["BRIZZ_HEADERS"]
|
|
1080
1271
|
}
|
|
@@ -1224,27 +1415,17 @@ init_logger();
|
|
|
1224
1415
|
init_version();
|
|
1225
1416
|
|
|
1226
1417
|
// src/internal/log/processors/log-processor.ts
|
|
1227
|
-
var
|
|
1418
|
+
var import_api8 = require("@opentelemetry/api");
|
|
1228
1419
|
var import_sdk_logs = require("@opentelemetry/sdk-logs");
|
|
1229
1420
|
init_logger();
|
|
1230
1421
|
|
|
1231
1422
|
// src/internal/masking/patterns.ts
|
|
1232
1423
|
var DEFAULT_PII_PATTERNS = [
|
|
1233
|
-
// Email addresses
|
|
1234
|
-
{
|
|
1235
|
-
name: "email_addresses",
|
|
1236
|
-
pattern: String.raw`\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b`
|
|
1237
|
-
},
|
|
1238
1424
|
// Phone numbers (US format)
|
|
1239
1425
|
{
|
|
1240
1426
|
name: "us_phone_numbers",
|
|
1241
1427
|
pattern: String.raw`(?:^|[\s])(?:\+?1[-.\s]*)?(?:\([0-9]{3}\)\s?[0-9]{3}[-.\s]?[0-9]{4}|[0-9]{3}[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}|[0-9]{10})(?=[\s]|$)`
|
|
1242
1428
|
},
|
|
1243
|
-
// Social Security Numbers
|
|
1244
|
-
{
|
|
1245
|
-
name: "ssn",
|
|
1246
|
-
pattern: String.raw`\b(?!000|666|9\d{2})\d{3}[-\s]?(?!00)\d{2}[-\s]?(?!0000)\d{4}\b`
|
|
1247
|
-
},
|
|
1248
1429
|
// Credit card numbers
|
|
1249
1430
|
{
|
|
1250
1431
|
name: "credit_cards",
|
|
@@ -1268,19 +1449,11 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1268
1449
|
name: "openai_keys",
|
|
1269
1450
|
pattern: String.raw`\bsk[-_][a-zA-Z0-9]{20,}\b`
|
|
1270
1451
|
},
|
|
1271
|
-
{
|
|
1272
|
-
name: "base64_secrets",
|
|
1273
|
-
pattern: String.raw`\b[A-Za-z0-9+/]{64,}={0,2}\b`
|
|
1274
|
-
},
|
|
1275
1452
|
// AWS Keys
|
|
1276
1453
|
{
|
|
1277
1454
|
name: "aws_access_keys",
|
|
1278
1455
|
pattern: String.raw`\b(?:AKIA|ABIA|ACCA|ASIA)[0-9A-Z]{16}\b`
|
|
1279
1456
|
},
|
|
1280
|
-
{
|
|
1281
|
-
name: "aws_secret_keys",
|
|
1282
|
-
pattern: String.raw`\b[A-Za-z0-9/+=]*[A-Z][A-Za-z0-9/+=]*[a-z][A-Za-z0-9/+=]*[/+=][A-Za-z0-9/+=]{30,}\b`
|
|
1283
|
-
},
|
|
1284
1457
|
// GitHub tokens
|
|
1285
1458
|
{
|
|
1286
1459
|
name: "github_tokens",
|
|
@@ -1311,11 +1484,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1311
1484
|
name: "ipv6_addresses",
|
|
1312
1485
|
pattern: String.raw`\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b`
|
|
1313
1486
|
},
|
|
1314
|
-
// Medical records
|
|
1315
|
-
{
|
|
1316
|
-
name: "medical_record_numbers",
|
|
1317
|
-
pattern: String.raw`\b(?:[Mm][Rr][Nn])[-\s]?\d{6,10}\b`
|
|
1318
|
-
},
|
|
1319
1487
|
// Bitcoin addresses
|
|
1320
1488
|
{
|
|
1321
1489
|
name: "bitcoin_addresses",
|
|
@@ -1326,11 +1494,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1326
1494
|
name: "ethereum_addresses",
|
|
1327
1495
|
pattern: String.raw`\b0x[a-fA-F0-9]{40}(?![a-fA-F0-9])\b`
|
|
1328
1496
|
},
|
|
1329
|
-
// UUIDs
|
|
1330
|
-
{
|
|
1331
|
-
name: "uuids",
|
|
1332
|
-
pattern: String.raw`\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(?![0-9a-fA-F-])\b`
|
|
1333
|
-
},
|
|
1334
1497
|
// Database connection strings
|
|
1335
1498
|
{
|
|
1336
1499
|
name: "database_connections",
|
|
@@ -1349,90 +1512,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1349
1512
|
name: "certificates",
|
|
1350
1513
|
pattern: "-----BEGIN CERTIFICATE-----"
|
|
1351
1514
|
},
|
|
1352
|
-
// Date of birth patterns
|
|
1353
|
-
{
|
|
1354
|
-
name: "date_of_birth_us",
|
|
1355
|
-
pattern: String.raw`\b(?:0[1-9]|1[0-2])[-/](?:0[1-9]|[12]\\d|3[01])[-/](?:19|20)\\d{2}\b`
|
|
1356
|
-
},
|
|
1357
|
-
{
|
|
1358
|
-
name: "date_of_birth_iso",
|
|
1359
|
-
pattern: String.raw`\b(?:19|20)\\d{2}[-/](?:0[1-9]|1[0-2])[-/](?:0[1-9]|[12]\\d|3[01])\b`
|
|
1360
|
-
},
|
|
1361
|
-
// US Identification Numbers
|
|
1362
|
-
{
|
|
1363
|
-
name: "us_passport_numbers",
|
|
1364
|
-
pattern: String.raw`\b[A-Z]?\\d{6,9}\b`
|
|
1365
|
-
},
|
|
1366
|
-
{
|
|
1367
|
-
name: "drivers_license",
|
|
1368
|
-
pattern: String.raw`\b[A-Z]{1,2}\\d{3,8}[-\s]?\\d{2,5}[-\s]?\\d{2,5}[-\s]?\\d{1,5}[-\s]?\\d?\b`
|
|
1369
|
-
},
|
|
1370
|
-
{
|
|
1371
|
-
name: "bank_account_numbers",
|
|
1372
|
-
pattern: String.raw`\b\\d{10,17}\b`
|
|
1373
|
-
},
|
|
1374
|
-
{
|
|
1375
|
-
name: "aba_routing_numbers",
|
|
1376
|
-
pattern: String.raw`\b((0[0-9])|(1[0-2])|(2[1-9])|(3[0-2])|(6[1-9])|(7[0-2])|80)([0-9]{7})\b`
|
|
1377
|
-
},
|
|
1378
|
-
{
|
|
1379
|
-
name: "health_insurance_numbers",
|
|
1380
|
-
pattern: String.raw`\b\\d{10}[A-Z]\b`
|
|
1381
|
-
},
|
|
1382
|
-
{
|
|
1383
|
-
name: "employee_ids",
|
|
1384
|
-
pattern: String.raw`\b(?:[Ee][Mm][Pp]|[Ee][Mm][Pp][Ll][Oo][Yy][Ee][Ee]|[Ee])[-\s]?\\d{5,8}\b`
|
|
1385
|
-
},
|
|
1386
|
-
{
|
|
1387
|
-
name: "tax_ein",
|
|
1388
|
-
pattern: String.raw`\b\\d{2}-\\d{7}\b`
|
|
1389
|
-
},
|
|
1390
|
-
{
|
|
1391
|
-
name: "medicare_beneficiary_id",
|
|
1392
|
-
pattern: String.raw`\b[1-9][A-Z][A-Z0-9]\\d-[A-Z][A-Z0-9]\\d-[A-Z][A-Z0-9]\\d{2}\b`
|
|
1393
|
-
},
|
|
1394
|
-
{
|
|
1395
|
-
name: "national_provider_id",
|
|
1396
|
-
pattern: String.raw`\b1\\d{9}\b`
|
|
1397
|
-
},
|
|
1398
|
-
{
|
|
1399
|
-
name: "dea_numbers",
|
|
1400
|
-
pattern: String.raw`\b[A-Z]{2}\\d{7}\b`
|
|
1401
|
-
},
|
|
1402
|
-
{
|
|
1403
|
-
name: "itin",
|
|
1404
|
-
pattern: String.raw`\b9\\d{2}(?:[ \\-]?)[7,8]\\d(?:[ \\-]?)\\d{4}\b`
|
|
1405
|
-
},
|
|
1406
|
-
// Vehicle and Location
|
|
1407
|
-
{
|
|
1408
|
-
name: "vin_numbers",
|
|
1409
|
-
pattern: String.raw`\b[A-HJ-NPR-Z0-9]{17}\b`
|
|
1410
|
-
},
|
|
1411
|
-
{
|
|
1412
|
-
name: "coordinates",
|
|
1413
|
-
pattern: String.raw`\b[-+]?(?:[0-8]?\\d(?:\\.\\d+)?|90(?:\\.0+)?),\\s*[-+]?(?:1[0-7]\\d(?:\\.\\d+)?|180(?:\\.0+)?|[0-9]?\\d(?:\\.\\d+)?)\b`
|
|
1414
|
-
},
|
|
1415
|
-
{
|
|
1416
|
-
name: "us_license_plates",
|
|
1417
|
-
pattern: String.raw`\b[A-Z]{1,3}[-\s]\\d{1,4}[A-Z]?\b|\b\\d{1,2}[A-Z]{1,3}\\d{1,4}\b`
|
|
1418
|
-
},
|
|
1419
|
-
{
|
|
1420
|
-
name: "us_zip_codes",
|
|
1421
|
-
pattern: String.raw`\b(\\d{5}-\\d{4}|\\d{5})\b`
|
|
1422
|
-
},
|
|
1423
|
-
{
|
|
1424
|
-
name: "us_street_addresses",
|
|
1425
|
-
pattern: String.raw`\b\\d{1,8}\b[\\s\\S]{10,100}?\b(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NC|ND|NE|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)\b\\s\\d{5}\b`
|
|
1426
|
-
},
|
|
1427
|
-
// International Banking
|
|
1428
|
-
{
|
|
1429
|
-
name: "iban",
|
|
1430
|
-
pattern: String.raw`\b[A-Z]{2}\d{2}[A-Z0-9]{4}\d{7}([A-Z0-9]?){0,16}\b`
|
|
1431
|
-
},
|
|
1432
|
-
{
|
|
1433
|
-
name: "swift_bic",
|
|
1434
|
-
pattern: String.raw`\b[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?\b`
|
|
1435
|
-
},
|
|
1436
1515
|
// Additional API Keys and Tokens
|
|
1437
1516
|
{
|
|
1438
1517
|
name: "google_oauth",
|
|
@@ -1495,73 +1574,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1495
1574
|
name: "putty_ssh_keys",
|
|
1496
1575
|
pattern: String.raw`PuTTY-User-Key-File-2: ssh-(?:rsa|dss)\s*Encryption: none(?:.|\s?)*?Private-MAC:`
|
|
1497
1576
|
},
|
|
1498
|
-
// International Phone Numbers
|
|
1499
|
-
{
|
|
1500
|
-
name: "france_phone_numbers",
|
|
1501
|
-
pattern: String.raw`\b([0O]?[1lI][1lI])?[3E][3E][0O]?[\\dOIlZEASB]{9}\b`
|
|
1502
|
-
},
|
|
1503
|
-
{
|
|
1504
|
-
name: "german_phone_numbers",
|
|
1505
|
-
pattern: String.raw`\b[\d\w]\d{2}[\d\w]{6}\d[\d\w]\b`
|
|
1506
|
-
},
|
|
1507
|
-
{
|
|
1508
|
-
name: "uk_phone_numbers",
|
|
1509
|
-
pattern: String.raw`\b([0O]?[1lI][1lI])?[4A][4A][\\dOIlZEASB]{10,11}\b`
|
|
1510
|
-
},
|
|
1511
|
-
// International IDs
|
|
1512
|
-
{
|
|
1513
|
-
name: "uk_drivers_license",
|
|
1514
|
-
pattern: String.raw`\b[A-Z]{5}\d{6}[A-Z]{2}\d{1}[A-Z]{2}\b`
|
|
1515
|
-
},
|
|
1516
|
-
{
|
|
1517
|
-
name: "uk_passport",
|
|
1518
|
-
pattern: String.raw`\b\\d{10}GB[RP]\\d{7}[UMF]{1}\\d{9}\b`
|
|
1519
|
-
},
|
|
1520
|
-
{
|
|
1521
|
-
name: "argentina_dni",
|
|
1522
|
-
pattern: String.raw`\b\\d{2}\\.\\d{3}\\.\\d{3}\b`
|
|
1523
|
-
},
|
|
1524
|
-
{
|
|
1525
|
-
name: "australia_tfn",
|
|
1526
|
-
pattern: String.raw`\b[Tt][Ff][Nn](:|:\\s|\\s|)(\\d{8,9})\b`
|
|
1527
|
-
},
|
|
1528
|
-
{
|
|
1529
|
-
name: "canada_passport",
|
|
1530
|
-
pattern: String.raw`\b[\\w]{2}[\\d]{6}\b`
|
|
1531
|
-
},
|
|
1532
|
-
{
|
|
1533
|
-
name: "croatia_vat",
|
|
1534
|
-
pattern: String.raw`\bHR\\d{11}\b`
|
|
1535
|
-
},
|
|
1536
|
-
{
|
|
1537
|
-
name: "czech_vat",
|
|
1538
|
-
pattern: String.raw`\bCZ\\d{8,10}\b`
|
|
1539
|
-
},
|
|
1540
|
-
{
|
|
1541
|
-
name: "denmark_personal_id",
|
|
1542
|
-
pattern: String.raw`\b(?:\\d{10}|\\d{6}[-\\s]\\d{4})\b`
|
|
1543
|
-
},
|
|
1544
|
-
{
|
|
1545
|
-
name: "france_national_id",
|
|
1546
|
-
pattern: String.raw`\b\\d{12}\b`
|
|
1547
|
-
},
|
|
1548
|
-
{
|
|
1549
|
-
name: "france_ssn",
|
|
1550
|
-
pattern: String.raw`\b(?:\\d{13}|\\d{13}\\s\\d{2})\b`
|
|
1551
|
-
},
|
|
1552
|
-
{
|
|
1553
|
-
name: "france_passport",
|
|
1554
|
-
pattern: String.raw`\b\\d{2}11\\d{5}\b`
|
|
1555
|
-
},
|
|
1556
|
-
{
|
|
1557
|
-
name: "california_drivers_license",
|
|
1558
|
-
pattern: String.raw`\b[A-Z]{1}\\d{7}\b`
|
|
1559
|
-
},
|
|
1560
|
-
// Medical and Healthcare
|
|
1561
|
-
{
|
|
1562
|
-
name: "hipaa_ndc",
|
|
1563
|
-
pattern: String.raw`\b\\d{4,5}-\\d{3,4}-\\d{1,2}\b`
|
|
1564
|
-
},
|
|
1565
1577
|
// Security and Network
|
|
1566
1578
|
{
|
|
1567
1579
|
name: "cve_numbers",
|
|
@@ -1595,44 +1607,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1595
1607
|
{
|
|
1596
1608
|
name: "discover_cards",
|
|
1597
1609
|
pattern: String.raw`\b65[4-9][0-9]{13}|64[4-9][0-9]{13}|6011[0-9]{12}\b`
|
|
1598
|
-
},
|
|
1599
|
-
{
|
|
1600
|
-
name: "enhanced_credit_cards",
|
|
1601
|
-
pattern: String.raw`\b((4\\d{3}|5[1-5]\\d{2}|2\\d{3}|3[47]\\d{1,2})[\\s\\-]?\\d{4,6}[\\s\\-]?\\d{4,6}?([\\s\\-]\\d{3,4})?(\\d{3})?)\b`
|
|
1602
|
-
},
|
|
1603
|
-
// Bank Routing Numbers (US specific)
|
|
1604
|
-
{
|
|
1605
|
-
name: "bbva_routing_ca",
|
|
1606
|
-
pattern: String.raw`\\b321170538\\b`
|
|
1607
|
-
},
|
|
1608
|
-
{
|
|
1609
|
-
name: "boa_routing_ca",
|
|
1610
|
-
pattern: String.raw`\\b(?:121|026)00(?:0|9)(?:358|593)\\b`
|
|
1611
|
-
},
|
|
1612
|
-
{
|
|
1613
|
-
name: "chase_routing_ca",
|
|
1614
|
-
pattern: String.raw`\\b322271627\\b`
|
|
1615
|
-
},
|
|
1616
|
-
{
|
|
1617
|
-
name: "citibank_routing_ca",
|
|
1618
|
-
pattern: String.raw`\\b32(?:11|22)71(?:18|72)4\\b`
|
|
1619
|
-
},
|
|
1620
|
-
{
|
|
1621
|
-
name: "usbank_routing_ca",
|
|
1622
|
-
pattern: String.raw`\\b12(?:1122676|2235821)\\b`
|
|
1623
|
-
},
|
|
1624
|
-
{
|
|
1625
|
-
name: "united_bank_routing_ca",
|
|
1626
|
-
pattern: String.raw`\\b122243350\\b`
|
|
1627
|
-
},
|
|
1628
|
-
{
|
|
1629
|
-
name: "wells_fargo_routing_ca",
|
|
1630
|
-
pattern: String.raw`\\b121042882\\b`
|
|
1631
|
-
},
|
|
1632
|
-
// Unrealistic alphanumeric identifiers
|
|
1633
|
-
{
|
|
1634
|
-
name: "generic_non_usual",
|
|
1635
|
-
pattern: String.raw`(?:^|\s)(?=[A-Za-z0-9_\)\*\=@]*[A-Za-z])(?=[A-Za-z0-9_\)\*\=@]*[0-9])([A-Za-z0-9_\)\*\=@]{5,})(?=\s|$)`
|
|
1636
1610
|
}
|
|
1637
1611
|
];
|
|
1638
1612
|
|
|
@@ -1854,7 +1828,7 @@ function maskAttributes(attributes, rules, outputOriginalValue = false) {
|
|
|
1854
1828
|
}
|
|
1855
1829
|
|
|
1856
1830
|
// src/internal/log/processors/log-processor.ts
|
|
1857
|
-
|
|
1831
|
+
init_semantic_conventions2();
|
|
1858
1832
|
var DEFAULT_LOG_MASKING_RULES = [
|
|
1859
1833
|
{
|
|
1860
1834
|
mode: "partial",
|
|
@@ -1873,7 +1847,7 @@ var BrizzSimpleLogRecordProcessor = class extends import_sdk_logs.SimpleLogRecor
|
|
|
1873
1847
|
if (maskingConfig) {
|
|
1874
1848
|
maskLog(logRecord, maskingConfig);
|
|
1875
1849
|
}
|
|
1876
|
-
const associationProperties =
|
|
1850
|
+
const associationProperties = import_api8.context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1877
1851
|
if (associationProperties) {
|
|
1878
1852
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1879
1853
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -1893,7 +1867,7 @@ var BrizzBatchLogRecordProcessor = class extends import_sdk_logs.BatchLogRecordP
|
|
|
1893
1867
|
if (maskingConfig) {
|
|
1894
1868
|
maskLog(logRecord, maskingConfig);
|
|
1895
1869
|
}
|
|
1896
|
-
const associationProperties =
|
|
1870
|
+
const associationProperties = import_api8.context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1897
1871
|
if (associationProperties) {
|
|
1898
1872
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1899
1873
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2293,12 +2267,12 @@ var BrizzSpanExporter = class {
|
|
|
2293
2267
|
};
|
|
2294
2268
|
|
|
2295
2269
|
// src/internal/trace/processors/span-processor.ts
|
|
2296
|
-
var
|
|
2270
|
+
var import_api9 = require("@opentelemetry/api");
|
|
2297
2271
|
var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
2298
2272
|
init_logger();
|
|
2299
|
-
|
|
2273
|
+
init_semantic_conventions2();
|
|
2300
2274
|
function applyContextAttributes(span) {
|
|
2301
|
-
const sessionProperties =
|
|
2275
|
+
const sessionProperties = import_api9.context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
2302
2276
|
if (sessionProperties) {
|
|
2303
2277
|
for (const [key, value] of Object.entries(sessionProperties)) {
|
|
2304
2278
|
span.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2308,12 +2282,6 @@ function applyContextAttributes(span) {
|
|
|
2308
2282
|
var DEFAULT_MASKING_RULES = [
|
|
2309
2283
|
{
|
|
2310
2284
|
mode: "partial",
|
|
2311
|
-
attributePattern: "gen_ai.prompt",
|
|
2312
|
-
patterns: DEFAULT_PII_PATTERNS
|
|
2313
|
-
},
|
|
2314
|
-
{
|
|
2315
|
-
mode: "partial",
|
|
2316
|
-
attributePattern: "gen_ai.completion",
|
|
2317
2285
|
patterns: DEFAULT_PII_PATTERNS
|
|
2318
2286
|
}
|
|
2319
2287
|
];
|
|
@@ -2323,24 +2291,16 @@ var BrizzSimpleSpanProcessor = class extends import_sdk_trace_base.SimpleSpanPro
|
|
|
2323
2291
|
super(spanExporter);
|
|
2324
2292
|
this.config = config;
|
|
2325
2293
|
}
|
|
2326
|
-
// Will work with the following code:
|
|
2327
|
-
// const span = tracer.startSpan('sensitive-operation',{attributes:{
|
|
2328
|
-
// 'user.password': 'secret123',
|
|
2329
|
-
// 'user.email': 'user@example.com',
|
|
2330
|
-
// }});
|
|
2331
|
-
//
|
|
2332
|
-
// Won't work because onStart is called before attributes are set:
|
|
2333
|
-
// span.setAttributes({
|
|
2334
|
-
// 'user.password': 'secret123',
|
|
2335
|
-
// 'user.email': 'user@example.com'
|
|
2336
|
-
// });
|
|
2337
2294
|
onStart(span, parentContext) {
|
|
2295
|
+
applyContextAttributes(span);
|
|
2296
|
+
super.onStart(span, parentContext);
|
|
2297
|
+
}
|
|
2298
|
+
onEnd(span) {
|
|
2338
2299
|
const maskingConfig = this.config.masking?.spanMasking;
|
|
2339
2300
|
if (maskingConfig) {
|
|
2340
|
-
|
|
2301
|
+
maskReadableSpan(span, maskingConfig);
|
|
2341
2302
|
}
|
|
2342
|
-
|
|
2343
|
-
super.onStart(span, parentContext);
|
|
2303
|
+
super.onEnd(span);
|
|
2344
2304
|
}
|
|
2345
2305
|
};
|
|
2346
2306
|
var BrizzBatchSpanProcessor = class extends import_sdk_trace_base.BatchSpanProcessor {
|
|
@@ -2350,39 +2310,39 @@ var BrizzBatchSpanProcessor = class extends import_sdk_trace_base.BatchSpanProce
|
|
|
2350
2310
|
this.config = config;
|
|
2351
2311
|
}
|
|
2352
2312
|
onStart(span, parentContext) {
|
|
2313
|
+
applyContextAttributes(span);
|
|
2314
|
+
super.onStart(span, parentContext);
|
|
2315
|
+
}
|
|
2316
|
+
onEnd(span) {
|
|
2353
2317
|
const maskingConfig = this.config.masking?.spanMasking;
|
|
2354
2318
|
if (maskingConfig) {
|
|
2355
|
-
|
|
2319
|
+
maskReadableSpan(span, maskingConfig);
|
|
2356
2320
|
}
|
|
2357
|
-
|
|
2358
|
-
super.onStart(span, parentContext);
|
|
2321
|
+
super.onEnd(span);
|
|
2359
2322
|
}
|
|
2360
2323
|
};
|
|
2361
|
-
function
|
|
2362
|
-
|
|
2363
|
-
|
|
2324
|
+
function maskReadableSpan(span, config) {
|
|
2325
|
+
const attrs = span.attributes;
|
|
2326
|
+
if (!attrs || Object.keys(attrs).length === 0) {
|
|
2327
|
+
return;
|
|
2364
2328
|
}
|
|
2365
|
-
let rules = config.rules
|
|
2329
|
+
let rules = config.rules ? [...config.rules] : [];
|
|
2366
2330
|
if (!config.disableDefaultRules) {
|
|
2367
|
-
rules = [...
|
|
2331
|
+
rules = [...rules, ...DEFAULT_MASKING_RULES];
|
|
2368
2332
|
}
|
|
2369
2333
|
try {
|
|
2370
|
-
const
|
|
2371
|
-
for (const [
|
|
2372
|
-
|
|
2373
|
-
}
|
|
2374
|
-
const
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
merged[key] = value;
|
|
2334
|
+
const input = {};
|
|
2335
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
2336
|
+
input[k] = v;
|
|
2337
|
+
}
|
|
2338
|
+
const masked = maskAttributes(input, rules);
|
|
2339
|
+
for (const [k, v] of Object.entries(masked ?? {})) {
|
|
2340
|
+
if (attrs[k] !== v) {
|
|
2341
|
+
attrs[k] = v;
|
|
2379
2342
|
}
|
|
2380
|
-
span.setAttributes(merged);
|
|
2381
2343
|
}
|
|
2382
|
-
return span;
|
|
2383
2344
|
} catch (error) {
|
|
2384
|
-
logger.error("Error masking span
|
|
2385
|
-
return span;
|
|
2345
|
+
logger.error("Error masking span", { err: error });
|
|
2386
2346
|
}
|
|
2387
2347
|
}
|
|
2388
2348
|
|
|
@@ -2498,10 +2458,10 @@ function getSpanProcessor() {
|
|
|
2498
2458
|
}
|
|
2499
2459
|
|
|
2500
2460
|
// src/internal/trace/session.ts
|
|
2501
|
-
var
|
|
2502
|
-
|
|
2461
|
+
var import_api10 = require("@opentelemetry/api");
|
|
2462
|
+
init_semantic_conventions2();
|
|
2503
2463
|
function setCurrentSpanCustomProperties(properties) {
|
|
2504
|
-
const current =
|
|
2464
|
+
const current = import_api10.trace.getActiveSpan();
|
|
2505
2465
|
if (!current || !current.isRecording()) {
|
|
2506
2466
|
return;
|
|
2507
2467
|
}
|
|
@@ -2513,11 +2473,11 @@ function setCurrentSpanCustomProperties(properties) {
|
|
|
2513
2473
|
}
|
|
2514
2474
|
}
|
|
2515
2475
|
function callWithProperties(properties, fn, thisArg, ...args) {
|
|
2516
|
-
const base =
|
|
2476
|
+
const base = import_api10.context.active();
|
|
2517
2477
|
const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
|
|
2518
2478
|
const merged = prev ? { ...prev, ...properties } : properties;
|
|
2519
2479
|
const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
|
|
2520
|
-
return
|
|
2480
|
+
return import_api10.context.with(next, fn, thisArg, ...args);
|
|
2521
2481
|
}
|
|
2522
2482
|
function withProperties(properties, fn, thisArg) {
|
|
2523
2483
|
return function wrapped(...args) {
|
|
@@ -2616,12 +2576,12 @@ var SessionTitle = class {
|
|
|
2616
2576
|
}
|
|
2617
2577
|
};
|
|
2618
2578
|
function getActiveSession() {
|
|
2619
|
-
return
|
|
2579
|
+
return import_api10.context.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
|
|
2620
2580
|
}
|
|
2621
2581
|
function startSession(sessionId, callback, extraProperties, options) {
|
|
2622
2582
|
const isTitle = options?.mode === "title";
|
|
2623
2583
|
const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
|
|
2624
|
-
const tracer =
|
|
2584
|
+
const tracer = import_api10.trace.getTracer("@brizz/sdk");
|
|
2625
2585
|
return tracer.startActiveSpan(spanName, (span) => {
|
|
2626
2586
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
2627
2587
|
if (extraProperties) {
|
|
@@ -2640,8 +2600,8 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
2640
2600
|
}
|
|
2641
2601
|
}
|
|
2642
2602
|
return callWithProperties(contextProperties, () => {
|
|
2643
|
-
const sessionCtx =
|
|
2644
|
-
return
|
|
2603
|
+
const sessionCtx = import_api10.context.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
|
|
2604
|
+
return import_api10.context.with(sessionCtx, () => {
|
|
2645
2605
|
try {
|
|
2646
2606
|
const result = callback(session);
|
|
2647
2607
|
if (result && typeof result.then === "function") {
|
|
@@ -2650,7 +2610,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
2650
2610
|
return value;
|
|
2651
2611
|
}).catch((error) => {
|
|
2652
2612
|
span.recordException(error);
|
|
2653
|
-
span.setStatus({ code:
|
|
2613
|
+
span.setStatus({ code: import_api10.SpanStatusCode.ERROR });
|
|
2654
2614
|
span.end();
|
|
2655
2615
|
throw error;
|
|
2656
2616
|
});
|
|
@@ -2659,7 +2619,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
2659
2619
|
return result;
|
|
2660
2620
|
} catch (error) {
|
|
2661
2621
|
span.recordException(error);
|
|
2662
|
-
span.setStatus({ code:
|
|
2622
|
+
span.setStatus({ code: import_api10.SpanStatusCode.ERROR });
|
|
2663
2623
|
span.end();
|
|
2664
2624
|
throw error;
|
|
2665
2625
|
}
|
|
@@ -2669,7 +2629,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
2669
2629
|
}
|
|
2670
2630
|
function startSessionTitle(callback, options) {
|
|
2671
2631
|
const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
|
|
2672
|
-
const tracer =
|
|
2632
|
+
const tracer = import_api10.trace.getTracer("@brizz/sdk");
|
|
2673
2633
|
return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
|
|
2674
2634
|
if (resolvedSessionId) {
|
|
2675
2635
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
|
|
@@ -2688,7 +2648,7 @@ function startSessionTitle(callback, options) {
|
|
|
2688
2648
|
return value;
|
|
2689
2649
|
}).catch((error) => {
|
|
2690
2650
|
span.recordException(error);
|
|
2691
|
-
span.setStatus({ code:
|
|
2651
|
+
span.setStatus({ code: import_api10.SpanStatusCode.ERROR });
|
|
2692
2652
|
span.end();
|
|
2693
2653
|
throw error;
|
|
2694
2654
|
});
|
|
@@ -2697,7 +2657,7 @@ function startSessionTitle(callback, options) {
|
|
|
2697
2657
|
return result;
|
|
2698
2658
|
} catch (error) {
|
|
2699
2659
|
span.recordException(error);
|
|
2700
|
-
span.setStatus({ code:
|
|
2660
|
+
span.setStatus({ code: import_api10.SpanStatusCode.ERROR });
|
|
2701
2661
|
span.end();
|
|
2702
2662
|
throw error;
|
|
2703
2663
|
}
|
|
@@ -2985,4 +2945,3 @@ var init_exports = {};
|
|
|
2985
2945
|
withProperties,
|
|
2986
2946
|
withSessionId
|
|
2987
2947
|
});
|
|
2988
|
-
//# sourceMappingURL=index.cjs.map
|