@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/preload.cjs
CHANGED
|
@@ -159,6 +159,38 @@ function setLogLevel(level) {
|
|
|
159
159
|
var import_resources3 = require("@opentelemetry/resources");
|
|
160
160
|
var import_sdk_node = require("@opentelemetry/sdk-node");
|
|
161
161
|
|
|
162
|
+
// src/internal/dsn.ts
|
|
163
|
+
var PLACEHOLDER_SERVICE = "<service-name>";
|
|
164
|
+
var SERVICE_NAME_HEADER = "X-Brizz-Service-Name";
|
|
165
|
+
function parseDSN(dsn) {
|
|
166
|
+
let parsed;
|
|
167
|
+
try {
|
|
168
|
+
parsed = new globalThis.URL(dsn);
|
|
169
|
+
} catch {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:" || !parsed.username || !parsed.host) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const scheme = parsed.protocol === "https:" ? "https" : "http";
|
|
176
|
+
let service;
|
|
177
|
+
try {
|
|
178
|
+
service = decodeURIComponent(parsed.pathname.replace(/^\//, ""));
|
|
179
|
+
} catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
if (service === "" || service === PLACEHOLDER_SERVICE) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
scheme,
|
|
187
|
+
host: parsed.host,
|
|
188
|
+
bearer: decodeURIComponent(parsed.username),
|
|
189
|
+
service,
|
|
190
|
+
baseUrl: `${scheme}://${parsed.host}`
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
162
194
|
// src/internal/config.ts
|
|
163
195
|
function resolveConfig(options) {
|
|
164
196
|
const envLogLevel = process.env["BRIZZ_LOG_LEVEL"] || options.logLevel?.toString() || DEFAULT_LOG_LEVEL.toString();
|
|
@@ -185,6 +217,7 @@ function resolveConfig(options) {
|
|
|
185
217
|
appName: options.appName,
|
|
186
218
|
baseUrl: options.baseUrl,
|
|
187
219
|
hasApiKey: !!options.apiKey,
|
|
220
|
+
dsnProvided: !!(process.env["BRIZZ_DSN"] || options.dsn),
|
|
188
221
|
disableBatch: options.disableBatch,
|
|
189
222
|
logLevel: resolvedLogLevel,
|
|
190
223
|
headersCount: Object.keys(options.headers || {}).length,
|
|
@@ -212,7 +245,42 @@ function resolveConfig(options) {
|
|
|
212
245
|
logLevel: resolvedLogLevel,
|
|
213
246
|
masking: resolvedMasking
|
|
214
247
|
};
|
|
215
|
-
|
|
248
|
+
const dsnInput = process.env["BRIZZ_DSN"] || options.dsn;
|
|
249
|
+
let parsedDSN = null;
|
|
250
|
+
if (dsnInput) {
|
|
251
|
+
const kwargConflicts = [];
|
|
252
|
+
if (options.apiKey !== void 0) {
|
|
253
|
+
kwargConflicts.push("apiKey");
|
|
254
|
+
}
|
|
255
|
+
if (options.baseUrl !== void 0) {
|
|
256
|
+
kwargConflicts.push("baseUrl");
|
|
257
|
+
}
|
|
258
|
+
if (options.appName !== void 0) {
|
|
259
|
+
kwargConflicts.push("appName");
|
|
260
|
+
}
|
|
261
|
+
if (kwargConflicts.length > 0) {
|
|
262
|
+
throw new Error(
|
|
263
|
+
`dsn cannot be combined with kwargs ${kwargConflicts.join(", ")}. The DSN bundles bearer, gateway URL, and service name \u2014 choose one configuration style.`
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
const envConflicts = ["BRIZZ_API_KEY", "BRIZZ_BASE_URL", "BRIZZ_APP_NAME"].filter(
|
|
267
|
+
(name) => process.env[name] !== void 0
|
|
268
|
+
);
|
|
269
|
+
if (envConflicts.length > 0) {
|
|
270
|
+
logger.warn(
|
|
271
|
+
`Ignoring ${envConflicts.join(", ")} \u2014 dsn / BRIZZ_DSN takes precedence.`
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
resolvedConfig.apiKey = void 0;
|
|
275
|
+
resolvedConfig.baseUrl = "https://telemetry.brizz.dev";
|
|
276
|
+
resolvedConfig.appName = "unknown-app";
|
|
277
|
+
parsedDSN = parseDSN(dsnInput);
|
|
278
|
+
if (parsedDSN) {
|
|
279
|
+
resolvedConfig.appName = parsedDSN.service;
|
|
280
|
+
resolvedConfig.baseUrl = parsedDSN.baseUrl;
|
|
281
|
+
resolvedConfig.apiKey = parsedDSN.bearer;
|
|
282
|
+
}
|
|
283
|
+
} else if (resolvedConfig.apiKey) {
|
|
216
284
|
resolvedConfig.headers["Authorization"] = `Bearer ${resolvedConfig.apiKey}`;
|
|
217
285
|
}
|
|
218
286
|
if (process.env["BRIZZ_HEADERS"]) {
|
|
@@ -227,14 +295,28 @@ function resolveConfig(options) {
|
|
|
227
295
|
throw new Error("Invalid JSON in BRIZZ_HEADERS environment variable", { cause: error });
|
|
228
296
|
}
|
|
229
297
|
}
|
|
298
|
+
if (dsnInput) {
|
|
299
|
+
const authHeaderKeys = /* @__PURE__ */ new Set(["authorization", SERVICE_NAME_HEADER.toLowerCase()]);
|
|
300
|
+
resolvedConfig.headers = Object.fromEntries(
|
|
301
|
+
Object.entries(resolvedConfig.headers).filter(
|
|
302
|
+
([key]) => !authHeaderKeys.has(key.toLowerCase())
|
|
303
|
+
)
|
|
304
|
+
);
|
|
305
|
+
if (parsedDSN) {
|
|
306
|
+
resolvedConfig.headers["Authorization"] = `Bearer ${parsedDSN.bearer}`;
|
|
307
|
+
resolvedConfig.headers[SERVICE_NAME_HEADER] = parsedDSN.service;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
230
310
|
logger.debug("Configuration resolved with environment variables", {
|
|
231
311
|
appName: resolvedConfig.appName,
|
|
232
312
|
baseUrl: resolvedConfig.baseUrl,
|
|
233
313
|
hasApiKey: !!resolvedConfig.apiKey,
|
|
314
|
+
dsnProvided: !!dsnInput,
|
|
234
315
|
disableBatch: resolvedConfig.disableBatch,
|
|
235
316
|
envOverrides: {
|
|
236
317
|
hasEnvApiKey: !!process.env["BRIZZ_API_KEY"],
|
|
237
318
|
hasEnvBaseUrl: !!process.env["BRIZZ_BASE_URL"],
|
|
319
|
+
hasEnvDsn: !!process.env["BRIZZ_DSN"],
|
|
238
320
|
hasEnvBatch: !!process.env["BRIZZ_DISABLE_BATCH"],
|
|
239
321
|
hasEnvHeaders: !!process.env["BRIZZ_HEADERS"]
|
|
240
322
|
}
|
|
@@ -261,25 +343,137 @@ var import_instrumentation_vertexai = require("@traceloop/instrumentation-vertex
|
|
|
261
343
|
|
|
262
344
|
// src/internal/instrumentation/mcp/instrumentation.ts
|
|
263
345
|
var import_openinference_instrumentation_mcp = require("@arizeai/openinference-instrumentation-mcp");
|
|
264
|
-
var
|
|
346
|
+
var import_api7 = require("@opentelemetry/api");
|
|
265
347
|
var import_instrumentation = require("@opentelemetry/instrumentation");
|
|
266
348
|
|
|
267
349
|
// src/internal/instrumentation/mcp/patches/protocol.ts
|
|
268
|
-
var
|
|
350
|
+
var import_api6 = require("@opentelemetry/api");
|
|
351
|
+
|
|
352
|
+
// src/internal/instrumentation/mcp/schemas.ts
|
|
353
|
+
var import_api2 = require("@opentelemetry/api");
|
|
354
|
+
|
|
355
|
+
// src/internal/instrumentation/mcp/semantic-conventions.ts
|
|
356
|
+
var MCP_TOOL_NAME = "mcp.tool.name";
|
|
357
|
+
var MCP_TOOL_ARGUMENTS = "mcp.tool.arguments";
|
|
358
|
+
var MCP_TOOL_RESULT = "mcp.tool.result";
|
|
359
|
+
var MCP_COMPONENT_TYPE = "mcp.component.type";
|
|
360
|
+
var MCP_COMPONENT_TOOL = "tool";
|
|
361
|
+
var MCP_COMPONENT_TOOL_SCHEMA = "tool_schema";
|
|
362
|
+
var MCP_TOOL_SCHEMA_PARAMETERS = "mcp.tool.schema.parameters";
|
|
363
|
+
var MCP_TOOL_SCHEMA_OUTPUT = "mcp.tool.schema.output";
|
|
364
|
+
var MCP_TOOL_DESCRIPTION = "mcp.tool.description";
|
|
365
|
+
var SPAN_NAME_TOOL_REGISTER = "mcp.tool.register";
|
|
366
|
+
var MCP_METHOD_NAME = "mcp.method.name";
|
|
367
|
+
var MCP_REQUEST_ID = "mcp.request.id";
|
|
368
|
+
var MCP_SESSION_ID = "mcp.session.id";
|
|
369
|
+
var MCP_PROTOCOL_VERSION = "mcp.protocol.version";
|
|
370
|
+
var MCP_RESOURCE_URI = "mcp.resource.uri";
|
|
371
|
+
var RPC_SYSTEM = "rpc.system";
|
|
372
|
+
var RPC_SYSTEM_MCP = "mcp";
|
|
373
|
+
var RPC_RESPONSE_STATUS_CODE = "rpc.response.status_code";
|
|
374
|
+
var GEN_AI_TOOL_NAME = "gen_ai.tool.name";
|
|
375
|
+
var GEN_AI_PROMPT_NAME = "gen_ai.prompt.name";
|
|
376
|
+
var GEN_AI_OPERATION_NAME = "gen_ai.operation.name";
|
|
377
|
+
var GEN_AI_OPERATION_EXECUTE_TOOL = "execute_tool";
|
|
378
|
+
var NETWORK_TRANSPORT = "network.transport";
|
|
379
|
+
var ERROR_TYPE = "error.type";
|
|
380
|
+
var ERROR_TYPE_TOOL = "tool_error";
|
|
381
|
+
var JSONRPC_REQUEST_ID = "jsonrpc.request.id";
|
|
382
|
+
var SPAN_NAME_TOOLS_CALL = "tools/call";
|
|
383
|
+
var MAX_ATTRIBUTE_LENGTH = 32 * 1024;
|
|
384
|
+
var TRUNCATION_SUFFIX = "\u2026(truncated)";
|
|
385
|
+
var METHOD_TOOLS_CALL = "tools/call";
|
|
386
|
+
var METHOD_TOOLS_LIST = "tools/list";
|
|
387
|
+
var METHOD_RESOURCES_READ = "resources/read";
|
|
388
|
+
var METHOD_PROMPTS_GET = "prompts/get";
|
|
389
|
+
var METHOD_INITIALIZE = "initialize";
|
|
390
|
+
|
|
391
|
+
// src/internal/instrumentation/mcp/schemas.ts
|
|
392
|
+
var _MAX_SCHEMA_ATTR_BYTES = 4e3;
|
|
393
|
+
function truncateSchemaAttr(value) {
|
|
394
|
+
if (value.length <= _MAX_SCHEMA_ATTR_BYTES) {
|
|
395
|
+
return value;
|
|
396
|
+
}
|
|
397
|
+
return `{"_truncated":true,"original_length":${value.length}}`;
|
|
398
|
+
}
|
|
399
|
+
function safeStringify(value) {
|
|
400
|
+
if (value === null || value === void 0) {
|
|
401
|
+
return "";
|
|
402
|
+
}
|
|
403
|
+
try {
|
|
404
|
+
return JSON.stringify(value);
|
|
405
|
+
} catch {
|
|
406
|
+
return "";
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function emitSchemaSpansFromListResponse(result, transportSessionId, tracer) {
|
|
410
|
+
if (!transportSessionId) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const tools = extractTools(result);
|
|
414
|
+
if (tools === void 0) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
for (const tool of tools) {
|
|
418
|
+
const name = typeof tool.name === "string" ? tool.name : void 0;
|
|
419
|
+
if (!name) {
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
const span = tracer.startSpan(`${SPAN_NAME_TOOL_REGISTER} ${name}`, {
|
|
423
|
+
kind: import_api2.SpanKind.INTERNAL
|
|
424
|
+
});
|
|
425
|
+
try {
|
|
426
|
+
stampSchemaAttributes(span, name, transportSessionId, tool);
|
|
427
|
+
span.setStatus({ code: import_api2.SpanStatusCode.OK });
|
|
428
|
+
} finally {
|
|
429
|
+
span.end();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function stampSchemaAttributes(span, toolName, transportSessionId, tool) {
|
|
434
|
+
if (!span.isRecording()) {
|
|
435
|
+
logger.warn(
|
|
436
|
+
`Brizz MCP: schema span is not recording; dropping attributes for ${toolName}`
|
|
437
|
+
);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
const description = typeof tool.description === "string" ? tool.description : "";
|
|
441
|
+
const parameters = truncateSchemaAttr(safeStringify(tool.inputSchema));
|
|
442
|
+
const outputSchema = tool.outputSchema !== void 0 && tool.outputSchema !== null ? truncateSchemaAttr(safeStringify(tool.outputSchema)) : "";
|
|
443
|
+
span.setAttribute(RPC_SYSTEM, RPC_SYSTEM_MCP);
|
|
444
|
+
span.setAttribute(MCP_COMPONENT_TYPE, MCP_COMPONENT_TOOL_SCHEMA);
|
|
445
|
+
span.setAttribute(MCP_SESSION_ID, transportSessionId);
|
|
446
|
+
span.setAttribute(MCP_TOOL_NAME, toolName);
|
|
447
|
+
span.setAttribute(MCP_TOOL_SCHEMA_PARAMETERS, parameters);
|
|
448
|
+
span.setAttribute(MCP_TOOL_SCHEMA_OUTPUT, outputSchema);
|
|
449
|
+
span.setAttribute(MCP_TOOL_DESCRIPTION, description);
|
|
450
|
+
}
|
|
451
|
+
function extractTools(result) {
|
|
452
|
+
if (!result || typeof result !== "object") {
|
|
453
|
+
return void 0;
|
|
454
|
+
}
|
|
455
|
+
const tools = result.tools;
|
|
456
|
+
if (!Array.isArray(tools)) {
|
|
457
|
+
return void 0;
|
|
458
|
+
}
|
|
459
|
+
return tools.filter(
|
|
460
|
+
(t) => t !== null && typeof t === "object"
|
|
461
|
+
);
|
|
462
|
+
}
|
|
269
463
|
|
|
270
464
|
// src/internal/instrumentation/mcp/session.ts
|
|
271
|
-
var
|
|
465
|
+
var import_api4 = require("@opentelemetry/api");
|
|
272
466
|
|
|
273
467
|
// src/internal/semantic-conventions.ts
|
|
274
|
-
var
|
|
468
|
+
var import_api3 = require("@opentelemetry/api");
|
|
275
469
|
var BRIZZ = "brizz";
|
|
276
470
|
var PROPERTIES = "properties";
|
|
277
471
|
var SESSION_ID = "session.id";
|
|
278
|
-
var PROPERTIES_CONTEXT_KEY = (0,
|
|
279
|
-
var SESSION_OBJECT_CONTEXT_KEY = (0,
|
|
472
|
+
var PROPERTIES_CONTEXT_KEY = (0, import_api3.createContextKey)(PROPERTIES);
|
|
473
|
+
var SESSION_OBJECT_CONTEXT_KEY = (0, import_api3.createContextKey)("brizz.session.object");
|
|
280
474
|
|
|
281
475
|
// src/internal/instrumentation/mcp/session.ts
|
|
282
|
-
function stampAndPropagateSession(span, sessionId, baseContext =
|
|
476
|
+
function stampAndPropagateSession(span, sessionId, baseContext = import_api4.context.active()) {
|
|
283
477
|
if (!sessionId) {
|
|
284
478
|
return { context: baseContext, sessionId: null };
|
|
285
479
|
}
|
|
@@ -306,39 +500,7 @@ function stampAndPropagateSession(span, sessionId, baseContext = import_api3.con
|
|
|
306
500
|
}
|
|
307
501
|
|
|
308
502
|
// src/internal/instrumentation/mcp/patches/attributes.ts
|
|
309
|
-
var
|
|
310
|
-
|
|
311
|
-
// src/internal/instrumentation/mcp/semantic-conventions.ts
|
|
312
|
-
var MCP_TOOL_NAME = "mcp.tool.name";
|
|
313
|
-
var MCP_TOOL_ARGUMENTS = "mcp.tool.arguments";
|
|
314
|
-
var MCP_TOOL_RESULT = "mcp.tool.result";
|
|
315
|
-
var MCP_COMPONENT_TYPE = "mcp.component.type";
|
|
316
|
-
var MCP_COMPONENT_TOOL = "tool";
|
|
317
|
-
var MCP_METHOD_NAME = "mcp.method.name";
|
|
318
|
-
var MCP_REQUEST_ID = "mcp.request.id";
|
|
319
|
-
var MCP_SESSION_ID = "mcp.session.id";
|
|
320
|
-
var MCP_PROTOCOL_VERSION = "mcp.protocol.version";
|
|
321
|
-
var MCP_RESOURCE_URI = "mcp.resource.uri";
|
|
322
|
-
var RPC_SYSTEM = "rpc.system";
|
|
323
|
-
var RPC_SYSTEM_MCP = "mcp";
|
|
324
|
-
var RPC_RESPONSE_STATUS_CODE = "rpc.response.status_code";
|
|
325
|
-
var GEN_AI_TOOL_NAME = "gen_ai.tool.name";
|
|
326
|
-
var GEN_AI_PROMPT_NAME = "gen_ai.prompt.name";
|
|
327
|
-
var GEN_AI_OPERATION_NAME = "gen_ai.operation.name";
|
|
328
|
-
var GEN_AI_OPERATION_EXECUTE_TOOL = "execute_tool";
|
|
329
|
-
var NETWORK_TRANSPORT = "network.transport";
|
|
330
|
-
var ERROR_TYPE = "error.type";
|
|
331
|
-
var ERROR_TYPE_TOOL = "tool_error";
|
|
332
|
-
var JSONRPC_REQUEST_ID = "jsonrpc.request.id";
|
|
333
|
-
var SPAN_NAME_TOOLS_CALL = "tools/call";
|
|
334
|
-
var MAX_ATTRIBUTE_LENGTH = 32 * 1024;
|
|
335
|
-
var TRUNCATION_SUFFIX = "\u2026(truncated)";
|
|
336
|
-
var METHOD_TOOLS_CALL = "tools/call";
|
|
337
|
-
var METHOD_RESOURCES_READ = "resources/read";
|
|
338
|
-
var METHOD_PROMPTS_GET = "prompts/get";
|
|
339
|
-
var METHOD_INITIALIZE = "initialize";
|
|
340
|
-
|
|
341
|
-
// src/internal/instrumentation/mcp/patches/attributes.ts
|
|
503
|
+
var import_api5 = require("@opentelemetry/api");
|
|
342
504
|
function deriveSpanName(method, params) {
|
|
343
505
|
try {
|
|
344
506
|
if (method === METHOD_TOOLS_CALL) {
|
|
@@ -441,7 +603,7 @@ function applyResultAttributes(span, method, result) {
|
|
|
441
603
|
if (obj && obj["isError"] === true) {
|
|
442
604
|
span.setAttribute(ERROR_TYPE, ERROR_TYPE_TOOL);
|
|
443
605
|
const message = extractToolErrorMessage(obj);
|
|
444
|
-
span.setStatus({ code:
|
|
606
|
+
span.setStatus({ code: import_api5.SpanStatusCode.ERROR, message });
|
|
445
607
|
}
|
|
446
608
|
}
|
|
447
609
|
function applyErrorAttributes(span, err) {
|
|
@@ -465,7 +627,7 @@ function applyErrorAttributes(span, err) {
|
|
|
465
627
|
} catch {
|
|
466
628
|
}
|
|
467
629
|
span.setStatus({
|
|
468
|
-
code:
|
|
630
|
+
code: import_api5.SpanStatusCode.ERROR,
|
|
469
631
|
message: typeof error?.message === "string" ? error.message : void 0
|
|
470
632
|
});
|
|
471
633
|
}
|
|
@@ -572,8 +734,8 @@ function wrapRequest(original, tracer) {
|
|
|
572
734
|
return original.apply(this, args);
|
|
573
735
|
}
|
|
574
736
|
return executeAroundSpan(span, request.method, () => {
|
|
575
|
-
const ctx =
|
|
576
|
-
return
|
|
737
|
+
const ctx = import_api6.trace.setSpan(import_api6.context.active(), span);
|
|
738
|
+
return import_api6.context.with(ctx, () => original.apply(this, args));
|
|
577
739
|
});
|
|
578
740
|
};
|
|
579
741
|
}
|
|
@@ -597,7 +759,20 @@ function wrapOnRequest(original, tracer) {
|
|
|
597
759
|
return original.apply(this, args);
|
|
598
760
|
}
|
|
599
761
|
const { span, spanCtx } = started;
|
|
600
|
-
const
|
|
762
|
+
const transportSessionId = this.sessionId ?? this._transport?.sessionId;
|
|
763
|
+
const postResult = method === METHOD_TOOLS_LIST ? (result) => {
|
|
764
|
+
try {
|
|
765
|
+
emitSchemaSpansFromListResponse(result, transportSessionId, tracer);
|
|
766
|
+
} catch (error) {
|
|
767
|
+
logger.warn(
|
|
768
|
+
`Brizz MCP: failed to emit tools/list schema spans: ${String(error)}`
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
} : void 0;
|
|
772
|
+
const wrappedHandler = (req, extra) => import_api6.context.with(
|
|
773
|
+
spanCtx,
|
|
774
|
+
() => executeHandler(span, method, handler, req, extra, postResult)
|
|
775
|
+
);
|
|
601
776
|
const hadEntry = handlers.has(method);
|
|
602
777
|
const prev = handlers.get(method);
|
|
603
778
|
handlers.set(method, wrappedHandler);
|
|
@@ -620,7 +795,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
620
795
|
}
|
|
621
796
|
};
|
|
622
797
|
}
|
|
623
|
-
function executeAroundSpan(span, method, run) {
|
|
798
|
+
function executeAroundSpan(span, method, run, postResult) {
|
|
624
799
|
let result;
|
|
625
800
|
try {
|
|
626
801
|
result = run();
|
|
@@ -631,12 +806,18 @@ function executeAroundSpan(span, method, run) {
|
|
|
631
806
|
}
|
|
632
807
|
if (!isThenable(result)) {
|
|
633
808
|
safeApplyResultAttributes(span, method, result);
|
|
809
|
+
if (postResult) {
|
|
810
|
+
postResult(result);
|
|
811
|
+
}
|
|
634
812
|
safeEnd(span);
|
|
635
813
|
return result;
|
|
636
814
|
}
|
|
637
815
|
return result.then(
|
|
638
816
|
(value) => {
|
|
639
817
|
safeApplyResultAttributes(span, method, value);
|
|
818
|
+
if (postResult) {
|
|
819
|
+
postResult(value);
|
|
820
|
+
}
|
|
640
821
|
safeEnd(span);
|
|
641
822
|
return value;
|
|
642
823
|
},
|
|
@@ -647,13 +828,13 @@ function executeAroundSpan(span, method, run) {
|
|
|
647
828
|
}
|
|
648
829
|
);
|
|
649
830
|
}
|
|
650
|
-
function executeHandler(span, method, handler, req, extra) {
|
|
651
|
-
return executeAroundSpan(span, method, () => handler(req, extra));
|
|
831
|
+
function executeHandler(span, method, handler, req, extra, postResult) {
|
|
832
|
+
return executeAroundSpan(span, method, () => handler(req, extra), postResult);
|
|
652
833
|
}
|
|
653
834
|
function safeStartClientSpan(tracer, request, protocol) {
|
|
654
835
|
try {
|
|
655
836
|
const spanName = deriveSpanName(request.method, request.params);
|
|
656
|
-
const span = tracer.startSpan(spanName, { kind:
|
|
837
|
+
const span = tracer.startSpan(spanName, { kind: import_api6.SpanKind.CLIENT });
|
|
657
838
|
applyClientRequestAttributes(
|
|
658
839
|
span,
|
|
659
840
|
request,
|
|
@@ -671,13 +852,13 @@ function safeStartServerSpan(tracer, request, protocol) {
|
|
|
671
852
|
const spanName = deriveSpanName(request.method, request.params);
|
|
672
853
|
const span = tracer.startSpan(
|
|
673
854
|
spanName,
|
|
674
|
-
{ kind:
|
|
855
|
+
{ kind: import_api6.SpanKind.SERVER },
|
|
675
856
|
parentCtx
|
|
676
857
|
);
|
|
677
858
|
applyServerRequestAttributes(span, request, protocol);
|
|
678
859
|
const sessionId = protocol.sessionId ?? protocol._transport?.sessionId;
|
|
679
860
|
const { context: sessCtx } = stampAndPropagateSession(span, sessionId, parentCtx);
|
|
680
|
-
return { span, spanCtx:
|
|
861
|
+
return { span, spanCtx: import_api6.trace.setSpan(sessCtx, span) };
|
|
681
862
|
} catch (error) {
|
|
682
863
|
logger.debug(`Brizz MCP: failed to open SERVER span: ${String(error)}`);
|
|
683
864
|
return null;
|
|
@@ -687,14 +868,14 @@ function extractParentContext(request) {
|
|
|
687
868
|
try {
|
|
688
869
|
const meta = request.params?._meta;
|
|
689
870
|
if (meta && typeof meta === "object") {
|
|
690
|
-
return
|
|
871
|
+
return import_api6.propagation.extract(import_api6.context.active(), meta);
|
|
691
872
|
}
|
|
692
873
|
} catch (error) {
|
|
693
874
|
logger.debug(
|
|
694
875
|
`Brizz MCP: failed to extract parent context from _meta: ${String(error)}`
|
|
695
876
|
);
|
|
696
877
|
}
|
|
697
|
-
return
|
|
878
|
+
return import_api6.context.active();
|
|
698
879
|
}
|
|
699
880
|
function isThenable(value) {
|
|
700
881
|
return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
@@ -727,7 +908,7 @@ function safeEnd(span) {
|
|
|
727
908
|
|
|
728
909
|
// src/internal/version.ts
|
|
729
910
|
function getSDKVersion() {
|
|
730
|
-
return "0.1.
|
|
911
|
+
return "0.1.26";
|
|
731
912
|
}
|
|
732
913
|
|
|
733
914
|
// src/internal/instrumentation/mcp/version.ts
|
|
@@ -751,7 +932,7 @@ var MCPInstrumentation = class extends import_openinference_instrumentation_mcp.
|
|
|
751
932
|
brizzTracer;
|
|
752
933
|
constructor(_config) {
|
|
753
934
|
super({ instrumentationConfig: _config?.instrumentationConfig });
|
|
754
|
-
this.brizzTracer =
|
|
935
|
+
this.brizzTracer = import_api7.trace.getTracer(INSTRUMENTATION_NAME, INSTRUMENTATION_VERSION);
|
|
755
936
|
}
|
|
756
937
|
/**
|
|
757
938
|
* Extend `super.init()` with our protocol-layer module definition.
|
|
@@ -992,26 +1173,16 @@ var import_resources = require("@opentelemetry/resources");
|
|
|
992
1173
|
var import_sdk_logs2 = require("@opentelemetry/sdk-logs");
|
|
993
1174
|
|
|
994
1175
|
// src/internal/log/processors/log-processor.ts
|
|
995
|
-
var
|
|
1176
|
+
var import_api8 = require("@opentelemetry/api");
|
|
996
1177
|
var import_sdk_logs = require("@opentelemetry/sdk-logs");
|
|
997
1178
|
|
|
998
1179
|
// src/internal/masking/patterns.ts
|
|
999
1180
|
var DEFAULT_PII_PATTERNS = [
|
|
1000
|
-
// Email addresses
|
|
1001
|
-
{
|
|
1002
|
-
name: "email_addresses",
|
|
1003
|
-
pattern: String.raw`\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b`
|
|
1004
|
-
},
|
|
1005
1181
|
// Phone numbers (US format)
|
|
1006
1182
|
{
|
|
1007
1183
|
name: "us_phone_numbers",
|
|
1008
1184
|
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]|$)`
|
|
1009
1185
|
},
|
|
1010
|
-
// Social Security Numbers
|
|
1011
|
-
{
|
|
1012
|
-
name: "ssn",
|
|
1013
|
-
pattern: String.raw`\b(?!000|666|9\d{2})\d{3}[-\s]?(?!00)\d{2}[-\s]?(?!0000)\d{4}\b`
|
|
1014
|
-
},
|
|
1015
1186
|
// Credit card numbers
|
|
1016
1187
|
{
|
|
1017
1188
|
name: "credit_cards",
|
|
@@ -1035,19 +1206,11 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1035
1206
|
name: "openai_keys",
|
|
1036
1207
|
pattern: String.raw`\bsk[-_][a-zA-Z0-9]{20,}\b`
|
|
1037
1208
|
},
|
|
1038
|
-
{
|
|
1039
|
-
name: "base64_secrets",
|
|
1040
|
-
pattern: String.raw`\b[A-Za-z0-9+/]{64,}={0,2}\b`
|
|
1041
|
-
},
|
|
1042
1209
|
// AWS Keys
|
|
1043
1210
|
{
|
|
1044
1211
|
name: "aws_access_keys",
|
|
1045
1212
|
pattern: String.raw`\b(?:AKIA|ABIA|ACCA|ASIA)[0-9A-Z]{16}\b`
|
|
1046
1213
|
},
|
|
1047
|
-
{
|
|
1048
|
-
name: "aws_secret_keys",
|
|
1049
|
-
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`
|
|
1050
|
-
},
|
|
1051
1214
|
// GitHub tokens
|
|
1052
1215
|
{
|
|
1053
1216
|
name: "github_tokens",
|
|
@@ -1078,11 +1241,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1078
1241
|
name: "ipv6_addresses",
|
|
1079
1242
|
pattern: String.raw`\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b`
|
|
1080
1243
|
},
|
|
1081
|
-
// Medical records
|
|
1082
|
-
{
|
|
1083
|
-
name: "medical_record_numbers",
|
|
1084
|
-
pattern: String.raw`\b(?:[Mm][Rr][Nn])[-\s]?\d{6,10}\b`
|
|
1085
|
-
},
|
|
1086
1244
|
// Bitcoin addresses
|
|
1087
1245
|
{
|
|
1088
1246
|
name: "bitcoin_addresses",
|
|
@@ -1093,11 +1251,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1093
1251
|
name: "ethereum_addresses",
|
|
1094
1252
|
pattern: String.raw`\b0x[a-fA-F0-9]{40}(?![a-fA-F0-9])\b`
|
|
1095
1253
|
},
|
|
1096
|
-
// UUIDs
|
|
1097
|
-
{
|
|
1098
|
-
name: "uuids",
|
|
1099
|
-
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`
|
|
1100
|
-
},
|
|
1101
1254
|
// Database connection strings
|
|
1102
1255
|
{
|
|
1103
1256
|
name: "database_connections",
|
|
@@ -1116,90 +1269,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1116
1269
|
name: "certificates",
|
|
1117
1270
|
pattern: "-----BEGIN CERTIFICATE-----"
|
|
1118
1271
|
},
|
|
1119
|
-
// Date of birth patterns
|
|
1120
|
-
{
|
|
1121
|
-
name: "date_of_birth_us",
|
|
1122
|
-
pattern: String.raw`\b(?:0[1-9]|1[0-2])[-/](?:0[1-9]|[12]\\d|3[01])[-/](?:19|20)\\d{2}\b`
|
|
1123
|
-
},
|
|
1124
|
-
{
|
|
1125
|
-
name: "date_of_birth_iso",
|
|
1126
|
-
pattern: String.raw`\b(?:19|20)\\d{2}[-/](?:0[1-9]|1[0-2])[-/](?:0[1-9]|[12]\\d|3[01])\b`
|
|
1127
|
-
},
|
|
1128
|
-
// US Identification Numbers
|
|
1129
|
-
{
|
|
1130
|
-
name: "us_passport_numbers",
|
|
1131
|
-
pattern: String.raw`\b[A-Z]?\\d{6,9}\b`
|
|
1132
|
-
},
|
|
1133
|
-
{
|
|
1134
|
-
name: "drivers_license",
|
|
1135
|
-
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`
|
|
1136
|
-
},
|
|
1137
|
-
{
|
|
1138
|
-
name: "bank_account_numbers",
|
|
1139
|
-
pattern: String.raw`\b\\d{10,17}\b`
|
|
1140
|
-
},
|
|
1141
|
-
{
|
|
1142
|
-
name: "aba_routing_numbers",
|
|
1143
|
-
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`
|
|
1144
|
-
},
|
|
1145
|
-
{
|
|
1146
|
-
name: "health_insurance_numbers",
|
|
1147
|
-
pattern: String.raw`\b\\d{10}[A-Z]\b`
|
|
1148
|
-
},
|
|
1149
|
-
{
|
|
1150
|
-
name: "employee_ids",
|
|
1151
|
-
pattern: String.raw`\b(?:[Ee][Mm][Pp]|[Ee][Mm][Pp][Ll][Oo][Yy][Ee][Ee]|[Ee])[-\s]?\\d{5,8}\b`
|
|
1152
|
-
},
|
|
1153
|
-
{
|
|
1154
|
-
name: "tax_ein",
|
|
1155
|
-
pattern: String.raw`\b\\d{2}-\\d{7}\b`
|
|
1156
|
-
},
|
|
1157
|
-
{
|
|
1158
|
-
name: "medicare_beneficiary_id",
|
|
1159
|
-
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`
|
|
1160
|
-
},
|
|
1161
|
-
{
|
|
1162
|
-
name: "national_provider_id",
|
|
1163
|
-
pattern: String.raw`\b1\\d{9}\b`
|
|
1164
|
-
},
|
|
1165
|
-
{
|
|
1166
|
-
name: "dea_numbers",
|
|
1167
|
-
pattern: String.raw`\b[A-Z]{2}\\d{7}\b`
|
|
1168
|
-
},
|
|
1169
|
-
{
|
|
1170
|
-
name: "itin",
|
|
1171
|
-
pattern: String.raw`\b9\\d{2}(?:[ \\-]?)[7,8]\\d(?:[ \\-]?)\\d{4}\b`
|
|
1172
|
-
},
|
|
1173
|
-
// Vehicle and Location
|
|
1174
|
-
{
|
|
1175
|
-
name: "vin_numbers",
|
|
1176
|
-
pattern: String.raw`\b[A-HJ-NPR-Z0-9]{17}\b`
|
|
1177
|
-
},
|
|
1178
|
-
{
|
|
1179
|
-
name: "coordinates",
|
|
1180
|
-
pattern: String.raw`\b[-+]?(?:[0-8]?\\d(?:\\.\\d+)?|90(?:\\.0+)?),\\s*[-+]?(?:1[0-7]\\d(?:\\.\\d+)?|180(?:\\.0+)?|[0-9]?\\d(?:\\.\\d+)?)\b`
|
|
1181
|
-
},
|
|
1182
|
-
{
|
|
1183
|
-
name: "us_license_plates",
|
|
1184
|
-
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`
|
|
1185
|
-
},
|
|
1186
|
-
{
|
|
1187
|
-
name: "us_zip_codes",
|
|
1188
|
-
pattern: String.raw`\b(\\d{5}-\\d{4}|\\d{5})\b`
|
|
1189
|
-
},
|
|
1190
|
-
{
|
|
1191
|
-
name: "us_street_addresses",
|
|
1192
|
-
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`
|
|
1193
|
-
},
|
|
1194
|
-
// International Banking
|
|
1195
|
-
{
|
|
1196
|
-
name: "iban",
|
|
1197
|
-
pattern: String.raw`\b[A-Z]{2}\d{2}[A-Z0-9]{4}\d{7}([A-Z0-9]?){0,16}\b`
|
|
1198
|
-
},
|
|
1199
|
-
{
|
|
1200
|
-
name: "swift_bic",
|
|
1201
|
-
pattern: String.raw`\b[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?\b`
|
|
1202
|
-
},
|
|
1203
1272
|
// Additional API Keys and Tokens
|
|
1204
1273
|
{
|
|
1205
1274
|
name: "google_oauth",
|
|
@@ -1262,73 +1331,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1262
1331
|
name: "putty_ssh_keys",
|
|
1263
1332
|
pattern: String.raw`PuTTY-User-Key-File-2: ssh-(?:rsa|dss)\s*Encryption: none(?:.|\s?)*?Private-MAC:`
|
|
1264
1333
|
},
|
|
1265
|
-
// International Phone Numbers
|
|
1266
|
-
{
|
|
1267
|
-
name: "france_phone_numbers",
|
|
1268
|
-
pattern: String.raw`\b([0O]?[1lI][1lI])?[3E][3E][0O]?[\\dOIlZEASB]{9}\b`
|
|
1269
|
-
},
|
|
1270
|
-
{
|
|
1271
|
-
name: "german_phone_numbers",
|
|
1272
|
-
pattern: String.raw`\b[\d\w]\d{2}[\d\w]{6}\d[\d\w]\b`
|
|
1273
|
-
},
|
|
1274
|
-
{
|
|
1275
|
-
name: "uk_phone_numbers",
|
|
1276
|
-
pattern: String.raw`\b([0O]?[1lI][1lI])?[4A][4A][\\dOIlZEASB]{10,11}\b`
|
|
1277
|
-
},
|
|
1278
|
-
// International IDs
|
|
1279
|
-
{
|
|
1280
|
-
name: "uk_drivers_license",
|
|
1281
|
-
pattern: String.raw`\b[A-Z]{5}\d{6}[A-Z]{2}\d{1}[A-Z]{2}\b`
|
|
1282
|
-
},
|
|
1283
|
-
{
|
|
1284
|
-
name: "uk_passport",
|
|
1285
|
-
pattern: String.raw`\b\\d{10}GB[RP]\\d{7}[UMF]{1}\\d{9}\b`
|
|
1286
|
-
},
|
|
1287
|
-
{
|
|
1288
|
-
name: "argentina_dni",
|
|
1289
|
-
pattern: String.raw`\b\\d{2}\\.\\d{3}\\.\\d{3}\b`
|
|
1290
|
-
},
|
|
1291
|
-
{
|
|
1292
|
-
name: "australia_tfn",
|
|
1293
|
-
pattern: String.raw`\b[Tt][Ff][Nn](:|:\\s|\\s|)(\\d{8,9})\b`
|
|
1294
|
-
},
|
|
1295
|
-
{
|
|
1296
|
-
name: "canada_passport",
|
|
1297
|
-
pattern: String.raw`\b[\\w]{2}[\\d]{6}\b`
|
|
1298
|
-
},
|
|
1299
|
-
{
|
|
1300
|
-
name: "croatia_vat",
|
|
1301
|
-
pattern: String.raw`\bHR\\d{11}\b`
|
|
1302
|
-
},
|
|
1303
|
-
{
|
|
1304
|
-
name: "czech_vat",
|
|
1305
|
-
pattern: String.raw`\bCZ\\d{8,10}\b`
|
|
1306
|
-
},
|
|
1307
|
-
{
|
|
1308
|
-
name: "denmark_personal_id",
|
|
1309
|
-
pattern: String.raw`\b(?:\\d{10}|\\d{6}[-\\s]\\d{4})\b`
|
|
1310
|
-
},
|
|
1311
|
-
{
|
|
1312
|
-
name: "france_national_id",
|
|
1313
|
-
pattern: String.raw`\b\\d{12}\b`
|
|
1314
|
-
},
|
|
1315
|
-
{
|
|
1316
|
-
name: "france_ssn",
|
|
1317
|
-
pattern: String.raw`\b(?:\\d{13}|\\d{13}\\s\\d{2})\b`
|
|
1318
|
-
},
|
|
1319
|
-
{
|
|
1320
|
-
name: "france_passport",
|
|
1321
|
-
pattern: String.raw`\b\\d{2}11\\d{5}\b`
|
|
1322
|
-
},
|
|
1323
|
-
{
|
|
1324
|
-
name: "california_drivers_license",
|
|
1325
|
-
pattern: String.raw`\b[A-Z]{1}\\d{7}\b`
|
|
1326
|
-
},
|
|
1327
|
-
// Medical and Healthcare
|
|
1328
|
-
{
|
|
1329
|
-
name: "hipaa_ndc",
|
|
1330
|
-
pattern: String.raw`\b\\d{4,5}-\\d{3,4}-\\d{1,2}\b`
|
|
1331
|
-
},
|
|
1332
1334
|
// Security and Network
|
|
1333
1335
|
{
|
|
1334
1336
|
name: "cve_numbers",
|
|
@@ -1362,44 +1364,6 @@ var DEFAULT_PII_PATTERNS = [
|
|
|
1362
1364
|
{
|
|
1363
1365
|
name: "discover_cards",
|
|
1364
1366
|
pattern: String.raw`\b65[4-9][0-9]{13}|64[4-9][0-9]{13}|6011[0-9]{12}\b`
|
|
1365
|
-
},
|
|
1366
|
-
{
|
|
1367
|
-
name: "enhanced_credit_cards",
|
|
1368
|
-
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`
|
|
1369
|
-
},
|
|
1370
|
-
// Bank Routing Numbers (US specific)
|
|
1371
|
-
{
|
|
1372
|
-
name: "bbva_routing_ca",
|
|
1373
|
-
pattern: String.raw`\\b321170538\\b`
|
|
1374
|
-
},
|
|
1375
|
-
{
|
|
1376
|
-
name: "boa_routing_ca",
|
|
1377
|
-
pattern: String.raw`\\b(?:121|026)00(?:0|9)(?:358|593)\\b`
|
|
1378
|
-
},
|
|
1379
|
-
{
|
|
1380
|
-
name: "chase_routing_ca",
|
|
1381
|
-
pattern: String.raw`\\b322271627\\b`
|
|
1382
|
-
},
|
|
1383
|
-
{
|
|
1384
|
-
name: "citibank_routing_ca",
|
|
1385
|
-
pattern: String.raw`\\b32(?:11|22)71(?:18|72)4\\b`
|
|
1386
|
-
},
|
|
1387
|
-
{
|
|
1388
|
-
name: "usbank_routing_ca",
|
|
1389
|
-
pattern: String.raw`\\b12(?:1122676|2235821)\\b`
|
|
1390
|
-
},
|
|
1391
|
-
{
|
|
1392
|
-
name: "united_bank_routing_ca",
|
|
1393
|
-
pattern: String.raw`\\b122243350\\b`
|
|
1394
|
-
},
|
|
1395
|
-
{
|
|
1396
|
-
name: "wells_fargo_routing_ca",
|
|
1397
|
-
pattern: String.raw`\\b121042882\\b`
|
|
1398
|
-
},
|
|
1399
|
-
// Unrealistic alphanumeric identifiers
|
|
1400
|
-
{
|
|
1401
|
-
name: "generic_non_usual",
|
|
1402
|
-
pattern: String.raw`(?:^|\s)(?=[A-Za-z0-9_\)\*\=@]*[A-Za-z])(?=[A-Za-z0-9_\)\*\=@]*[0-9])([A-Za-z0-9_\)\*\=@]{5,})(?=\s|$)`
|
|
1403
1367
|
}
|
|
1404
1368
|
];
|
|
1405
1369
|
|
|
@@ -1638,7 +1602,7 @@ var BrizzSimpleLogRecordProcessor = class extends import_sdk_logs.SimpleLogRecor
|
|
|
1638
1602
|
if (maskingConfig) {
|
|
1639
1603
|
maskLog(logRecord, maskingConfig);
|
|
1640
1604
|
}
|
|
1641
|
-
const associationProperties =
|
|
1605
|
+
const associationProperties = import_api8.context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1642
1606
|
if (associationProperties) {
|
|
1643
1607
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1644
1608
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -1658,7 +1622,7 @@ var BrizzBatchLogRecordProcessor = class extends import_sdk_logs.BatchLogRecordP
|
|
|
1658
1622
|
if (maskingConfig) {
|
|
1659
1623
|
maskLog(logRecord, maskingConfig);
|
|
1660
1624
|
}
|
|
1661
|
-
const associationProperties =
|
|
1625
|
+
const associationProperties = import_api8.context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
1662
1626
|
if (associationProperties) {
|
|
1663
1627
|
for (const [key, value] of Object.entries(associationProperties)) {
|
|
1664
1628
|
logRecord.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2045,10 +2009,10 @@ var BrizzSpanExporter = class {
|
|
|
2045
2009
|
};
|
|
2046
2010
|
|
|
2047
2011
|
// src/internal/trace/processors/span-processor.ts
|
|
2048
|
-
var
|
|
2012
|
+
var import_api9 = require("@opentelemetry/api");
|
|
2049
2013
|
var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
2050
2014
|
function applyContextAttributes(span) {
|
|
2051
|
-
const sessionProperties =
|
|
2015
|
+
const sessionProperties = import_api9.context.active().getValue(PROPERTIES_CONTEXT_KEY);
|
|
2052
2016
|
if (sessionProperties) {
|
|
2053
2017
|
for (const [key, value] of Object.entries(sessionProperties)) {
|
|
2054
2018
|
span.setAttribute(`${BRIZZ}.${key}`, value);
|
|
@@ -2058,12 +2022,6 @@ function applyContextAttributes(span) {
|
|
|
2058
2022
|
var DEFAULT_MASKING_RULES = [
|
|
2059
2023
|
{
|
|
2060
2024
|
mode: "partial",
|
|
2061
|
-
attributePattern: "gen_ai.prompt",
|
|
2062
|
-
patterns: DEFAULT_PII_PATTERNS
|
|
2063
|
-
},
|
|
2064
|
-
{
|
|
2065
|
-
mode: "partial",
|
|
2066
|
-
attributePattern: "gen_ai.completion",
|
|
2067
2025
|
patterns: DEFAULT_PII_PATTERNS
|
|
2068
2026
|
}
|
|
2069
2027
|
];
|
|
@@ -2073,24 +2031,16 @@ var BrizzSimpleSpanProcessor = class extends import_sdk_trace_base.SimpleSpanPro
|
|
|
2073
2031
|
super(spanExporter);
|
|
2074
2032
|
this.config = config;
|
|
2075
2033
|
}
|
|
2076
|
-
// Will work with the following code:
|
|
2077
|
-
// const span = tracer.startSpan('sensitive-operation',{attributes:{
|
|
2078
|
-
// 'user.password': 'secret123',
|
|
2079
|
-
// 'user.email': 'user@example.com',
|
|
2080
|
-
// }});
|
|
2081
|
-
//
|
|
2082
|
-
// Won't work because onStart is called before attributes are set:
|
|
2083
|
-
// span.setAttributes({
|
|
2084
|
-
// 'user.password': 'secret123',
|
|
2085
|
-
// 'user.email': 'user@example.com'
|
|
2086
|
-
// });
|
|
2087
2034
|
onStart(span, parentContext) {
|
|
2035
|
+
applyContextAttributes(span);
|
|
2036
|
+
super.onStart(span, parentContext);
|
|
2037
|
+
}
|
|
2038
|
+
onEnd(span) {
|
|
2088
2039
|
const maskingConfig = this.config.masking?.spanMasking;
|
|
2089
2040
|
if (maskingConfig) {
|
|
2090
|
-
|
|
2041
|
+
maskReadableSpan(span, maskingConfig);
|
|
2091
2042
|
}
|
|
2092
|
-
|
|
2093
|
-
super.onStart(span, parentContext);
|
|
2043
|
+
super.onEnd(span);
|
|
2094
2044
|
}
|
|
2095
2045
|
};
|
|
2096
2046
|
var BrizzBatchSpanProcessor = class extends import_sdk_trace_base.BatchSpanProcessor {
|
|
@@ -2100,39 +2050,39 @@ var BrizzBatchSpanProcessor = class extends import_sdk_trace_base.BatchSpanProce
|
|
|
2100
2050
|
this.config = config;
|
|
2101
2051
|
}
|
|
2102
2052
|
onStart(span, parentContext) {
|
|
2053
|
+
applyContextAttributes(span);
|
|
2054
|
+
super.onStart(span, parentContext);
|
|
2055
|
+
}
|
|
2056
|
+
onEnd(span) {
|
|
2103
2057
|
const maskingConfig = this.config.masking?.spanMasking;
|
|
2104
2058
|
if (maskingConfig) {
|
|
2105
|
-
|
|
2059
|
+
maskReadableSpan(span, maskingConfig);
|
|
2106
2060
|
}
|
|
2107
|
-
|
|
2108
|
-
super.onStart(span, parentContext);
|
|
2061
|
+
super.onEnd(span);
|
|
2109
2062
|
}
|
|
2110
2063
|
};
|
|
2111
|
-
function
|
|
2112
|
-
|
|
2113
|
-
|
|
2064
|
+
function maskReadableSpan(span, config) {
|
|
2065
|
+
const attrs = span.attributes;
|
|
2066
|
+
if (!attrs || Object.keys(attrs).length === 0) {
|
|
2067
|
+
return;
|
|
2114
2068
|
}
|
|
2115
|
-
let rules = config.rules
|
|
2069
|
+
let rules = config.rules ? [...config.rules] : [];
|
|
2116
2070
|
if (!config.disableDefaultRules) {
|
|
2117
|
-
rules = [...
|
|
2071
|
+
rules = [...rules, ...DEFAULT_MASKING_RULES];
|
|
2118
2072
|
}
|
|
2119
2073
|
try {
|
|
2120
|
-
const
|
|
2121
|
-
for (const [
|
|
2122
|
-
|
|
2123
|
-
}
|
|
2124
|
-
const
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
merged[key] = value;
|
|
2074
|
+
const input = {};
|
|
2075
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
2076
|
+
input[k] = v;
|
|
2077
|
+
}
|
|
2078
|
+
const masked = maskAttributes(input, rules);
|
|
2079
|
+
for (const [k, v] of Object.entries(masked ?? {})) {
|
|
2080
|
+
if (attrs[k] !== v) {
|
|
2081
|
+
attrs[k] = v;
|
|
2129
2082
|
}
|
|
2130
|
-
span.setAttributes(merged);
|
|
2131
2083
|
}
|
|
2132
|
-
return span;
|
|
2133
2084
|
} catch (error) {
|
|
2134
|
-
logger.error("Error masking span
|
|
2135
|
-
return span;
|
|
2085
|
+
logger.error("Error masking span", { err: error });
|
|
2136
2086
|
}
|
|
2137
2087
|
}
|
|
2138
2088
|
|
|
@@ -2245,7 +2195,7 @@ function getSpanProcessor() {
|
|
|
2245
2195
|
}
|
|
2246
2196
|
|
|
2247
2197
|
// src/internal/trace/session.ts
|
|
2248
|
-
var
|
|
2198
|
+
var import_api10 = require("@opentelemetry/api");
|
|
2249
2199
|
|
|
2250
2200
|
// src/internal/sdk.ts
|
|
2251
2201
|
var _Brizz = class __Brizz {
|
|
@@ -2578,17 +2528,19 @@ if (runtime.isESM && runtime.supportsLoaderAPI) {
|
|
|
2578
2528
|
maybeRegisterESMLoader();
|
|
2579
2529
|
}
|
|
2580
2530
|
try {
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2531
|
+
const logLevel = process.env["BRIZZ_LOG_LEVEL"] || DEFAULT_LOG_LEVEL.toString();
|
|
2532
|
+
if (process.env["BRIZZ_DSN"]) {
|
|
2533
|
+
Brizz.initialize({ logLevel, disableNodeSdk: false });
|
|
2534
|
+
} else {
|
|
2535
|
+
Brizz.initialize({
|
|
2536
|
+
apiKey: process.env["BRIZZ_API_KEY"],
|
|
2537
|
+
baseUrl: process.env["BRIZZ_BASE_URL"],
|
|
2538
|
+
appName: process.env["BRIZZ_APP_NAME"] || process.env["OTEL_SERVICE_NAME"],
|
|
2539
|
+
logLevel,
|
|
2540
|
+
disableNodeSdk: false
|
|
2541
|
+
});
|
|
2542
|
+
}
|
|
2590
2543
|
logger.info(`SDK auto-initialized for ${runtime.isESM ? "ESM" : "CJS"} runtime`);
|
|
2591
2544
|
} catch (error) {
|
|
2592
2545
|
logger.warn("Failed to auto-initialize SDK:", { error });
|
|
2593
2546
|
}
|
|
2594
|
-
//# sourceMappingURL=preload.cjs.map
|