@brizz/sdk 0.1.4 → 0.1.5
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 +12 -0
- package/dist/index.cjs +24 -140
- 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 +24 -140
- package/dist/index.js.map +1 -1
- package/dist/preload.cjs +21 -139
- package/dist/preload.cjs.map +1 -1
- package/dist/preload.js +21 -139
- package/dist/preload.js.map +1 -1
- package/package.json +53 -53
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -280,6 +280,7 @@ function resolveConfig(options) {
|
|
|
280
280
|
headers: { ...options.headers },
|
|
281
281
|
apiKey: process.env["BRIZZ_API_KEY"] || options.apiKey,
|
|
282
282
|
disableBatch: process.env["BRIZZ_DISABLE_BATCH"] === "true" || !!options.disableBatch,
|
|
283
|
+
environment: process.env["BRIZZ_ENVIRONMENT"] || options.environment,
|
|
283
284
|
logLevel: resolvedLogLevel,
|
|
284
285
|
masking: resolvedMasking
|
|
285
286
|
};
|
|
@@ -976,7 +977,7 @@ function maskStringByPattern(value, pattern, mode = "full") {
|
|
|
976
977
|
logger.warn("Regex execution failed, skipping masking", error);
|
|
977
978
|
return value;
|
|
978
979
|
}
|
|
979
|
-
for (const matchInfo of matches.
|
|
980
|
+
for (const matchInfo of matches.toReversed()) {
|
|
980
981
|
let patternName = "unknown";
|
|
981
982
|
if (matchInfo.groups) {
|
|
982
983
|
for (const [groupName, groupValue] of Object.entries(matchInfo.groups)) {
|
|
@@ -1222,9 +1223,13 @@ var LoggingModule = class _LoggingModule {
|
|
|
1222
1223
|
logger.debug("Creating resource with service name", {
|
|
1223
1224
|
serviceName: config.appName
|
|
1224
1225
|
});
|
|
1225
|
-
const
|
|
1226
|
+
const resourceAttributes = {
|
|
1226
1227
|
"service.name": config.appName
|
|
1227
|
-
}
|
|
1228
|
+
};
|
|
1229
|
+
if (config.environment) {
|
|
1230
|
+
resourceAttributes["deployment.environment"] = config.environment;
|
|
1231
|
+
}
|
|
1232
|
+
const resource = resourceFromAttributes(resourceAttributes);
|
|
1228
1233
|
logger.debug("Creating logger provider with resource");
|
|
1229
1234
|
this.loggerProvider = new LoggerProvider({
|
|
1230
1235
|
resource,
|
|
@@ -1418,130 +1423,6 @@ import {
|
|
|
1418
1423
|
BatchSpanProcessor,
|
|
1419
1424
|
SimpleSpanProcessor
|
|
1420
1425
|
} from "@opentelemetry/sdk-trace-base";
|
|
1421
|
-
|
|
1422
|
-
// src/internal/trace/transformations/vercel-ai.ts
|
|
1423
|
-
import { SpanAttributes } from "@traceloop/ai-semantic-conventions";
|
|
1424
|
-
var AI_GENERATE_TEXT_DO_GENERATE = "ai.generateText.doGenerate";
|
|
1425
|
-
var AI_STREAM_TEXT_DO_STREAM = "ai.streamText.doStream";
|
|
1426
|
-
var HANDLED_SPAN_NAMES = {
|
|
1427
|
-
[AI_GENERATE_TEXT_DO_GENERATE]: "gen_ai.chat",
|
|
1428
|
-
[AI_STREAM_TEXT_DO_STREAM]: "gen_ai.chat",
|
|
1429
|
-
"ai.streamText": "ai.streamText",
|
|
1430
|
-
"ai.toolCall": (span) => {
|
|
1431
|
-
const toolName = span.attributes["ai.toolCall.name"];
|
|
1432
|
-
return `${String(toolName ?? "unknown")}.tool`;
|
|
1433
|
-
}
|
|
1434
|
-
};
|
|
1435
|
-
var AI_RESPONSE_TEXT = "ai.response.text";
|
|
1436
|
-
var AI_PROMPT_MESSAGES = "ai.prompt.messages";
|
|
1437
|
-
var AI_USAGE_PROMPT_TOKENS = "ai.usage.promptTokens";
|
|
1438
|
-
var AI_USAGE_COMPLETION_TOKENS = "ai.usage.completionTokens";
|
|
1439
|
-
var AI_MODEL_PROVIDER = "ai.model.provider";
|
|
1440
|
-
var transformAiSdkSpanName = (span) => {
|
|
1441
|
-
if (span.name in HANDLED_SPAN_NAMES) {
|
|
1442
|
-
const handler = HANDLED_SPAN_NAMES[span.name];
|
|
1443
|
-
if (typeof handler === "function") {
|
|
1444
|
-
span.name = handler(span);
|
|
1445
|
-
} else if (handler) {
|
|
1446
|
-
span.name = handler;
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
};
|
|
1450
|
-
var transformResponseText = (attributes) => {
|
|
1451
|
-
if (AI_RESPONSE_TEXT in attributes) {
|
|
1452
|
-
attributes[`${SpanAttributes.LLM_COMPLETIONS}.0.content`] = attributes[AI_RESPONSE_TEXT];
|
|
1453
|
-
attributes[`${SpanAttributes.LLM_COMPLETIONS}.0.role`] = "assistant";
|
|
1454
|
-
delete attributes[AI_RESPONSE_TEXT];
|
|
1455
|
-
}
|
|
1456
|
-
};
|
|
1457
|
-
var transformPromptMessages = (attributes) => {
|
|
1458
|
-
if (AI_PROMPT_MESSAGES in attributes) {
|
|
1459
|
-
try {
|
|
1460
|
-
const messages = JSON.parse(attributes[AI_PROMPT_MESSAGES]);
|
|
1461
|
-
for (const [index, msg] of messages.entries()) {
|
|
1462
|
-
const message = msg;
|
|
1463
|
-
logger.debug("Transforming prompt message", { msg: message, type: typeof message.content });
|
|
1464
|
-
if (typeof message.content === "string") {
|
|
1465
|
-
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.content`] = message.content;
|
|
1466
|
-
} else {
|
|
1467
|
-
if (Array.isArray(message.content) && message.content.length > 0) {
|
|
1468
|
-
const lastContent = message.content.at(-1);
|
|
1469
|
-
if (lastContent?.text) {
|
|
1470
|
-
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.content`] = lastContent.text;
|
|
1471
|
-
}
|
|
1472
|
-
} else {
|
|
1473
|
-
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.content`] = JSON.stringify(
|
|
1474
|
-
message.content
|
|
1475
|
-
);
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.role`] = message.role;
|
|
1479
|
-
}
|
|
1480
|
-
delete attributes[AI_PROMPT_MESSAGES];
|
|
1481
|
-
} catch (error) {
|
|
1482
|
-
logger.debug("Skipping prompt messages transformation because of JSON parsing error", {
|
|
1483
|
-
e: error
|
|
1484
|
-
});
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
};
|
|
1488
|
-
var transformPromptTokens = (attributes) => {
|
|
1489
|
-
if (AI_USAGE_PROMPT_TOKENS in attributes) {
|
|
1490
|
-
attributes[`${SpanAttributes.LLM_USAGE_PROMPT_TOKENS}`] = attributes[AI_USAGE_PROMPT_TOKENS];
|
|
1491
|
-
delete attributes[AI_USAGE_PROMPT_TOKENS];
|
|
1492
|
-
}
|
|
1493
|
-
};
|
|
1494
|
-
var transformCompletionTokens = (attributes) => {
|
|
1495
|
-
if (AI_USAGE_COMPLETION_TOKENS in attributes) {
|
|
1496
|
-
attributes[`${SpanAttributes.LLM_USAGE_COMPLETION_TOKENS}`] = attributes[AI_USAGE_COMPLETION_TOKENS];
|
|
1497
|
-
delete attributes[AI_USAGE_COMPLETION_TOKENS];
|
|
1498
|
-
}
|
|
1499
|
-
};
|
|
1500
|
-
var calculateTotalTokens = (attributes) => {
|
|
1501
|
-
const promptTokens = attributes[`${SpanAttributes.LLM_USAGE_PROMPT_TOKENS}`];
|
|
1502
|
-
const completionTokens = attributes[`${SpanAttributes.LLM_USAGE_COMPLETION_TOKENS}`];
|
|
1503
|
-
if (promptTokens && completionTokens) {
|
|
1504
|
-
attributes[`${SpanAttributes.LLM_USAGE_TOTAL_TOKENS}`] = Number(promptTokens) + Number(completionTokens);
|
|
1505
|
-
}
|
|
1506
|
-
};
|
|
1507
|
-
var transformVendor = (attributes) => {
|
|
1508
|
-
if (AI_MODEL_PROVIDER in attributes) {
|
|
1509
|
-
const vendor = attributes[AI_MODEL_PROVIDER];
|
|
1510
|
-
attributes[SpanAttributes.LLM_SYSTEM] = vendor && vendor.startsWith("openai") ? "OpenAI" : vendor;
|
|
1511
|
-
delete attributes[AI_MODEL_PROVIDER];
|
|
1512
|
-
}
|
|
1513
|
-
};
|
|
1514
|
-
var transformAiSdkAttributes = (attributes) => {
|
|
1515
|
-
transformResponseText(attributes);
|
|
1516
|
-
transformPromptMessages(attributes);
|
|
1517
|
-
transformPromptTokens(attributes);
|
|
1518
|
-
transformCompletionTokens(attributes);
|
|
1519
|
-
calculateTotalTokens(attributes);
|
|
1520
|
-
transformVendor(attributes);
|
|
1521
|
-
};
|
|
1522
|
-
var shouldHandleSpan = (span) => {
|
|
1523
|
-
return span.name in HANDLED_SPAN_NAMES;
|
|
1524
|
-
};
|
|
1525
|
-
var transformAiSdkSpan = (span) => {
|
|
1526
|
-
if (!shouldHandleSpan(span)) {
|
|
1527
|
-
logger.debug("Skipping span transformation", { spanName: span.name });
|
|
1528
|
-
return;
|
|
1529
|
-
}
|
|
1530
|
-
for (const key in span.attributes) {
|
|
1531
|
-
if (Number.isNaN(span.attributes[key])) {
|
|
1532
|
-
span.attributes[key] = 0;
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
logger.debug("Transforming AI SDK span", {
|
|
1536
|
-
spanName: span.name,
|
|
1537
|
-
spanContext: span.spanContext(),
|
|
1538
|
-
attributes: span.attributes
|
|
1539
|
-
});
|
|
1540
|
-
transformAiSdkSpanName(span);
|
|
1541
|
-
transformAiSdkAttributes(span.attributes);
|
|
1542
|
-
};
|
|
1543
|
-
|
|
1544
|
-
// src/internal/trace/processors/span-processor.ts
|
|
1545
1426
|
var DEFAULT_MASKING_RULES = [
|
|
1546
1427
|
{
|
|
1547
1428
|
mode: "partial",
|
|
@@ -1584,10 +1465,6 @@ var BrizzSimpleSpanProcessor = class extends SimpleSpanProcessor {
|
|
|
1584
1465
|
}
|
|
1585
1466
|
super.onStart(span, parentContext);
|
|
1586
1467
|
}
|
|
1587
|
-
onEnd(span) {
|
|
1588
|
-
transformAiSdkSpan(span);
|
|
1589
|
-
super.onEnd(span);
|
|
1590
|
-
}
|
|
1591
1468
|
};
|
|
1592
1469
|
var BrizzBatchSpanProcessor = class extends BatchSpanProcessor {
|
|
1593
1470
|
config;
|
|
@@ -1608,10 +1485,6 @@ var BrizzBatchSpanProcessor = class extends BatchSpanProcessor {
|
|
|
1608
1485
|
}
|
|
1609
1486
|
super.onStart(span, parentContext);
|
|
1610
1487
|
}
|
|
1611
|
-
onEnd(span) {
|
|
1612
|
-
transformAiSdkSpan(span);
|
|
1613
|
-
super.onEnd(span);
|
|
1614
|
-
}
|
|
1615
1488
|
};
|
|
1616
1489
|
function maskSpan(span, config) {
|
|
1617
1490
|
if (!span.attributes || Object.keys(span.attributes).length === 0) {
|
|
@@ -1755,7 +1628,10 @@ function withSessionId(sessionId, fn, thisArg) {
|
|
|
1755
1628
|
return function wrapped(...args) {
|
|
1756
1629
|
const base = context3.active();
|
|
1757
1630
|
const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
|
|
1758
|
-
const next = base.setValue(
|
|
1631
|
+
const next = base.setValue(
|
|
1632
|
+
PROPERTIES_CONTEXT_KEY,
|
|
1633
|
+
prev ? { ...prev, [SESSION_ID]: sessionId } : { [SESSION_ID]: sessionId }
|
|
1634
|
+
);
|
|
1759
1635
|
return context3.with(next, fn, thisArg ?? this, ...args);
|
|
1760
1636
|
};
|
|
1761
1637
|
}
|
|
@@ -1833,12 +1709,16 @@ var _Brizz = class __Brizz {
|
|
|
1833
1709
|
}
|
|
1834
1710
|
const registry = InstrumentationRegistry.getInstance();
|
|
1835
1711
|
const manualInstrumentations = registry.getManualInstrumentations();
|
|
1712
|
+
const resourceAttributes = {
|
|
1713
|
+
"service.name": resolvedConfig.appName
|
|
1714
|
+
};
|
|
1715
|
+
if (resolvedConfig.environment) {
|
|
1716
|
+
resourceAttributes["deployment.environment"] = resolvedConfig.environment;
|
|
1717
|
+
}
|
|
1836
1718
|
this._sdk = new NodeSDK({
|
|
1837
1719
|
spanProcessors: [getSpanProcessor()],
|
|
1838
1720
|
metricReader: getMetricsReader(),
|
|
1839
|
-
resource: resourceFromAttributes2(
|
|
1840
|
-
"service.name": resolvedConfig.appName
|
|
1841
|
-
}),
|
|
1721
|
+
resource: resourceFromAttributes2(resourceAttributes),
|
|
1842
1722
|
instrumentations: manualInstrumentations
|
|
1843
1723
|
});
|
|
1844
1724
|
this._sdk.start();
|
|
@@ -1962,7 +1842,10 @@ function detectRuntime() {
|
|
|
1962
1842
|
const isESM = noNodeJSGlobals && noModuleSystem;
|
|
1963
1843
|
const isCJS = hasRequire && typeof module !== "undefined" && typeof exports !== "undefined" && typeof __filename === "string" && typeof __dirname === "string";
|
|
1964
1844
|
const supportsLoaderAPI = (major ?? 0) >= 21 || (major ?? 0) === 20 && (minor ?? 0) >= 6 || (major ?? 0) === 18 && (minor ?? 0) >= 19;
|
|
1965
|
-
const supportsRegister =
|
|
1845
|
+
const supportsRegister = (
|
|
1846
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1847
|
+
!!process.features?.typescript || !!globalThis.module?.register
|
|
1848
|
+
);
|
|
1966
1849
|
logger.debug("Runtime detection results:", {
|
|
1967
1850
|
nodeVersion: `${major ?? 0}.${minor ?? 0}`,
|
|
1968
1851
|
isESM,
|
|
@@ -1983,6 +1866,7 @@ function detectRuntime() {
|
|
|
1983
1866
|
module: typeof module,
|
|
1984
1867
|
exports: typeof exports,
|
|
1985
1868
|
"process.features": process.features,
|
|
1869
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1986
1870
|
"globalThis.module": globalThis.module
|
|
1987
1871
|
}
|
|
1988
1872
|
});
|