@brizz/sdk 0.1.33 → 0.1.35

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.
@@ -1,6 +1,6 @@
1
1
  // src/internal/version.ts
2
2
  function getSDKVersion() {
3
- return "0.1.33";
3
+ return "0.1.35";
4
4
  }
5
5
 
6
6
  export {
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/internal/version.ts
2
2
  function getSDKVersion() {
3
- return "0.1.33";
3
+ return "0.1.35";
4
4
  }
5
5
 
6
6
 
@@ -0,0 +1,63 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkWC573FCIcjs = require('./chunk-WC573FCI.cjs');
4
+
5
+ // src/internal/instrumentation/google-genai.ts
6
+ var _instrumentation = require('@opentelemetry/instrumentation');
7
+ var _instrumentationgooglegenerativeai = require('@traceloop/instrumentation-google-generativeai');
8
+ var MODULE_NAME = "@google/genai";
9
+ var SUPPORTED_VERSIONS = [">=1.0.0 <3.0.0"];
10
+ var GoogleGenAIInstrumentation = class extends _instrumentationgooglegenerativeai.GenAIInstrumentation {
11
+ /**
12
+ * Replace — not extend — upstream's module definition. Upstream returns a
13
+ * single definition for `@google/genai`; registering ours alongside it would
14
+ * patch the same module twice on v1.
15
+ */
16
+ init() {
17
+ return new (0, _instrumentation.InstrumentationNodeModuleDefinition)(
18
+ MODULE_NAME,
19
+ SUPPORTED_VERSIONS,
20
+ (module) => {
21
+ this.manuallyInstrument(module);
22
+ return module;
23
+ }
24
+ );
25
+ }
26
+ /**
27
+ * Brand the class we patched so de-duplication survives bundlers that minify
28
+ * upstream's runtime class name. Every patch path (module-load hook, registry
29
+ * `instrumentModules`, `instrumentGoogleGenAI`) funnels through here.
30
+ */
31
+ manuallyInstrument(module) {
32
+ const original = module.GoogleGenAI;
33
+ super.manuallyInstrument(module);
34
+ if (module.GoogleGenAI !== original) {
35
+ module.GoogleGenAI[PATCHED_MARKER] = true;
36
+ }
37
+ }
38
+ };
39
+ var PATCHED_CLASS_NAME = "PatchedGoogleGenAI";
40
+ var PATCHED_MARKER = /* @__PURE__ */ Symbol.for("brizz.googleGenAI.patched");
41
+ function instrumentGoogleGenAI(module) {
42
+ const original = module.GoogleGenAI;
43
+ const branded = original[PATCHED_MARKER] === true;
44
+ if (branded || original.name === PATCHED_CLASS_NAME) {
45
+ return original;
46
+ }
47
+ const holder = { GoogleGenAI: original };
48
+ const instrumentation = new GoogleGenAIInstrumentation({
49
+ exceptionLogger: (error) => {
50
+ _chunkWC573FCIcjs.logger.error(`Exception in Google GenAI instrumentation: ${String(error)}`);
51
+ }
52
+ });
53
+ instrumentation.manuallyInstrument(holder);
54
+ if (holder.GoogleGenAI === original) {
55
+ _chunkWC573FCIcjs.logger.warn("Google GenAI instrumentation did not patch the client; calls will not be traced");
56
+ }
57
+ return holder.GoogleGenAI;
58
+ }
59
+
60
+
61
+
62
+
63
+ exports.GoogleGenAIInstrumentation = GoogleGenAIInstrumentation; exports.instrumentGoogleGenAI = instrumentGoogleGenAI;
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-7SUF4VVI.js";
5
5
  import {
6
6
  getSDKVersion
7
- } from "./chunk-PY6FJBVY.js";
7
+ } from "./chunk-GSKXPOLQ.js";
8
8
  import {
9
9
  DEFAULT_LOG_LEVEL,
10
10
  logger,
@@ -13,7 +13,7 @@ import {
13
13
  } from "./chunk-Y4HNUX3Q.js";
14
14
  import {
15
15
  InterruptPropagator
16
- } from "./chunk-N4X2B6BC.js";
16
+ } from "./chunk-24CEDVD2.js";
17
17
  import {
18
18
  BRIZZ,
19
19
  EXTERNAL_LINK_EVENT_NAME,
@@ -29,6 +29,18 @@ import {
29
29
  FEEDBACK_TYPE,
30
30
  INTERNAL_EVENT_PREFIX,
31
31
  MESSAGE_ID,
32
+ METRIC_ATTRIBUTE_PREFIX,
33
+ METRIC_COMMENT,
34
+ METRIC_EVENT_NAME,
35
+ METRIC_MAX,
36
+ METRIC_MIN,
37
+ METRIC_NAME,
38
+ METRIC_POLARITY,
39
+ METRIC_POLARITY_NEGATIVE,
40
+ METRIC_POLARITY_POSITIVE,
41
+ METRIC_TIMESTAMP,
42
+ METRIC_UNIT,
43
+ METRIC_VALUE,
32
44
  MUTE_INPUT,
33
45
  MUTE_OUTPUT,
34
46
  ORGANIZATION_DOMAIN,
@@ -36,6 +48,7 @@ import {
36
48
  ORGANIZATION_NAME,
37
49
  ORGANIZATION_PLAN,
38
50
  PROPERTIES_CONTEXT_KEY,
51
+ RESERVED_METRIC_NAMES,
39
52
  SESSION_ID,
40
53
  SESSION_INPUT,
41
54
  SESSION_INPUT_CONTEXT,
@@ -51,7 +64,7 @@ import {
51
64
  USER_NAME,
52
65
  USER_PLAN,
53
66
  USER_ROLE
54
- } from "./chunk-GRRKMMG6.js";
67
+ } from "./chunk-QY4VADPP.js";
55
68
  import {
56
69
  __require
57
70
  } from "./chunk-3RG5ZIWI.js";
@@ -157,11 +170,26 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
157
170
  }
158
171
  })();
