@brizz/sdk 0.1.3 → 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 +84 -7
- package/dist/index.cjs +38 -144
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +35 -142
- 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
|
@@ -88,6 +88,7 @@ interface IBrizzInitializeOptions {
|
|
|
88
88
|
apiKey?: string;
|
|
89
89
|
headers?: Record<string, string>;
|
|
90
90
|
disableBatch?: boolean;
|
|
91
|
+
environment?: string;
|
|
91
92
|
masking?: boolean | IMaskingConfig;
|
|
92
93
|
logLevel?: LogLevel | string;
|
|
93
94
|
instrumentModules?: IInstrumentModules;
|
|
@@ -116,7 +117,8 @@ declare function emitEvent(name: string, attributes?: Record<string, string | nu
|
|
|
116
117
|
declare function getSpanExporter(): SpanExporter;
|
|
117
118
|
declare function getSpanProcessor(): SpanProcessor;
|
|
118
119
|
|
|
119
|
-
declare function
|
|
120
|
+
declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>): F;
|
|
121
|
+
declare function callWithSessionId<A extends unknown[], F extends (...args: A) => ReturnType<F>>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
|
|
120
122
|
|
|
121
123
|
declare function getMetricsExporter(): OTLPMetricExporter;
|
|
122
124
|
declare function getMetricsReader(): MetricReader;
|
|
@@ -134,4 +136,4 @@ declare namespace init {
|
|
|
134
136
|
export { };
|
|
135
137
|
}
|
|
136
138
|
|
|
137
|
-
export { Brizz, DEFAULT_PII_PATTERNS, type IAttributesMaskingRule, type IBrizzInitializeOptions, type IEventMaskingConfig, type IEventMaskingRule, type IInstrumentModules, type ILogMaskingConfig, type ILogger, type IMaskingConfig, type ISpanMaskingConfig, LogLevel, type MaskingMode, type RuntimeInfo,
|
|
139
|
+
export { Brizz, DEFAULT_PII_PATTERNS, type IAttributesMaskingRule, type IBrizzInitializeOptions, type IEventMaskingConfig, type IEventMaskingRule, type IInstrumentModules, type ILogMaskingConfig, type ILogger, type IMaskingConfig, type ISpanMaskingConfig, LogLevel, type MaskingMode, type RuntimeInfo, callWithSessionId, detectRuntime, emitEvent, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, withSessionId };
|
package/dist/index.d.ts
CHANGED
|
@@ -88,6 +88,7 @@ interface IBrizzInitializeOptions {
|
|
|
88
88
|
apiKey?: string;
|
|
89
89
|
headers?: Record<string, string>;
|
|
90
90
|
disableBatch?: boolean;
|
|
91
|
+
environment?: string;
|
|
91
92
|
masking?: boolean | IMaskingConfig;
|
|
92
93
|
logLevel?: LogLevel | string;
|
|
93
94
|
instrumentModules?: IInstrumentModules;
|
|
@@ -116,7 +117,8 @@ declare function emitEvent(name: string, attributes?: Record<string, string | nu
|
|
|
116
117
|
declare function getSpanExporter(): SpanExporter;
|
|
117
118
|
declare function getSpanProcessor(): SpanProcessor;
|
|
118
119
|
|
|
119
|
-
declare function
|
|
120
|
+
declare function withSessionId<F extends (this: any, ...args: any[]) => any>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>): F;
|
|
121
|
+
declare function callWithSessionId<A extends unknown[], F extends (...args: A) => ReturnType<F>>(sessionId: string, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
|
|
120
122
|
|
|
121
123
|
declare function getMetricsExporter(): OTLPMetricExporter;
|
|
122
124
|
declare function getMetricsReader(): MetricReader;
|
|
@@ -134,4 +136,4 @@ declare namespace init {
|
|
|
134
136
|
export { };
|
|
135
137
|
}
|
|
136
138
|
|
|
137
|
-
export { Brizz, DEFAULT_PII_PATTERNS, type IAttributesMaskingRule, type IBrizzInitializeOptions, type IEventMaskingConfig, type IEventMaskingRule, type IInstrumentModules, type ILogMaskingConfig, type ILogger, type IMaskingConfig, type ISpanMaskingConfig, LogLevel, type MaskingMode, type RuntimeInfo,
|
|
139
|
+
export { Brizz, DEFAULT_PII_PATTERNS, type IAttributesMaskingRule, type IBrizzInitializeOptions, type IEventMaskingConfig, type IEventMaskingRule, type IInstrumentModules, type ILogMaskingConfig, type ILogger, type IMaskingConfig, type ISpanMaskingConfig, LogLevel, type MaskingMode, type RuntimeInfo, callWithSessionId, detectRuntime, emitEvent, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, withSessionId };
|
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) {
|
|
@@ -1751,7 +1624,18 @@ function withProperties(properties, fn, thisArg, ...args) {
|
|
|
1751
1624
|
const newContext = context3.active().setValue(PROPERTIES_CONTEXT_KEY, properties);
|
|
1752
1625
|
return context3.with(newContext, fn, thisArg, ...args);
|
|
1753
1626
|
}
|
|
1754
|
-
function
|
|
1627
|
+
function withSessionId(sessionId, fn, thisArg) {
|
|
1628
|
+
return function wrapped(...args) {
|
|
1629
|
+
const base = context3.active();
|
|
1630
|
+
const prev = base.getValue(PROPERTIES_CONTEXT_KEY);
|
|
1631
|
+
const next = base.setValue(
|
|
1632
|
+
PROPERTIES_CONTEXT_KEY,
|
|
1633
|
+
prev ? { ...prev, [SESSION_ID]: sessionId } : { [SESSION_ID]: sessionId }
|
|
1634
|
+
);
|
|
1635
|
+
return context3.with(next, fn, thisArg ?? this, ...args);
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
function callWithSessionId(sessionId, fn, thisArg, ...args) {
|
|
1755
1639
|
return withProperties({ [SESSION_ID]: sessionId }, fn, thisArg, ...args);
|
|
1756
1640
|
}
|
|
1757
1641
|
|
|
@@ -1825,12 +1709,16 @@ var _Brizz = class __Brizz {
|
|
|
1825
1709
|
}
|
|
1826
1710
|
const registry = InstrumentationRegistry.getInstance();
|
|
1827
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
|
+
}
|
|
1828
1718
|
this._sdk = new NodeSDK({
|
|
1829
1719
|
spanProcessors: [getSpanProcessor()],
|
|
1830
1720
|
metricReader: getMetricsReader(),
|
|
1831
|
-
resource: resourceFromAttributes2(
|
|
1832
|
-
"service.name": resolvedConfig.appName
|
|
1833
|
-
}),
|
|
1721
|
+
resource: resourceFromAttributes2(resourceAttributes),
|
|
1834
1722
|
instrumentations: manualInstrumentations
|
|
1835
1723
|
});
|
|
1836
1724
|
this._sdk.start();
|
|
@@ -1954,7 +1842,10 @@ function detectRuntime() {
|
|
|
1954
1842
|
const isESM = noNodeJSGlobals && noModuleSystem;
|
|
1955
1843
|
const isCJS = hasRequire && typeof module !== "undefined" && typeof exports !== "undefined" && typeof __filename === "string" && typeof __dirname === "string";
|
|
1956
1844
|
const supportsLoaderAPI = (major ?? 0) >= 21 || (major ?? 0) === 20 && (minor ?? 0) >= 6 || (major ?? 0) === 18 && (minor ?? 0) >= 19;
|
|
1957
|
-
const supportsRegister =
|
|
1845
|
+
const supportsRegister = (
|
|
1846
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1847
|
+
!!process.features?.typescript || !!globalThis.module?.register
|
|
1848
|
+
);
|
|
1958
1849
|
logger.debug("Runtime detection results:", {
|
|
1959
1850
|
nodeVersion: `${major ?? 0}.${minor ?? 0}`,
|
|
1960
1851
|
isESM,
|
|
@@ -1975,6 +1866,7 @@ function detectRuntime() {
|
|
|
1975
1866
|
module: typeof module,
|
|
1976
1867
|
exports: typeof exports,
|
|
1977
1868
|
"process.features": process.features,
|
|
1869
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1978
1870
|
"globalThis.module": globalThis.module
|
|
1979
1871
|
}
|
|
1980
1872
|
});
|
|
@@ -1994,7 +1886,7 @@ export {
|
|
|
1994
1886
|
DEFAULT_PII_PATTERNS,
|
|
1995
1887
|
LogLevel,
|
|
1996
1888
|
SeverityNumber2 as SeverityNumber,
|
|
1997
|
-
|
|
1889
|
+
callWithSessionId,
|
|
1998
1890
|
detectRuntime,
|
|
1999
1891
|
emitEvent,
|
|
2000
1892
|
getLogLevel,
|
|
@@ -2006,6 +1898,7 @@ export {
|
|
|
2006
1898
|
logger,
|
|
2007
1899
|
maskAttributes,
|
|
2008
1900
|
maskValue,
|
|
2009
|
-
setLogLevel
|
|
1901
|
+
setLogLevel,
|
|
1902
|
+
withSessionId
|
|
2010
1903
|
};
|
|
2011
1904
|
//# sourceMappingURL=index.js.map
|