@brizz/sdk 0.1.17 → 0.1.18

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/dist/index.cjs CHANGED
@@ -223,7 +223,14 @@ var exceptionLogger = (error) => {
223
223
  };
224
224
  function loadNodeAutoInstrumentations() {
225
225
  try {
226
- const nodeInstrumentations = (0, import_auto_instrumentations_node.getNodeAutoInstrumentations)();
226
+ const nodeInstrumentations = (0, import_auto_instrumentations_node.getNodeAutoInstrumentations)({
227
+ // Disabled because @traceloop/instrumentation-openai wraps the same OpenAI
228
+ // prototype with richer span attributes (gen_ai.input.messages /
229
+ // gen_ai.output.messages). Leaving both enabled lets the official one win
230
+ // and route content to log events instead of span attributes, leaving the
231
+ // Brizz backend parser with no payload to read.
232
+ "@opentelemetry/instrumentation-openai": { enabled: false }
233
+ });
227
234
  (0, import_instrumentation.registerInstrumentations)({ instrumentations: nodeInstrumentations });
228
235
  return nodeInstrumentations;
229
236
  } catch (error) {
@@ -327,6 +334,7 @@ function resolveConfig(options) {
327
334
  const resolvedConfig = {
328
335
  ...options,
329
336
  appName: process.env["BRIZZ_APP_NAME"] || options.appName || "unknown-app",
337
+ appVersion: process.env["BRIZZ_APP_VERSION"] || options.appVersion,
330
338
  baseUrl: process.env["BRIZZ_BASE_URL"] || options.baseUrl || "https://telemetry.brizz.dev",
331
339
  headers: { ...options.headers },
332
340
  apiKey: process.env["BRIZZ_API_KEY"] || options.apiKey,
@@ -497,7 +505,7 @@ var import_sdk_logs2 = require("@opentelemetry/sdk-logs");
497
505
 
498
506
  // src/internal/version.ts
499
507
  function getSDKVersion() {
500
- return "0.1.17";
508
+ return "0.1.18";
501
509
  }
502
510
 
503
511
  // src/internal/log/processors/log-processor.ts
@@ -1306,6 +1314,7 @@ var LoggingModule = class _LoggingModule {
1306
1314
  serviceName: config.appName
1307
1315
  });
1308
1316
  const resourceAttributes = {
1317
+ ...config.resourceAttributes,
1309
1318
  "service.name": config.appName,
1310
1319
  [BRIZZ_SDK_VERSION]: getSDKVersion(),
1311
1320
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
@@ -1313,6 +1322,9 @@ var LoggingModule = class _LoggingModule {
1313
1322
  if (config.environment) {
1314
1323
  resourceAttributes["deployment.environment"] = config.environment;
1315
1324
  }
1325
+ if (config.appVersion) {
1326
+ resourceAttributes["service.version"] = config.appVersion;
1327
+ }
1316
1328
  const resource = (0, import_resources.resourceFromAttributes)(resourceAttributes);
1317
1329
  logger.debug("Creating logger provider with resource");
1318
1330
  this.loggerProvider = new import_sdk_logs2.LoggerProvider({
@@ -1502,13 +1514,16 @@ function getMetricsReader() {
1502
1514
  var import_exporter_trace_otlp_proto = require("@opentelemetry/exporter-trace-otlp-proto");
1503
1515
 
1504
1516
  // src/internal/trace/exporters/span-exporter.ts
1517
+ var import_core = require("@opentelemetry/core");
1505
1518
  var import_resources2 = require("@opentelemetry/resources");
1506
1519
  var BrizzSpanExporter = class {
1507
1520
  _delegate;
1508
1521
  _brizzResource;
1522
+ _beforeSendSpan;
1509
1523
  constructor(delegate, config) {
1510
1524
  this._delegate = delegate;
1511
1525
  const resourceAttrs = {
1526
+ ...config.resourceAttributes,
1512
1527
  "service.name": config.appName,
1513
1528
  [BRIZZ_SDK_VERSION]: getSDKVersion(),
1514
1529
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
@@ -1516,15 +1531,47 @@ var BrizzSpanExporter = class {
1516
1531
  if (config.environment) {
1517
1532
  resourceAttrs["deployment.environment"] = config.environment;
1518
1533
  }
1534
+ if (config.appVersion) {
1535
+ resourceAttrs["service.version"] = config.appVersion;
1536
+ }
1519
1537
  this._brizzResource = (0, import_resources2.resourceFromAttributes)(resourceAttrs);
1538
+ this._beforeSendSpan = config.beforeSendSpan;
1520
1539
  }
1521
1540
  export(spans, resultCallback) {
1541
+ if (spans.length === 0) {
1542
+ resultCallback({ code: import_core.ExportResultCode.SUCCESS });
1543
+ return;
1544
+ }
1522
1545
  const patchedSpans = spans.map((span) => ({
1523
1546
  ...span,
1524
1547
  resource: span.resource.merge(this._brizzResource),
1525
1548
  spanContext: span.spanContext.bind(span)
1526
1549
  }));
1527
- this._delegate.export(patchedSpans, resultCallback);
1550
+ const filter = this._beforeSendSpan;
1551
+ if (!filter) {
1552
+ this._delegate.export(patchedSpans, resultCallback);
1553
+ return;
1554
+ }
1555
+ const verdicts = patchedSpans.map((span) => {
1556
+ try {
1557
+ return Promise.resolve(filter(span));
1558
+ } catch (error) {
1559
+ logger.warn("beforeSendSpan threw; span will be kept", { error });
1560
+ return Promise.resolve(true);
1561
+ }
1562
+ });
1563
+ Promise.all(verdicts).then((keep) => {
1564
+ const filtered = patchedSpans.filter((_, i) => keep[i] !== false);
1565
+ if (filtered.length === 0) {
1566
+ resultCallback({ code: import_core.ExportResultCode.SUCCESS });
1567
+ return;
1568
+ }
1569
+ this._delegate.export(filtered, resultCallback);
1570
+ return;
1571
+ }).catch((error) => {
1572
+ logger.warn("beforeSendSpan rejected; all spans will be kept", { error });
1573
+ this._delegate.export(patchedSpans, resultCallback);
1574
+ });
1528
1575
  }
1529
1576
  async shutdown() {
1530
1577
  return this._delegate.shutdown();
@@ -1991,6 +2038,7 @@ var _Brizz = class __Brizz {
1991
2038
  const registry = InstrumentationRegistry.getInstance();
1992
2039
  const manualInstrumentations = registry.getManualInstrumentations();
1993
2040
  const resourceAttributes = {
2041
+ ...resolvedConfig.resourceAttributes,
1994
2042
  "service.name": resolvedConfig.appName,
1995
2043
  [BRIZZ_SDK_VERSION]: getSDKVersion(),
1996
2044
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
@@ -1998,6 +2046,9 @@ var _Brizz = class __Brizz {
1998
2046
  if (resolvedConfig.environment) {
1999
2047
  resourceAttributes["deployment.environment"] = resolvedConfig.environment;
2000
2048
  }
2049
+ if (resolvedConfig.appVersion) {
2050
+ resourceAttributes["service.version"] = resolvedConfig.appVersion;
2051
+ }
2001
2052
  this._sdk = new import_sdk_node.NodeSDK({
2002
2053
  spanProcessors: resolvedConfig.disableSpanExporter ? [] : [getSpanProcessor()],
2003
2054
  metricReader: getMetricsReader(),