@brizz/sdk 0.1.22 → 0.1.25
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 +297 -335
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +273 -311
- package/dist/index.js.map +1 -1
- package/dist/preload.cjs +274 -322
- package/dist/preload.cjs.map +1 -1
- package/dist/preload.js +263 -311
- package/dist/preload.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -202,44 +202,8 @@ var init_semantic_conventions = __esm({
|
|
|
202
202
|
}
|
|
203
203
|
});
|
|
204
204
|
|
|
205
|
-
// src/internal/instrumentation/mcp/session.ts
|
|
206
|
-
function stampAndPropagateSession(span, sessionId, baseContext = import_api3.context.active()) {
|
|
207
|
-
if (!sessionId) {
|
|
208
|
-
return { context: baseContext, sessionId: null };
|
|
209
|
-
}
|
|
210
|
-
if (span.isRecording()) {
|
|
211
|
-
try {
|
|
212
|
-
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
213
|
-
} catch (error) {
|
|
214
|
-
logger.warn(
|
|
215
|
-
`Brizz MCP: failed to stamp session id on span: ${String(error)}`
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
try {
|
|
220
|
-
const prev = baseContext.getValue(PROPERTIES_CONTEXT_KEY);
|
|
221
|
-
const merged = prev ? { ...prev, [SESSION_ID]: sessionId } : { [SESSION_ID]: sessionId };
|
|
222
|
-
return {
|
|
223
|
-
context: baseContext.setValue(PROPERTIES_CONTEXT_KEY, merged),
|
|
224
|
-
sessionId
|
|
225
|
-
};
|
|
226
|
-
} catch (error) {
|
|
227
|
-
logger.warn(`Brizz MCP: failed to attach session context: ${String(error)}`);
|
|
228
|
-
return { context: baseContext, sessionId };
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
var import_api3;
|
|
232
|
-
var init_session = __esm({
|
|
233
|
-
"src/internal/instrumentation/mcp/session.ts"() {
|
|
234
|
-
"use strict";
|
|
235
|
-
import_api3 = require("@opentelemetry/api");
|
|
236
|
-
init_logger();
|
|
237
|
-
init_semantic_conventions();
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
|
|
241
205
|
// 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;
|
|
206
|
+
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;
|
|
243
207
|
var init_semantic_conventions2 = __esm({
|
|
244
208
|
"src/internal/instrumentation/mcp/semantic-conventions.ts"() {
|
|
245
209
|
"use strict";
|
|
@@ -248,6 +212,11 @@ var init_semantic_conventions2 = __esm({
|
|
|
248
212
|
MCP_TOOL_RESULT = "mcp.tool.result";
|
|
249
213
|
MCP_COMPONENT_TYPE = "mcp.component.type";
|
|
250
214
|
MCP_COMPONENT_TOOL = "tool";
|
|
215
|
+
MCP_COMPONENT_TOOL_SCHEMA = "tool_schema";
|
|
216
|
+
MCP_TOOL_SCHEMA_PARAMETERS = "mcp.tool.schema.parameters";
|
|
217
|
+
MCP_TOOL_SCHEMA_OUTPUT = "mcp.tool.schema.output";
|
|
218
|
+
MCP_TOOL_DESCRIPTION = "mcp.tool.description";
|
|
219
|
+
SPAN_NAME_TOOL_REGISTER = "mcp.tool.register";
|
|
251
220
|
MCP_METHOD_NAME = "mcp.method.name";
|
|
252
221
|
MCP_REQUEST_ID = "mcp.request.id";
|
|
253
222
|
MCP_SESSION_ID = "mcp.session.id";
|
|
@@ -268,12 +237,133 @@ var init_semantic_conventions2 = __esm({
|
|
|
268
237
|
MAX_ATTRIBUTE_LENGTH = 32 * 1024;
|
|
269
238
|
TRUNCATION_SUFFIX = "\u2026(truncated)";
|
|
270
239
|
METHOD_TOOLS_CALL = "tools/call";
|
|
240
|
+
METHOD_TOOLS_LIST = "tools/list";
|
|
271
241
|
METHOD_RESOURCES_READ = "resources/read";
|
|
272
242
|
METHOD_PROMPTS_GET = "prompts/get";
|
|
273
243
|
METHOD_INITIALIZE = "initialize";
|
|
274
244
|
}
|
|
275
245
|
});
|
|
276
246
|
|
|
247
|
+
// src/internal/instrumentation/mcp/schemas.ts
|
|
248
|
+
function truncateSchemaAttr(value) {
|
|
249
|
+
if (value.length <= _MAX_SCHEMA_ATTR_BYTES) {
|
|
250
|
+
return value;
|
|
251
|
+
}
|
|
252
|
+
return `{"_truncated":true,"original_length":${value.length}}`;
|
|
253
|
+
}
|
|
254
|
+
function safeStringify(value) {
|
|
255
|
+
if (value === null || value === void 0) {
|
|
256
|
+
return "";
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
return JSON.stringify(value);
|
|
260
|
+
} catch {
|
|
261
|
+
return "";
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function emitSchemaSpansFromListResponse(result, transportSessionId, tracer) {
|
|
265
|
+
if (!transportSessionId) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const tools = extractTools(result);
|
|
269
|
+
if (tools === void 0) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
for (const tool of tools) {
|
|
273
|
+
const name = typeof tool.name === "string" ? tool.name : void 0;
|
|
274
|
+
if (!name) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const span = tracer.startSpan(`${SPAN_NAME_TOOL_REGISTER} ${name}`, {
|
|
278
|
+
kind: import_api3.SpanKind.INTERNAL
|
|
279
|
+
});
|
|
280
|
+
try {
|
|
281
|
+
stampSchemaAttributes(span, name, transportSessionId, tool);
|
|
282
|
+
span.setStatus({ code: import_api3.SpanStatusCode.OK });
|
|
283
|
+
} finally {
|
|
284
|
+
span.end();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function stampSchemaAttributes(span, toolName, transportSessionId, tool) {
|
|
289
|
+
if (!span.isRecording()) {
|
|
290
|
+
logger.warn(
|
|
291
|
+
`Brizz MCP: schema span is not recording; dropping attributes for ${toolName}`
|
|
292
|
+
);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const description = typeof tool.description === "string" ? tool.description : "";
|
|
296
|
+
const parameters = truncateSchemaAttr(safeStringify(tool.inputSchema));
|
|
297
|
+
const outputSchema = tool.outputSchema !== void 0 && tool.outputSchema !== null ? truncateSchemaAttr(safeStringify(tool.outputSchema)) : "";
|
|
298
|
+
span.setAttribute(RPC_SYSTEM, RPC_SYSTEM_MCP);
|
|
299
|
+
span.setAttribute(MCP_COMPONENT_TYPE, MCP_COMPONENT_TOOL_SCHEMA);
|
|
300
|
+
span.setAttribute(MCP_SESSION_ID, transportSessionId);
|
|
301
|
+
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, transportSessionId);
|
|
302
|
+
span.setAttribute(MCP_TOOL_NAME, toolName);
|
|
303
|
+
span.setAttribute(MCP_TOOL_SCHEMA_PARAMETERS, parameters);
|
|
304
|
+
span.setAttribute(MCP_TOOL_SCHEMA_OUTPUT, outputSchema);
|
|
305
|
+
span.setAttribute(MCP_TOOL_DESCRIPTION, description);
|
|
306
|
+
}
|
|
307
|
+
function extractTools(result) {
|
|
308
|
+
if (!result || typeof result !== "object") {
|
|
309
|
+
return void 0;
|
|
310
|
+
}
|
|
311
|
+
const tools = result.tools;
|
|
312
|
+
if (!Array.isArray(tools)) {
|
|
313
|
+
return void 0;
|
|
314
|
+
}
|
|
315
|
+
return tools.filter(
|
|
316
|
+
(t) => t !== null && typeof t === "object"
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
var import_api3, _MAX_SCHEMA_ATTR_BYTES;
|
|
320
|
+
var init_schemas = __esm({
|
|
321
|
+
"src/internal/instrumentation/mcp/schemas.ts"() {
|
|
322
|
+
"use strict";
|
|
323
|
+
import_api3 = require("@opentelemetry/api");
|
|
324
|
+
init_logger();
|
|
325
|
+
init_semantic_conventions();
|
|
326
|
+
init_semantic_conventions2();
|
|
327
|
+
_MAX_SCHEMA_ATTR_BYTES = 4e3;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
// src/internal/instrumentation/mcp/session.ts
|
|
332
|
+
function stampAndPropagateSession(span, sessionId, baseContext = import_api4.context.active()) {
|
|
333
|
+
if (!sessionId) {
|
|
334
|
+
return { context: baseContext, sessionId: null };
|
|
335
|
+
}
|
|
336
|
+
if (span.isRecording()) {
|
|
337
|
+
try {
|
|
338
|
+
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
339
|
+
} catch (error) {
|
|
340
|
+
logger.warn(
|
|
341
|
+
`Brizz MCP: failed to stamp session id on span: ${String(error)}`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
try {
|
|
346
|
+
const prev = baseContext.getValue(PROPERTIES_CONTEXT_KEY);
|
|
347
|
+
const merged = prev ? { ...prev, [SESSION_ID]: sessionId } : { [SESSION_ID]: sessionId };
|
|
348
|
+
return {
|
|
349
|
+
context: baseContext.setValue(PROPERTIES_CONTEXT_KEY, merged),
|
|
350
|
+
sessionId
|
|
351
|
+
};
|
|
352
|
+
} catch (error) {
|
|
353
|
+
logger.warn(`Brizz MCP: failed to attach session context: ${String(error)}`);
|
|
354
|
+
return { context: baseContext, sessionId };
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
var import_api4;
|
|
358
|
+
var init_session = __esm({
|
|
359
|
+
"src/internal/instrumentation/mcp/session.ts"() {
|
|
360
|
+
"use strict";
|
|
361
|
+
import_api4 = require("@opentelemetry/api");
|
|
362
|
+
init_logger();
|
|
363
|
+
init_semantic_conventions();
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
|
|
277
367
|
// src/internal/instrumentation/mcp/patches/attributes.ts
|
|
278
368
|
function deriveSpanName(method, params) {
|
|
279
369
|
try {
|
|
@@ -377,7 +467,7 @@ function applyResultAttributes(span, method, result) {
|
|
|
377
467
|
if (obj && obj["isError"] === true) {
|
|
378
468
|
span.setAttribute(ERROR_TYPE, ERROR_TYPE_TOOL);
|
|
379
469
|
const message = extractToolErrorMessage(obj);
|
|
380
|
-
span.setStatus({ code:
|
|
470
|
+
span.setStatus({ code: import_api5.SpanStatusCode.ERROR, message });
|
|
381
471
|
}
|
|
382
472
|
}
|
|
383
473
|
function applyErrorAttributes(span, err) {
|
|
@@ -401,7 +491,7 @@ function applyErrorAttributes(span, err) {
|
|
|
401
491
|
} catch {
|
|
402
492
|
}
|
|
403
493
|
span.setStatus({
|
|
404
|
-
code:
|
|
494
|
+
code: import_api5.SpanStatusCode.ERROR,
|
|
405
495
|
message: typeof error?.message === "string" ? error.message : void 0
|
|
406
496
|
});
|
|
407
497
|
}
|
|
@@ -463,11 +553,11 @@ function normalizeTransport(ctorName) {
|
|
|
463
553
|
}
|
|
464
554
|
return null;
|
|
465
555
|
}
|
|
466
|
-
var
|
|
556
|
+
var import_api5;
|
|
467
557
|
var init_attributes = __esm({
|
|
468
558
|
"src/internal/instrumentation/mcp/patches/attributes.ts"() {
|
|
469
559
|
"use strict";
|
|
470
|
-
|
|
560
|
+
import_api5 = require("@opentelemetry/api");
|
|
471
561
|
init_semantic_conventions2();
|
|
472
562
|
}
|
|
473
563
|
});
|
|
@@ -515,8 +605,8 @@ function wrapRequest(original, tracer) {
|
|
|
515
605
|
return original.apply(this, args);
|
|
516
606
|
}
|
|
517
607
|
return executeAroundSpan(span, request.method, () => {
|
|
518
|
-
const ctx =
|
|
519
|
-
return
|
|
608
|
+
const ctx = import_api6.trace.setSpan(import_api6.context.active(), span);
|
|
609
|
+
return import_api6.context.with(ctx, () => original.apply(this, args));
|
|
520
610
|
});
|
|
521
611
|
};
|
|
522
612
|
}
|
|
@@ -540,7 +630,20 @@ function wrapOnRequest(original, tracer) {
|
|
|
540
630
|
return original.apply(this, args);
|
|
541
631
|
}
|
|
542
632
|
const { span, spanCtx } = started;
|
|
543
|
-
const
|
|
633
|
+
const transportSessionId = this.sessionId ?? this._transport?.sessionId;
|
|
634
|
+
const postResult = method === METHOD_TOOLS_LIST ? (result) => {
|
|
635
|
+
try {
|
|
636
|
+
emitSchemaSpansFromListResponse(result, transportSessionId, tracer);
|
|
637
|
+
} catch (error) {
|
|
638
|
+
logger.warn(
|
|
639
|
+
`Brizz MCP: failed to emit tools/list schema spans: ${String(error)}`
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
} : void 0;
|
|
643
|
+
const wrappedHandler = (req, extra) => import_api6.context.with(
|
|
644
|
+
spanCtx,
|
|
645
|
+
() => executeHandler(span, method, handler, req, extra, postResult)
|
|
646
|
+
);
|
|
544
647
|
const hadEntry = handlers.has(method);
|
|
545
648
|
const prev = handlers.get(method);
|
|
546
649
|
handlers.set(method, wrappedHandler);
|
|
@@ -563,7 +666,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
563
666
|
}
|
|
564
667
|
};
|
|
565
668
|
}
|
|
566
|
-
function executeAroundSpan(span, method, run) {
|
|
669
|
+
function executeAroundSpan(span, method, run, postResult) {
|
|
567
670
|
let result;
|
|
568
671
|
try {
|
|
569
672
|
result = run();
|
|
@@ -574,12 +677,18 @@ function executeAroundSpan(span, method, run) {
|
|
|
574
677
|
}
|
|
575
678
|
if (!isThenable(result)) {
|
|
576
679
|
safeApplyResultAttributes(span, method, result);
|
|
680
|
+
if (postResult) {
|
|
681
|
+
postResult(result);
|
|
682
|
+
}
|
|
577
683
|
safeEnd(span);
|
|
578
684
|
return result;
|
|
579
685
|
}
|
|
580
686
|
return result.then(
|
|
581
687
|
(value) => {
|
|
582
688
|
safeApplyResultAttributes(span, method, value);
|
|
689
|
+
if (postResult) {
|
|
690
|
+
postResult(value);
|
|
691
|
+
}
|
|
583
692
|
safeEnd(span);
|
|
584
693
|
return value;
|
|
585
694
|
},
|
|
@@ -590,13 +699,13 @@ function executeAroundSpan(span, method, run) {
|
|
|
590
699
|
}
|
|
591
700
|
);
|
|
592
701
|
}
|
|
593
|
-
function executeHandler(span, method, handler, req, extra) {
|
|
594
|
-
return executeAroundSpan(span, method, () => handler(req, extra));
|
|
702
|
+
function executeHandler(span, method, handler, req, extra, postResult) {
|
|
703
|
+
return executeAroundSpan(span, method, () => handler(req, extra), postResult);
|
|
595
704
|
}
|
|
596
705
|
function safeStartClientSpan(tracer, request, protocol) {
|
|
597
706
|
try {
|
|
598
707
|
const spanName = deriveSpanName(request.method, request.params);
|
|
599
|
-
const span = tracer.startSpan(spanName, { kind:
|
|
708
|
+
const span = tracer.startSpan(spanName, { kind: import_api6.SpanKind.CLIENT });
|
|
600
709
|
applyClientRequestAttributes(
|
|
601
710
|
span,
|
|
602
711
|
request,
|
|
@@ -614,13 +723,13 @@ function safeStartServerSpan(tracer, request, protocol) {
|
|
|
614
723
|
const spanName = deriveSpanName(request.method, request.params);
|
|
615
724
|
const span = tracer.startSpan(
|
|
616
725
|
spanName,
|
|
617
|
-
{ kind:
|
|
726
|
+
{ kind: import_api6.SpanKind.SERVER },
|
|
618
727
|
parentCtx
|
|
619
728
|
);
|
|
620
729
|
applyServerRequestAttributes(span, request, protocol);
|
|
621
730
|
const sessionId = protocol.sessionId ?? protocol._transport?.sessionId;
|
|
622
731
|
const { context: sessCtx } = stampAndPropagateSession(span, sessionId, parentCtx);
|
|
623
|
-
return { span, spanCtx:
|
|
732
|
+
return { span, spanCtx: import_api6.trace.setSpan(sessCtx, span) };
|
|
624
733
|
} catch (error) {
|
|
625
734
|
logger.debug(`Brizz MCP: failed to open SERVER span: ${String(error)}`);
|
|
626
735
|
return null;
|
|
@@ -630,14 +739,14 @@ function extractParentContext(request) {
|
|
|
630
739
|
try {
|
|
631
740
|
const meta = request.params?._meta;
|
|
632
741
|
if (meta && typeof meta === "object") {
|
|
633
|
-
return
|
|
742
|
+
return import_api6.propagation.extract(import_api6.context.active(), meta);
|
|
634
743
|
}
|
|
635
744
|
} catch (error) {
|
|
636
745
|
logger.debug(
|
|
637
746
|
`Brizz MCP: failed to extract parent context from _meta: ${String(error)}`
|
|
638
747
|
);
|
|
639
748
|
}
|
|
640
|
-
return
|
|
749
|
+
return import_api6.context.active();
|
|
641
750
|
}
|
|
642
751
|
function isThenable(value) {
|
|
643
752
|
return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
@@ -667,12 +776,14 @@ function safeEnd(span) {
|
|
|
667
776
|
logger.debug(`Brizz MCP: failed to end span: ${String(error)}`);
|
|
668
777
|
}
|
|
669
778
|
}
|
|
670
|
-
var
|
|
779
|
+
var import_api6, PATCHED_FLAG;
|
|
671
780
|
var init_protocol = __esm({
|
|
672
781
|
"src/internal/instrumentation/mcp/patches/protocol.ts"() {
|
|
673
782
|
"use strict";
|
|
674
|
-
|
|
783
|
+
import_api6 = require("@opentelemetry/api");
|
|
675
784
|
init_logger();
|
|
785
|
+
init_schemas();
|
|
786
|
+
init_semantic_conventions2();
|
|
676
787
|
init_session();
|
|
677
788
|
init_attributes();
|
|
678
789
|
PATCHED_FLAG = /* @__PURE__ */ Symbol("brizz.mcp.protocol-patched");
|
|
@@ -681,7 +792,7 @@ var init_protocol = __esm({
|
|
|
681
792
|
|
|
682
793
|
// src/internal/version.ts
|
|
683
794
|
function getSDKVersion() {
|
|
684
|
-
return "0.1.
|
|
795
|
+
return "0.1.25";
|
|
685
796
|
}
|
|
686
797
|
var init_version = __esm({
|
|
687
798
|
"src/internal/version.ts"() {
|
|
@@ -704,12 +815,12 @@ var init_version2 = __esm({
|
|
|
704
815
|
function isMCPInstrumentation(value) {
|
|
705
816
|
return !!value && typeof value === "object" && typeof value.instrumentationName === "string";
|
|
706
817
|
}
|
|
707
|
-
var import_openinference_instrumentation_mcp,
|
|
818
|
+
var import_openinference_instrumentation_mcp, import_api7, import_instrumentation, PROTOCOL_MODULE_NAME, PROTOCOL_SUPPORTED_VERSIONS, MCPInstrumentation;
|
|
708
819
|
var init_instrumentation = __esm({
|
|
709
820
|
"src/internal/instrumentation/mcp/instrumentation.ts"() {
|
|
710
821
|
"use strict";
|
|
711
822
|
import_openinference_instrumentation_mcp = require("@arizeai/openinference-instrumentation-mcp");
|
|
712
|
-
|
|
823
|
+
import_api7 = require("@opentelemetry/api");
|
|
713
824
|
import_instrumentation = require("@opentelemetry/instrumentation");
|
|
714
825
|
init_logger();
|
|
715
826
|
init_protocol();
|
|
@@ -730,7 +841,7 @@ var init_instrumentation = __esm({
|
|
|
730
841
|
brizzTracer;
|
|
731
842
|
constructor(_config) {
|
|
732
843
|
super({ instrumentationConfig: _config?.instrumentationConfig });
|
|
733
|
-
this.brizzTracer =
|
|
844
|
+
this.brizzTracer = import_api7.trace.getTracer(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION);
|
|
734
845
|
}
|
|
735
846
|
/**
|
|
736
847
|
* Extend `super.init()` with our protocol-layer module definition.
|
|
@@ -998,6 +1109,38 @@ autoInitializeInstrumentations();
|
|
|
998
1109
|
var import_resources3 = require("@opentelemetry/resources");
|
|
999
1110
|
var import_sdk_node = require("@opentelemetry/sdk-node");
|
|
1000
1111
|
|
|
1112
|
+
// src/internal/dsn.ts
|
|
1113
|
+
var PLACEHOLDER_SERVICE = "<service-name>";
|
|
1114
|
+
var SERVICE_NAME_HEADER = "X-Brizz-Service-Name";
|
|
1115
|
+
function parseDSN(dsn) {
|
|
1116
|
+
let parsed;
|
|
1117
|
+
try {
|
|
1118
|
+
parsed = new globalThis.URL(dsn);
|
|
1119
|
+
} catch {
|
|
1120
|
+
return null;
|
|
1121
|
+
}
|
|
1122
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:" || !parsed.username || !parsed.host) {
|
|
1123
|
+
return null;
|
|
1124
|
+
}
|
|
1125
|
+
const scheme = parsed.protocol === "https:" ? "https" : "http";
|
|
1126
|
+
let service;
|
|
1127
|
+
try {
|
|
1128
|
+
service = decodeURIComponent(parsed.pathname.replace(/^\//, ""));
|
|
1129
|
+
} catch {
|
|
1130
|
+
return null;
|
|
1131
|
+
}
|
|
1132
|
+
if (service === "" || service === PLACEHOLDER_SERVICE) {
|
|
1133
|
+
return null;
|
|
1134
|
+
}
|
|
1135
|
+
return {
|
|
1136
|
+
scheme,
|
|
1137
|
+
host: parsed.host,
|
|
1138
|
+
bearer: decodeURIComponent(parsed.username),
|
|
1139
|
+
service,
|
|
1140
|
+
baseUrl: `${scheme}://${parsed.host}`
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1001
1144
|
// src/internal/config.ts
|
|
1002
1145
|
init_logger();
|
|
1003
1146
|
function resolveConfig(options) {
|
|
@@ -1025,6 +1168,7 @@ function resolveConfig(options) {
|
|
|
1025
1168
|
appName: options.appName,
|
|
1026
1169
|
baseUrl: options.baseUrl,
|
|
1027
1170
|
hasApiKey: !!options.apiKey,
|
|
1171
|
+
dsnProvided: !!(process.env["BRIZZ_DSN"] || options.dsn),
|
|
1028
1172
|
disableBatch: options.disableBatch,
|
|
1029
1173
|
logLevel: resolvedLogLevel,
|
|
1030
1174
|
headersCount: Object.keys(options.headers || {}).length,
|
|
@@ -1052,7 +1196,42 @@ function resolveConfig(options) {
|
|
|
1052
1196
|
logLevel: resolvedLogLevel,
|
|
1053
1197
|
masking: resolvedMasking
|
|
1054
1198
|
};
|
|
1055
|
-
|
|
1199
|
+
const dsnInput = process.env["BRIZZ_DSN"] || options.dsn;
|
|
1200
|
+
let parsedDSN = null;
|
|
1201
|
+
if (dsnInput) {
|
|
1202
|
+
const kwargConflicts = [];
|
|
1203
|
+
if (options.apiKey !== void 0) {
|
|
1204
|
+
kwargConflicts.push("apiKey");
|
|
1205
|
+
}
|
|
1206
|
+
if (options.baseUrl !== void 0) {
|
|
1207
|
+
kwargConflicts.push("baseUrl");
|
|
1208
|
+
}
|
|
1209
|
+
if (options.appName !== void 0) {
|
|
1210
|
+
kwargConflicts.push("appName");
|
|
1211
|
+
}
|
|
1212
|
+
if (kwargConflicts.length > 0) {
|
|
1213
|
+
throw new Error(
|
|
1214
|
+
`dsn cannot be combined with kwargs ${kwargConflicts.join(", ")}. The DSN bundles bearer, gateway URL, and service name \u2014 choose one configuration style.`
|
|
1215
|
+
);
|
|
1216
|
+
}
|
|
1217
|
+
const envConflicts = ["BRIZZ_API_KEY", "BRIZZ_BASE_URL", "BRIZZ_APP_NAME"].filter(
|
|
1218
|
+
(name) => process.env[name] !== void 0
|
|
1219
|
+
);
|
|
1220
|
+
if (envConflicts.length > 0) {
|
|
1221
|
+
logger.warn(
|
|
1222
|
+
`Ignoring ${envConflicts.join(", ")} \u2014 dsn / BRIZZ_DSN takes precedence.`
|
|
1223
|
+
);
|
|
1224
|
+
}
|
|
1225
|
+
resolvedConfig.apiKey = void 0;
|
|
1226
|
+
resolvedConfig.baseUrl = "https://telemetry.brizz.dev";
|
|
1227
|
+
resolvedConfig.appName = "unknown-app";
|
|
1228
|
+
parsedDSN = parseDSN(dsnInput);
|
|
1229
|
+
if (parsedDSN) {
|
|
1230
|
+
resolvedConfig.appName = parsedDSN.service;
|
|
1231
|
+
resolvedConfig.baseUrl = parsedDSN.baseUrl;
|
|
1232
|
+
resolvedConfig.apiKey = parsedDSN.bearer;
|
|
1233
|
+
}
|
|
1234
|
+
} else if (resolvedConfig.apiKey) {
|
|
1056
1235
|
resolvedConfig.headers["Authorization"] = `Bearer ${resolvedConfig.apiKey}`;
|
|
1057
1236
|
}
|
|
1058
1237
|
if (process.env["BRIZZ_HEADERS"]) {
|
|
@@ -1067,14 +1246,28 @@ function resolveConfig(options) {
|
|
|
1067
1246
|
throw new Error("Invalid JSON in BRIZZ_HEADERS environment variable", { cause: error });
|
|
1068
1247
|
}
|
|
1069
1248
|
}
|
|
1249
|
+
if (dsnInput) {
|
|
1250
|
+
const authHeaderKeys = /* @__PURE__ */ new Set(["authorization", SERVICE_NAME_HEADER.toLowerCase()]);
|
|
1251
|
+
resolvedConfig.headers = Object.fromEntries(
|
|
1252
|
+
Object.entries(resolvedConfig.headers).filter(
|
|
1253
|
+
([key]) => !authHeaderKeys.has(key.toLowerCase())
|
|
1254
|
+
)
|
|
1255
|
+
);
|
|
1256
|
+
if (parsedDSN) {
|
|
1257
|
+
resolvedConfig.headers["Authorization"] = `Bearer ${parsedDSN.bearer}`;
|
|
1258
|
+
resolvedConfig.headers[SERVICE_NAME_HEADER] = parsedDSN.service;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1070
1261
|
logger.debug("Configuration resolved with environment variables", {
|
|
1071
1262
|
appName: resolvedConfig.appName,
|
|
1072
1263
|
baseUrl: resolvedConfig.baseUrl,
|
|
1073
1264
|
hasApiKey: !!resolvedConfig.apiKey,
|
|
1265
|
+
dsnProvided: !!dsnInput,
|
|
1074
1266
|
disableBatch: resolvedConfig.disableBatch,
|
|
1075
1267
|
envOverrides: {
|
|
1076
1268
|
hasEnvApiKey: !!process.env["BRIZZ_API_KEY"],
|
|
1077
1269
|
hasEnvBaseUrl: !!process.env["BRIZZ_BASE_URL"],
|
|
1270
|
+
hasEnvDsn: !!process.env["BRIZZ_DSN"],
|
|
1078
1271
|
hasEnvBatch: !!process.env["BRIZZ_DISABLE_BATCH"],
|
|
1079
1272
|
hasEnvHeaders: !!process.env["BRIZZ_HEADERS"]
|
|
1080
1273
|
}
|
|
@@ -1224,27 +1417,17 @@ init_logger();
|
|
|
1224
1417
|
init_version();
|
|
1225
1418
|
|
|
1226
1419
|
// src/internal/log/processors/log-processor.ts
|
|
1227
|
-
var
|
|
1420
|
+
var import_api8 = require("@opentelemetry/api");
|
|
1228
1421
|
var import_sdk_logs = require("@opentelemetry/sdk-logs");
|
|
1229
1422
|
init_logger();
|
|
1230
1423
|
|
|
1231
1424
|
// src/internal/masking/patterns.ts
|
|
1232
1425
|
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
1426
|
// Phone numbers (US format)
|
|
1239
1427
|
{
|
|
1240
1428
|
name: "us_phone_numbers",
|
|
1241
1429
|
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
1430
|
},
|
|
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
1431
|
// Credit card numbers
|
|
1249
1432
|
{
|
|
1250
1433
|
name: "credit_cards",
|
|
@@ -1268,19 +1451,11 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1268
1451
|
name: "openai_keys",
|
|
1269
1452
|
pattern: String.raw`\bsk[-_][a-zA-Z0-9]{20,}\b`
|
|
1270
1453
|
},
|
|
1271
|
-
{
|
|
1272
|
-
name: "base64_secrets",
|
|
1273
|
-
pattern: String.raw`\b[A-Za-z0-9+/]{64,}={0,2}\b`
|
|
1274
|
-
},
|
|
1275
1454
|
// AWS Keys
|
|
1276
1455
|
{
|
|
1277
1456
|
name: "aws_access_keys",
|
|
1278
1457
|
pattern: String.raw`\b(?:AKIA|ABIA|ACCA|ASIA)[0-9A-Z]{16}\b`
|
|
1279
1458
|
},
|
|
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
1459
|
// GitHub tokens
|
|
1285
1460
|
{
|
|
1286
1461
|
name: "github_tokens",
|
|
@@ -1311,11 +1486,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1311
1486
|
name: "ipv6_addresses",
|
|
1312
1487
|
pattern: String.raw`\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b`
|
|
1313
1488
|
},
|
|
1314
|
-
// Medical records
|
|
1315
|
-
{
|
|
1316
|
-
name: "medical_record_numbers",
|
|
1317
|
-
pattern: String.raw`\b(?:[Mm][Rr][Nn])[-\s]?\d{6,10}\b`
|
|
1318
|
-
},
|
|
1319
1489
|
// Bitcoin addresses
|
|
1320
1490
|
{
|
|
1321
1491
|
name: "bitcoin_addresses",
|
|
@@ -1326,11 +1496,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1326
1496
|
name: "ethereum_addresses",
|
|
1327
1497
|
pattern: String.raw`\b0x[a-fA-F0-9]{40}(?![a-fA-F0-9])\b`
|
|
1328
1498
|
},
|
|
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
1499
|
// Database connection strings
|
|
1335
1500
|
{
|
|
1336
1501
|
name: "database_connections",
|
|
@@ -1349,90 +1514,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1349
1514
|
name: "certificates",
|
|
1350
1515
|
pattern: "-----BEGIN CERTIFICATE-----"
|
|
1351
1516
|
},
|
|
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
1517
|
// Additional API Keys and Tokens
|
|
1437
1518
|
{
|
|
1438
1519
|
name: "google_oauth",
|
|
@@ -1495,73 +1576,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1495
1576
|
name: "putty_ssh_keys",
|
|
1496
1577
|
pattern: String.raw`PuTTY-User-Key-File-2: ssh-(?:rsa|dss)\s*Encryption: none(?:.|\s?)*?Private-MAC:`
|
|
1497
1578
|
},
|
|
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
1579
|
// Security and Network
|
|
1566
1580
|
{
|
|
1567
1581
|
name: "cve_numbers",
|
|
@@ -1595,44 +1609,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1595
1609
|
{
|
|
1596
1610
|
name: "discover_cards",
|
|
1597
1611
|
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
1612
|
}
|
|
1637
1613
|
];
|
|
1638
1614
|
|
|
@@ -1873,7 +1849,7 @@ var BrizzSimpleLogRecordProcessor = class extends import_sdk_logs.SimpleLogRecor
|
|
|
1873
1849
|
if (maskingConfig) {
|
|
1874
1850
|
maskLog(logRecord, maskingConfig);
|
|
1875
1851
|
}
|
|
1876
|
-
const associationProperties =
|
|
1852
|
+
const associationProperties = import_api8.context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1877
1853
|
if (associationProperties) {
|
|
1878
1854
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1879
1855
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -1893,7 +1869,7 @@ var BrizzBatchLogRecordProcessor = class extends import_sdk_logs.BatchLogRecordP
|
|
|
1893
1869
|
if (maskingConfig) {
|
|
1894
1870
|
maskLog(logRecord, maskingConfig);
|
|
1895
1871
|
}
|
|
1896
|
-
const associationProperties =
|
|
1872
|
+
const associationProperties = import_api8.context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1897
1873
|
if (associationProperties) {
|
|
1898
1874
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1899
1875
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2293,12 +2269,12 @@ var BrizzSpanExporter = class {
|
|
|
2293
2269
|
};
|
|
2294
2270
|
|
|
2295
2271
|
// src/internal/trace/processors/span-processor.ts
|
|
2296
|
-
var
|
|
2272
|
+
var import_api9 = require("@opentelemetry/api");
|
|
2297
2273
|
var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
2298
2274
|
init_logger();
|
|
2299
2275
|
init_semantic_conventions();
|
|
2300
2276
|
function applyContextAttributes(span) {
|
|
2301
|
-
const sessionProperties =
|
|
2277
|
+
const sessionProperties = import_api9.context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
2302
2278
|
if (sessionProperties) {
|
|
2303
2279
|
for (const [key, value] of Object.entries(sessionProperties)) {
|
|
2304
2280
|
span.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2308,12 +2284,6 @@ function applyContextAttributes(span) {
|
|
|
2308
2284
|
var DEFAULT_MASKING_RULES = [
|
|
2309
2285
|
{
|
|
2310
2286
|
mode: "partial",
|
|
2311
|
-
attributePattern: "gen_ai.prompt",
|
|
2312
|
-
patterns: DEFAULT_PII_PATTERNS
|
|
2313
|
-
},
|
|
2314
|
-
{
|
|
2315
|
-
mode: "partial",
|
|
2316
|
-
attributePattern: "gen_ai.completion",
|
|
2317
2287
|
patterns: DEFAULT_PII_PATTERNS
|
|
2318
2288
|
}
|
|
2319
2289
|
];
|
|
@@ -2323,24 +2293,16 @@ var BrizzSimpleSpanProcessor = class extends import_sdk_trace_base.SimpleSpanPro
|
|
|
2323
2293
|
super(spanExporter);
|
|
2324
2294
|
this.config = config;
|
|
2325
2295
|
}
|
|
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
2296
|
onStart(span, parentContext) {
|
|
2297
|
+
applyContextAttributes(span);
|
|
2298
|
+
super.onStart(span, parentContext);
|
|
2299
|
+
}
|
|
2300
|
+
onEnd(span) {
|
|
2338
2301
|
const maskingConfig = this.config.masking?.spanMasking;
|
|
2339
2302
|
if (maskingConfig) {
|
|
2340
|
-
|
|
2303
|
+
maskReadableSpan(span, maskingConfig);
|
|
2341
2304
|
}
|
|
2342
|
-
|
|
2343
|
-
super.onStart(span, parentContext);
|
|
2305
|
+
super.onEnd(span);
|
|
2344
2306
|
}
|
|
2345
2307
|
};
|
|
2346
2308
|
var BrizzBatchSpanProcessor = class extends import_sdk_trace_base.BatchSpanProcessor {
|
|
@@ -2350,39 +2312,39 @@ var BrizzBatchSpanProcessor = class extends import_sdk_trace_base.BatchSpanProce
|
|
|
2350
2312
|
this.config = config;
|
|
2351
2313
|
}
|
|
2352
2314
|
onStart(span, parentContext) {
|
|
2315
|
+
applyContextAttributes(span);
|
|
2316
|
+
super.onStart(span, parentContext);
|
|
2317
|
+
}
|
|
2318
|
+
onEnd(span) {
|
|
2353
2319
|
const maskingConfig = this.config.masking?.spanMasking;
|
|
2354
2320
|
if (maskingConfig) {
|
|
2355
|
-
|
|
2321
|
+
maskReadableSpan(span, maskingConfig);
|
|
2356
2322
|
}
|
|
2357
|
-
|
|
2358
|
-
super.onStart(span, parentContext);
|
|
2323
|
+
super.onEnd(span);
|
|
2359
2324
|
}
|
|
2360
2325
|
};
|
|
2361
|
-
function
|
|
2362
|
-
|
|
2363
|
-
|
|
2326
|
+
function maskReadableSpan(span, config) {
|
|
2327
|
+
const attrs = span.attributes;
|
|
2328
|
+
if (!attrs || Object.keys(attrs).length === 0) {
|
|
2329
|
+
return;
|
|
2364
2330
|
}
|
|
2365
|
-
let rules = config.rules
|
|
2331
|
+
let rules = config.rules ? [...config.rules] : [];
|
|
2366
2332
|
if (!config.disableDefaultRules) {
|
|
2367
|
-
rules = [...
|
|
2333
|
+
rules = [...rules, ...DEFAULT_MASKING_RULES];
|
|
2368
2334
|
}
|
|
2369
2335
|
try {
|
|
2370
|
-
const
|
|
2371
|
-
for (const [
|
|
2372
|
-
|
|
2373
|
-
}
|
|
2374
|
-
const
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
merged[key] = value;
|
|
2336
|
+
const input = {};
|
|
2337
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
2338
|
+
input[k] = v;
|
|
2339
|
+
}
|
|
2340
|
+
const masked = maskAttributes(input, rules);
|
|
2341
|
+
for (const [k, v] of Object.entries(masked ?? {})) {
|
|
2342
|
+
if (attrs[k] !== v) {
|
|
2343
|
+
attrs[k] = v;
|
|
2379
2344
|
}
|
|
2380
|
-
span.setAttributes(merged);
|
|
2381
2345
|
}
|
|
2382
|
-
return span;
|
|
2383
2346
|
} catch (error) {
|
|
2384
|
-
logger.error("Error masking span
|
|
2385
|
-
return span;
|
|
2347
|
+
logger.error("Error masking span", { err: error });
|
|
2386
2348
|
}
|
|
2387
2349
|
}
|
|
2388
2350
|
|
|
@@ -2498,10 +2460,10 @@ function getSpanProcessor() {
|
|
|
2498
2460
|
}
|
|
2499
2461
|
|
|
2500
2462
|
// src/internal/trace/session.ts
|
|
2501
|
-
var
|
|
2463
|
+
var import_api10 = require("@opentelemetry/api");
|
|
2502
2464
|
init_semantic_conventions();
|
|
2503
2465
|
function setCurrentSpanCustomProperties(properties) {
|
|
2504
|
-
const current =
|
|
2466
|
+
const current = import_api10.trace.getActiveSpan();
|
|
2505
2467
|
if (!current || !current.isRecording()) {
|
|
2506
2468
|
return;
|
|
2507
2469
|
}
|
|
@@ -2513,11 +2475,11 @@ function setCurrentSpanCustomProperties(properties) {
|
|
|
2513
2475
|
}
|
|
2514
2476
|
}
|
|
2515
2477
|
function callWithProperties(properties, fn, thisArg, ...args) {
|
|
2516
|
-
const base =
|
|
2478
|
+
const base = import_api10.context.active();
|
|
2517
2479
|
const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
|
|
2518
2480
|
const merged = prev ? { ...prev, ...properties } : properties;
|
|
2519
2481
|
const next = base.setValue(PROPERTIES_CONTEXT_KEY, merged);
|
|
2520
|
-
return
|
|
2482
|
+
return import_api10.context.with(next, fn, thisArg, ...args);
|
|
2521
2483
|
}
|
|
2522
2484
|
function withProperties(properties, fn, thisArg) {
|
|
2523
2485
|
return function wrapped(...args) {
|
|
@@ -2616,12 +2578,12 @@ var SessionTitle = class {
|
|
|
2616
2578
|
}
|
|
2617
2579
|
};
|
|
2618
2580
|
function getActiveSession() {
|
|
2619
|
-
return
|
|
2581
|
+
return import_api10.context.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
|
|
2620
2582
|
}
|
|
2621
2583
|
function startSession(sessionId, callback, extraProperties, options) {
|
|
2622
2584
|
const isTitle = options?.mode === "title";
|
|
2623
2585
|
const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
|
|
2624
|
-
const tracer =
|
|
2586
|
+
const tracer = import_api10.trace.getTracer("@brizz/sdk");
|
|
2625
2587
|
return tracer.startActiveSpan(spanName, (span) => {
|
|
2626
2588
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
2627
2589
|
if (extraProperties) {
|
|
@@ -2640,8 +2602,8 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
2640
2602
|
}
|
|
2641
2603
|
}
|
|
2642
2604
|
return callWithProperties(contextProperties, () => {
|
|
2643
|
-
const sessionCtx =
|
|
2644
|
-
return
|
|
2605
|
+
const sessionCtx = import_api10.context.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
|
|
2606
|
+
return import_api10.context.with(sessionCtx, () => {
|
|
2645
2607
|
try {
|
|
2646
2608
|
const result = callback(session);
|
|
2647
2609
|
if (result && typeof result.then === "function") {
|
|
@@ -2650,7 +2612,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
2650
2612
|
return value;
|
|
2651
2613
|
}).catch((error) => {
|
|
2652
2614
|
span.recordException(error);
|
|
2653
|
-
span.setStatus({ code:
|
|
2615
|
+
span.setStatus({ code: import_api10.SpanStatusCode.ERROR });
|
|
2654
2616
|
span.end();
|
|
2655
2617
|
throw error;
|
|
2656
2618
|
});
|
|
@@ -2659,7 +2621,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
2659
2621
|
return result;
|
|
2660
2622
|
} catch (error) {
|
|
2661
2623
|
span.recordException(error);
|
|
2662
|
-
span.setStatus({ code:
|
|
2624
|
+
span.setStatus({ code: import_api10.SpanStatusCode.ERROR });
|
|
2663
2625
|
span.end();
|
|
2664
2626
|
throw error;
|
|
2665
2627
|
}
|
|
@@ -2669,7 +2631,7 @@ function startSession(sessionId, callback, extraProperties, options) {
|
|
|
2669
2631
|
}
|
|
2670
2632
|
function startSessionTitle(callback, options) {
|
|
2671
2633
|
const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
|
|
2672
|
-
const tracer =
|
|
2634
|
+
const tracer = import_api10.trace.getTracer("@brizz/sdk");
|
|
2673
2635
|
return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
|
|
2674
2636
|
if (resolvedSessionId) {
|
|
2675
2637
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
|
|
@@ -2688,7 +2650,7 @@ function startSessionTitle(callback, options) {
|
|
|
2688
2650
|
return value;
|
|
2689
2651
|
}).catch((error) => {
|
|
2690
2652
|
span.recordException(error);
|
|
2691
|
-
span.setStatus({ code:
|
|
2653
|
+
span.setStatus({ code: import_api10.SpanStatusCode.ERROR });
|
|
2692
2654
|
span.end();
|
|
2693
2655
|
throw error;
|
|
2694
2656
|
});
|
|
@@ -2697,7 +2659,7 @@ function startSessionTitle(callback, options) {
|
|
|
2697
2659
|
return result;
|
|
2698
2660
|
} catch (error) {
|
|
2699
2661
|
span.recordException(error);
|
|
2700
|
-
span.setStatus({ code:
|
|
2662
|
+
span.setStatus({ code: import_api10.SpanStatusCode.ERROR });
|
|
2701
2663
|
span.end();
|
|
2702
2664
|
throw error;
|
|
2703
2665
|
}
|