159
172
  }
173
+ if (this.manualModules?.google_genai) {
174
+ const genaiModule = this.manualModules.google_genai;
175
+ void (async () => {
176
+ try {
177
+ const { GoogleGenAIInstrumentation } = await import("./google-genai-T7I4FFIP.js");
178
+ const genaiInst = new GoogleGenAIInstrumentation({ exceptionLogger });
179
+ genaiInst.manuallyInstrument(genaiModule);
180
+ logger.debug("Manual instrumentation enabled for Google GenAI");
181
+ } catch (error) {
182
+ logger.error(
183
+ `Failed to apply Google GenAI instrumentation. Ensure @traceloop/instrumentation-google-generativeai is installed; on a read-only ESM module namespace use instrumentGoogleGenAI from @brizz/sdk/google-genai instead: ${String(error)}`
184
+ );
185
+ }
186
+ })();
187
+ }
160
188
  if (this.manualModules?.mcp) {
161
189
  const mcpModules = this.manualModules.mcp;
162
190
  void (async () => {
163
191
  try {
164
- const { MCPInstrumentation } = await import("./mcp-XIHWT2AU.js");
192
+ const { MCPInstrumentation } = await import("./mcp-EJNZYON6.js");
165
193
  const instrumentation = new MCPInstrumentation({ exceptionLogger });
166
194
  instrumentation.manuallyInstrument(mcpModules);
167
195
  logger.debug("Manual instrumentation enabled for MCP");
@@ -1265,24 +1293,24 @@ function addExternalLink(url, options) {
1265
1293
  emitExternalLink(sessionId, url, options?.title, options?.linkType);
1266
1294
  }
1267
1295
  function recordFeedback(type, options) {
1268
- const attributes = { [FEEDBACK_TYPE]: type };
1296
+ const eventAttributes = { [FEEDBACK_TYPE]: type };
1269
1297
  if (options?.score !== void 0) {
1270
- attributes[FEEDBACK_SCORE] = options.score;
1298
+ eventAttributes[FEEDBACK_SCORE] = options.score;
1271
1299
  }
1272
1300
  if (options?.reason !== void 0) {
1273
- attributes[FEEDBACK_REASON] = options.reason;
1301
+ eventAttributes[FEEDBACK_REASON] = options.reason;
1274
1302
  }
1275
1303
  if (options?.comment !== void 0) {
1276
- attributes[FEEDBACK_COMMENT] = options.comment;
1304
+ eventAttributes[FEEDBACK_COMMENT] = options.comment;
1277
1305
  }
1278
1306
  if (options?.source !== void 0) {
1279
- attributes[FEEDBACK_SOURCE] = options.source;
1307
+ eventAttributes[FEEDBACK_SOURCE] = options.source;
1280
1308
  }
1281
- if (options?.traits) {
1282
- for (const [key, value] of Object.entries(options.traits)) {
1309
+ if (options?.attributes) {
1310
+ for (const [key, value] of Object.entries(options.attributes)) {
1283
1311
  const k = `${FEEDBACK_ATTR_PREFIX}${key}`;
1284
- if (attributes[k] === void 0) {
1285
- attributes[k] = value;
1312
+ if (eventAttributes[k] === void 0) {
1313
+ eventAttributes[k] = value;
1286
1314
  }
1287
1315
  }
1288
1316
  }
@@ -1302,14 +1330,136 @@ function recordFeedback(type, options) {
1302
1330
  }
1303
1331
  try {
1304
1332
  if (Object.keys(anchor).length === 0) {
1305
- emitEvent(FEEDBACK_EVENT_NAME, attributes);
1333
+ emitEvent(FEEDBACK_EVENT_NAME, eventAttributes);
1306
1334
  } else {
1307
- callWithProperties(anchor, () => emitEvent(FEEDBACK_EVENT_NAME, attributes));
1335
+ callWithProperties(anchor, () => emitEvent(FEEDBACK_EVENT_NAME, eventAttributes));
1308
1336
  }
1309
1337
  } catch (error) {
1310
1338
  logger.warn("recordFeedback: failed to emit feedback event", error);
1311
1339
  }
1312
1340
  }
1341
+ var METRIC_NAME_PATTERN = /^[a-z][a-z0-9_.-]{0,63}$/;
1342
+ var METRIC_COMMENT_MAX_LEN = 4096;
1343
+ var METRIC_ATTRIBUTES_MAX = 20;
1344
+ var METRIC_ATTRIBUTE_VALUE_MAX_LEN = 256;
1345
+ function recordMetric(options) {
1346
+ try {
1347
+ recordMetricImpl(options);
1348
+ } catch (error) {
1349
+ logger.warn(`recordMetric(${JSON.stringify(options?.name)}) failed; metric dropped.`, error);
1350
+ }
1351
+ }
1352
+ function recordMetricImpl(options) {
1353
+ const name = typeof options.name === "string" ? options.name.toLowerCase() : "";
1354
+ if (!METRIC_NAME_PATTERN.test(name)) {
1355
+ logger.warn(
1356
+ `recordMetric called with an invalid name ${JSON.stringify(options.name)}; metric dropped. Names must match ${METRIC_NAME_PATTERN.source} after lowercasing.`
1357
+ );
1358
+ return;
1359
+ }
1360
+ if (RESERVED_METRIC_NAMES.has(name)) {
1361
+ logger.warn(
1362
+ `recordMetric called with the reserved name ${JSON.stringify(name)}; metric dropped. Brizz computes this metric itself \u2014 pick a different name.`
1363
+ );
1364
+ return;
1365
+ }
1366
+ const { value } = options;
1367
+ let numericValue;
1368
+ if (typeof value === "boolean") {
1369
+ numericValue = value ? 1 : 0;
1370
+ } else if (typeof value === "number" && Number.isFinite(value)) {
1371
+ numericValue = value;
1372
+ } else {
1373
+ logger.warn(
1374
+ `recordMetric(${name}) called with a non-finite or non-numeric value ${JSON.stringify(value)}; metric dropped.`
1375
+ );
1376
+ return;
1377
+ }
1378
+ const eventAttributes = {
1379
+ [METRIC_NAME]: name,
1380
+ [METRIC_VALUE]: numericValue
1381
+ };
1382
+ if (options.unit !== void 0) {
1383
+ eventAttributes[METRIC_UNIT] = options.unit;
1384
+ }
1385
+ if (options.minValue !== void 0) {
1386
+ eventAttributes[METRIC_MIN] = options.minValue;
1387
+ }
1388
+ if (options.maxValue !== void 0) {
1389
+ eventAttributes[METRIC_MAX] = options.maxValue;
1390
+ }
1391
+ if (options.comment !== void 0) {
1392
+ let comment = options.comment;
1393
+ if (comment.length > METRIC_COMMENT_MAX_LEN) {
1394
+ logger.warn(
1395
+ `recordMetric(${name}) comment exceeds ${METRIC_COMMENT_MAX_LEN} characters; truncated.`
1396
+ );
1397
+ comment = comment.slice(0, METRIC_COMMENT_MAX_LEN);
1398
+ }
1399
+ eventAttributes[METRIC_COMMENT] = comment;
1400
+ }
1401
+ if (options.polarity !== void 0) {
1402
+ const polarity = options.polarity;
1403
+ if (polarity === METRIC_POLARITY_POSITIVE || polarity === METRIC_POLARITY_NEGATIVE) {
1404
+ eventAttributes[METRIC_POLARITY] = polarity;
1405
+ } else {
1406
+ logger.warn(
1407
+ `recordMetric(${name}) called with an invalid polarity ${JSON.stringify(polarity)}; expected '${METRIC_POLARITY_POSITIVE}' or '${METRIC_POLARITY_NEGATIVE}'. Emitting the metric without it.`
1408
+ );
1409
+ }
1410
+ }
1411
+ if (options.timestamp !== void 0) {
1412
+ if (Number.isFinite(options.timestamp.getTime())) {
1413
+ eventAttributes[METRIC_TIMESTAMP] = options.timestamp.toISOString();
1414
+ } else {
1415
+ logger.warn(
1416
+ `recordMetric(${name}) called with an invalid timestamp; emitting the metric without it.`
1417
+ );
1418
+ }
1419
+ }
1420
+ if (options.attributes) {
1421
+ let accepted = 0;
1422
+ for (const [key, attrValue] of Object.entries(options.attributes)) {
1423
+ if (accepted >= METRIC_ATTRIBUTES_MAX) {
1424
+ logger.warn(
1425
+ `recordMetric(${name}) called with more than ${METRIC_ATTRIBUTES_MAX} attributes; the excess was dropped.`
1426
+ );
1427
+ break;
1428
+ }
1429
+ const normalizedKey = key.toLowerCase();
1430
+ if (!METRIC_NAME_PATTERN.test(normalizedKey)) {
1431
+ logger.warn(
1432
+ `recordMetric(${name}) called with an invalid attribute key ${JSON.stringify(key)}; that attribute was dropped. Keys must match ${METRIC_NAME_PATTERN.source} after lowercasing.`
1433
+ );
1434
+ continue;
1435
+ }
1436
+ let text = typeof attrValue === "string" ? attrValue : String(attrValue);
1437
+ if (text.length > METRIC_ATTRIBUTE_VALUE_MAX_LEN) {
1438
+ logger.warn(
1439
+ `recordMetric(${name}) attribute ${JSON.stringify(normalizedKey)} exceeds ${METRIC_ATTRIBUTE_VALUE_MAX_LEN} characters; truncated.`
1440
+ );
1441
+ text = text.slice(0, METRIC_ATTRIBUTE_VALUE_MAX_LEN);
1442
+ }
1443
+ eventAttributes[`${METRIC_ATTRIBUTE_PREFIX}${normalizedKey}`] = text;
1444
+ accepted += 1;
1445
+ }
1446
+ }
1447
+ const sessionId = options.sessionId ?? resolveSessionIdFromContext();
1448
+ if (sessionId === void 0) {
1449
+ logger.warn(
1450
+ `recordMetric(${name}) called with no resolvable session id; the metric cannot be attributed to a conversation and is dropped. Pass options.sessionId or call inside a startSession/callWithSessionId scope.`
1451
+ );
1452
+ return;
1453
+ }
1454
+ try {
1455
+ callWithProperties(
1456
+ { [SESSION_ID]: sessionId },
1457
+ () => emitEvent(METRIC_EVENT_NAME, eventAttributes)
1458
+ );
1459
+ } catch (error) {
1460
+ logger.warn("recordMetric: failed to emit metric event", error);
1461
+ }
1462
+ }
1313
1463
  function startSession(sessionId, callback, extraProperties, options) {
1314
1464
  const isTitle = options?.mode === "title";
1315
1465
  const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
@@ -2186,6 +2336,7 @@ export {
2186
2336
  getActiveSession,
2187
2337
  addExternalLink,
2188
2338
  recordFeedback,
2339
+ recordMetric,
2189
2340
  startSession,
2190
2341
  startSessionTitle,
2191
2342
  DEFAULT_PII_PATTERNS,
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkLIFLVFK6cjs = require('./chunk-LIFLVFK6.cjs');
3
+ var _chunkNEF2O7HFcjs = require('./chunk-NEF2O7HF.cjs');
4
4
 
5
5
  // src/internal/instrumentation/vercel-ai/interrupt.ts
6
6
  var _api = require('@opentelemetry/api');
@@ -78,7 +78,7 @@ function createInterruptIntegration() {
78
78
  return;
79
79
  }
80
80
  const value = JSON.stringify(names);
81
- span.setAttribute(_chunkLIFLVFK6cjs.INTERRUPT_TOOLS, value);
81
+ span.setAttribute(_chunkNEF2O7HFcjs.INTERRUPT_TOOLS, value);
82
82
  setPending(span.spanContext().spanId, value);
83
83
  };
84
84
  return {
@@ -94,7 +94,7 @@ var InterruptPropagator = class {
94
94
  const parentSpanId = _optionalChain([span, 'access', _ => _.parentSpanContext, 'optionalAccess', _2 => _2.spanId]);
95
95
  const stashed = parentSpanId && pendingByParentSpanId.get(parentSpanId);
96
96
  if (stashed) {
97
- span.setAttribute(_chunkLIFLVFK6cjs.INTERRUPT_TOOLS, stashed);
97
+ span.setAttribute(_chunkNEF2O7HFcjs.INTERRUPT_TOOLS, stashed);
98
98
  pendingByParentSpanId.delete(parentSpanId);
99
99
  return;
100
100
  }
@@ -104,7 +104,7 @@ var InterruptPropagator = class {
104
104
  const scoped = parsePromptToolNames(span.attributes["ai.prompt.tools"]);
105
105
  const names = scoped === null ? [...needsApprovalToolNames] : scoped.filter((n) => needsApprovalToolNames.has(n));
106
106
  if (names.length > 0) {
107
- span.setAttribute(_chunkLIFLVFK6cjs.INTERRUPT_TOOLS, JSON.stringify(names));
107
+ span.setAttribute(_chunkNEF2O7HFcjs.INTERRUPT_TOOLS, JSON.stringify(names));
108
108
  }
109
109
  }
110
110
  onEnd() {
@@ -38,6 +38,30 @@ var FEEDBACK_REASON = "brizz.feedback.reason";
38
38
  var FEEDBACK_COMMENT = "brizz.feedback.comment";
39
39
  var FEEDBACK_SOURCE = "brizz.feedback.source";
40
40
  var FEEDBACK_ATTR_PREFIX = "brizz.feedback.";
41
+ var METRIC_EVENT_NAME = "brizz.internal.metric";
42
+ var METRIC_NAME = "brizz.internal.metric.name";
43
+ var METRIC_VALUE = "brizz.internal.metric.value";
44
+ var METRIC_UNIT = "brizz.internal.metric.unit";
45
+ var METRIC_COMMENT = "brizz.internal.metric.comment";
46
+ var METRIC_POLARITY = "brizz.internal.metric.polarity";
47
+ var METRIC_MIN = "brizz.internal.metric.min";
48
+ var METRIC_MAX = "brizz.internal.metric.max";
49
+ var METRIC_TIMESTAMP = "brizz.internal.metric.timestamp";
50
+ var METRIC_ATTRIBUTE_PREFIX = "brizz.internal.metric.attribute.";
51
+ var RESERVED_METRIC_NAMES = /* @__PURE__ */ new Set([
52
+ "faithfulness",
53
+ "answer_relevancy",
54
+ "toxicity",
55
+ "task_completion_v2",
56
+ "prompt_alignment",
57
+ "user_frustration",
58
+ "user_satisfaction_v2",
59
+ "repetitiveness",
60
+ "session_outcome",
61
+ "response_time"
62
+ ]);
63
+ var METRIC_POLARITY_POSITIVE = "positive";
64
+ var METRIC_POLARITY_NEGATIVE = "negative";
41
65
 
42
66
 
43
67
 
@@ -77,4 +101,17 @@ var FEEDBACK_ATTR_PREFIX = "brizz.feedback.";
77
101
 
78
102
 
79
103
 
80
- exports.BRIZZ = BRIZZ; exports.SESSION_ID = SESSION_ID; exports.PROPERTIES_CONTEXT_KEY = PROPERTIES_CONTEXT_KEY; exports.SESSION_OBJECT_CONTEXT_KEY = SESSION_OBJECT_CONTEXT_KEY; exports.SESSION_INPUT = SESSION_INPUT; exports.SESSION_OUTPUT = SESSION_OUTPUT; exports.SESSION_INPUT_CONTEXT = SESSION_INPUT_CONTEXT; exports.SESSION_OUTPUT_CONTEXT = SESSION_OUTPUT_CONTEXT; exports.SESSION_SPAN_NAME = SESSION_SPAN_NAME; exports.MUTE_INPUT = MUTE_INPUT; exports.MUTE_OUTPUT = MUTE_OUTPUT; exports.USER_ID = USER_ID; exports.USER_EMAIL = USER_EMAIL; exports.USER_NAME = USER_NAME; exports.USER_ROLE = USER_ROLE; exports.USER_PLAN = USER_PLAN; exports.ORGANIZATION_ID = ORGANIZATION_ID; exports.ORGANIZATION_NAME = ORGANIZATION_NAME; exports.ORGANIZATION_PLAN = ORGANIZATION_PLAN; exports.ORGANIZATION_DOMAIN = ORGANIZATION_DOMAIN; exports.MESSAGE_ID = MESSAGE_ID; exports.SESSION_TITLE_SPAN_NAME = SESSION_TITLE_SPAN_NAME; exports.SESSION_TITLE_GENERATION = SESSION_TITLE_GENERATION; exports.SESSION_TITLE = SESSION_TITLE; exports.INTERRUPT_TOOLS = INTERRUPT_TOOLS; exports.INTERNAL_EVENT_PREFIX = INTERNAL_EVENT_PREFIX; exports.EXTERNAL_LINK_EVENT_NAME = EXTERNAL_LINK_EVENT_NAME; exports.EXTERNAL_LINK_URL = EXTERNAL_LINK_URL; exports.EXTERNAL_LINK_TITLE = EXTERNAL_LINK_TITLE; exports.EXTERNAL_LINK_TYPE = EXTERNAL_LINK_TYPE; exports.FEEDBACK_EVENT_NAME = FEEDBACK_EVENT_NAME; exports.FEEDBACK_TYPE = FEEDBACK_TYPE; exports.FEEDBACK_SCORE = FEEDBACK_SCORE; exports.FEEDBACK_REASON = FEEDBACK_REASON; exports.FEEDBACK_COMMENT = FEEDBACK_COMMENT; exports.FEEDBACK_SOURCE = FEEDBACK_SOURCE; exports.FEEDBACK_ATTR_PREFIX = FEEDBACK_ATTR_PREFIX;
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+ exports.BRIZZ = BRIZZ; exports.SESSION_ID = SESSION_ID; exports.PROPERTIES_CONTEXT_KEY = PROPERTIES_CONTEXT_KEY; exports.SESSION_OBJECT_CONTEXT_KEY = SESSION_OBJECT_CONTEXT_KEY; exports.SESSION_INPUT = SESSION_INPUT; exports.SESSION_OUTPUT = SESSION_OUTPUT; exports.SESSION_INPUT_CONTEXT = SESSION_INPUT_CONTEXT; exports.SESSION_OUTPUT_CONTEXT = SESSION_OUTPUT_CONTEXT; exports.SESSION_SPAN_NAME = SESSION_SPAN_NAME; exports.MUTE_INPUT = MUTE_INPUT; exports.MUTE_OUTPUT = MUTE_OUTPUT; exports.USER_ID = USER_ID; exports.USER_EMAIL = USER_EMAIL; exports.USER_NAME = USER_NAME; exports.USER_ROLE = USER_ROLE; exports.USER_PLAN = USER_PLAN; exports.ORGANIZATION_ID = ORGANIZATION_ID; exports.ORGANIZATION_NAME = ORGANIZATION_NAME; exports.ORGANIZATION_PLAN = ORGANIZATION_PLAN; exports.ORGANIZATION_DOMAIN = ORGANIZATION_DOMAIN; exports.MESSAGE_ID = MESSAGE_ID; exports.SESSION_TITLE_SPAN_NAME = SESSION_TITLE_SPAN_NAME; exports.SESSION_TITLE_GENERATION = SESSION_TITLE_GENERATION; exports.SESSION_TITLE = SESSION_TITLE; exports.INTERRUPT_TOOLS = INTERRUPT_TOOLS; exports.INTERNAL_EVENT_PREFIX = INTERNAL_EVENT_PREFIX; exports.EXTERNAL_LINK_EVENT_NAME = EXTERNAL_LINK_EVENT_NAME; exports.EXTERNAL_LINK_URL = EXTERNAL_LINK_URL; exports.EXTERNAL_LINK_TITLE = EXTERNAL_LINK_TITLE; exports.EXTERNAL_LINK_TYPE = EXTERNAL_LINK_TYPE; exports.FEEDBACK_EVENT_NAME = FEEDBACK_EVENT_NAME; exports.FEEDBACK_TYPE = FEEDBACK_TYPE; exports.FEEDBACK_SCORE = FEEDBACK_SCORE; exports.FEEDBACK_REASON = FEEDBACK_REASON; exports.FEEDBACK_COMMENT = FEEDBACK_COMMENT; exports.FEEDBACK_SOURCE = FEEDBACK_SOURCE; exports.FEEDBACK_ATTR_PREFIX = FEEDBACK_ATTR_PREFIX; exports.METRIC_EVENT_NAME = METRIC_EVENT_NAME; exports.METRIC_NAME = METRIC_NAME; exports.METRIC_VALUE = METRIC_VALUE; exports.METRIC_UNIT = METRIC_UNIT; exports.METRIC_COMMENT = METRIC_COMMENT; exports.METRIC_POLARITY = METRIC_POLARITY; exports.METRIC_MIN = METRIC_MIN; exports.METRIC_MAX = METRIC_MAX; exports.METRIC_TIMESTAMP = METRIC_TIMESTAMP; exports.METRIC_ATTRIBUTE_PREFIX = METRIC_ATTRIBUTE_PREFIX; exports.RESERVED_METRIC_NAMES = RESERVED_METRIC_NAMES; exports.METRIC_POLARITY_POSITIVE = METRIC_POLARITY_POSITIVE; exports.METRIC_POLARITY_NEGATIVE = METRIC_POLARITY_NEGATIVE;
@@ -38,6 +38,30 @@ var FEEDBACK_REASON = "brizz.feedback.reason";
38
38
  var FEEDBACK_COMMENT = "brizz.feedback.comment";
39
39
  var FEEDBACK_SOURCE = "brizz.feedback.source";
40
40
  var FEEDBACK_ATTR_PREFIX = "brizz.feedback.";
41
+ var METRIC_EVENT_NAME = "brizz.internal.metric";
42
+ var METRIC_NAME = "brizz.internal.metric.name";
43
+ var METRIC_VALUE = "brizz.internal.metric.value";
44
+ var METRIC_UNIT = "brizz.internal.metric.unit";
45
+ var METRIC_COMMENT = "brizz.internal.metric.comment";
46
+ var METRIC_POLARITY = "brizz.internal.metric.polarity";
47
+ var METRIC_MIN = "brizz.internal.metric.min";
48
+ var METRIC_MAX = "brizz.internal.metric.max";
49
+ var METRIC_TIMESTAMP = "brizz.internal.metric.timestamp";
50
+ var METRIC_ATTRIBUTE_PREFIX = "brizz.internal.metric.attribute.";
51
+ var RESERVED_METRIC_NAMES = /* @__PURE__ */ new Set([
52
+ "faithfulness",
53
+ "answer_relevancy",
54
+ "toxicity",
55
+ "task_completion_v2",
56
+ "prompt_alignment",
57
+ "user_frustration",
58
+ "user_satisfaction_v2",
59
+ "repetitiveness",
60
+ "session_outcome",
61
+ "response_time"
62
+ ]);
63
+ var METRIC_POLARITY_POSITIVE = "positive";
64
+ var METRIC_POLARITY_NEGATIVE = "negative";
41
65
 
42
66
  export {
43
67
  BRIZZ,
@@ -76,5 +100,18 @@ export {
76
100
  FEEDBACK_REASON,
77
101
  FEEDBACK_COMMENT,
78
102
  FEEDBACK_SOURCE,
79
- FEEDBACK_ATTR_PREFIX
103
+ FEEDBACK_ATTR_PREFIX,
104
+ METRIC_EVENT_NAME,
105
+ METRIC_NAME,
106
+ METRIC_VALUE,
107
+ METRIC_UNIT,
108
+ METRIC_COMMENT,
109
+ METRIC_POLARITY,
110
+ METRIC_MIN,
111
+ METRIC_MAX,
112
+ METRIC_TIMESTAMP,
113
+ METRIC_ATTRIBUTE_PREFIX,
114
+ RESERVED_METRIC_NAMES,
115
+ METRIC_POLARITY_POSITIVE,
116
+ METRIC_POLARITY_NEGATIVE
80
117
  };
@@ -0,0 +1,63 @@
1
+ import {
2
+ logger
3
+ } from "./chunk-Y4HNUX3Q.js";
4
+
5
+ // src/internal/instrumentation/google-genai.ts
6
+ import { InstrumentationNodeModuleDefinition } from "@opentelemetry/instrumentation";
7
+ import { GenAIInstrumentation } from "@traceloop/instrumentation-google-generativeai";
8
+ var MODULE_NAME = "@google/genai";
9
+ var SUPPORTED_VERSIONS = [">=1.0.0 <3.0.0"];
10
+ var GoogleGenAIInstrumentation = class extends GenAIInstrumentation {
11
+ /**
12
+ * Replace — not extend — upstream's module definition. Upstream returns a
13
+ * single definition for `@google/genai`; registering ours alongside it would
14
+ * patch the same module twice on v1.
15
+ */
16
+ init() {
17
+ return new InstrumentationNodeModuleDefinition(
18
+ MODULE_NAME,
19
+ SUPPORTED_VERSIONS,
20
+ (module) => {
21
+ this.manuallyInstrument(module);
22
+ return module;
23
+ }
24
+ );
25
+ }
26
+ /**
27
+ * Brand the class we patched so de-duplication survives bundlers that minify
28
+ * upstream's runtime class name. Every patch path (module-load hook, registry
29
+ * `instrumentModules`, `instrumentGoogleGenAI`) funnels through here.
30
+ */
31
+ manuallyInstrument(module) {
32
+ const original = module.GoogleGenAI;
33
+ super.manuallyInstrument(module);
34
+ if (module.GoogleGenAI !== original) {
35
+ module.GoogleGenAI[PATCHED_MARKER] = true;
36
+ }
37
+ }
38
+ };
39
+ var PATCHED_CLASS_NAME = "PatchedGoogleGenAI";
40
+ var PATCHED_MARKER = /* @__PURE__ */ Symbol.for("brizz.googleGenAI.patched");
41
+ function instrumentGoogleGenAI(module) {
42
+ const original = module.GoogleGenAI;
43
+ const branded = original[PATCHED_MARKER] === true;
44
+ if (branded || original.name === PATCHED_CLASS_NAME) {
45
+ return original;
46
+ }
47
+ const holder = { GoogleGenAI: original };
48
+ const instrumentation = new GoogleGenAIInstrumentation({
49
+ exceptionLogger: (error) => {
50
+ logger.error(`Exception in Google GenAI instrumentation: ${String(error)}`);
51
+ }
52
+ });
53
+ instrumentation.manuallyInstrument(holder);
54
+ if (holder.GoogleGenAI === original) {
55
+ logger.warn("Google GenAI instrumentation did not patch the client; calls will not be traced");
56
+ }
57
+ return holder.GoogleGenAI;
58
+ }
59
+
60
+ export {
61
+ GoogleGenAIInstrumentation,
62
+ instrumentGoogleGenAI
63
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkKFETJN5Mcjs = require('./chunk-KFETJN5M.cjs');
5
+ require('./chunk-WC573FCI.cjs');
6
+ require('./chunk-OBGZSXTJ.cjs');
7
+
8
+
9
+
10
+ exports.GoogleGenAIInstrumentation = _chunkKFETJN5Mcjs.GoogleGenAIInstrumentation; exports.instrumentGoogleGenAI = _chunkKFETJN5Mcjs.instrumentGoogleGenAI;
@@ -0,0 +1,10 @@
1
+ import {
2
+ GoogleGenAIInstrumentation,
3
+ instrumentGoogleGenAI
4
+ } from "./chunk-TEY6FAVZ.js";
5
+ import "./chunk-Y4HNUX3Q.js";
6
+ import "./chunk-3RG5ZIWI.js";
7
+ export {
8
+ GoogleGenAIInstrumentation,
9
+ instrumentGoogleGenAI
10
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkKFETJN5Mcjs = require('./chunk-KFETJN5M.cjs');
4
+ require('./chunk-WC573FCI.cjs');
5
+ require('./chunk-OBGZSXTJ.cjs');
6
+
7
+
8
+ exports.instrumentGoogleGenAI = _chunkKFETJN5Mcjs.instrumentGoogleGenAI;
@@ -0,0 +1,7 @@
1
+ import { GenAIInstrumentation } from '@traceloop/instrumentation-google-generativeai';
2
+
3
+ type GoogleGenAIModule = Parameters<GenAIInstrumentation['manuallyInstrument']>[0];
4
+ type GoogleGenAIClass = GoogleGenAIModule['GoogleGenAI'];
5
+ declare function instrumentGoogleGenAI(module: GoogleGenAIModule): GoogleGenAIClass;
6
+
7
+ export { instrumentGoogleGenAI };
@@ -0,0 +1,7 @@
1
+ import { GenAIInstrumentation } from '@traceloop/instrumentation-google-generativeai';
2
+
3
+ type GoogleGenAIModule = Parameters<GenAIInstrumentation['manuallyInstrument']>[0];
4
+ type GoogleGenAIClass = GoogleGenAIModule['GoogleGenAI'];
5
+ declare function instrumentGoogleGenAI(module: GoogleGenAIModule): GoogleGenAIClass;
6
+
7
+ export { instrumentGoogleGenAI };
@@ -0,0 +1,8 @@
1
+ import {
2
+ instrumentGoogleGenAI
3
+ } from "./chunk-TEY6FAVZ.js";
4
+ import "./chunk-Y4HNUX3Q.js";
5
+ import "./chunk-3RG5ZIWI.js";
6
+ export {
7
+ instrumentGoogleGenAI
8
+ };