@brizz/sdk 0.1.16 → 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.d.cts CHANGED
@@ -1,11 +1,13 @@
1
+ import { AttributeValue, Span } from '@opentelemetry/api';
2
+ export { AttributeValue } from '@opentelemetry/api';
1
3
  import { LogRecordExporter } from '@opentelemetry/sdk-logs';
2
4
  import { MetricReader } from '@opentelemetry/sdk-metrics';
3
- import { SpanExporter } from '@opentelemetry/sdk-trace-base';
5
+ import { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base';
6
+ export { ReadableSpan } from '@opentelemetry/sdk-trace-base';
4
7
  import { LogBody, SeverityNumber } from '@opentelemetry/api-logs';
5
8
  export { SeverityNumber } from '@opentelemetry/api-logs';
6
9
  import { SpanProcessor } from '@opentelemetry/sdk-trace-node';
7
10
  import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
8
- import { Span, AttributeValue } from '@opentelemetry/api';
9
11
 
10
12
  interface IInstrumentModules {
11
13
  openAI?: unknown;
@@ -83,6 +85,7 @@ declare function maskAttributes(attributes: Record<string, unknown>, rules: read
83
85
 
84
86
  interface IBrizzInitializeOptions {
85
87
  appName?: string;
88
+ appVersion?: string;
86
89
  baseUrl?: string;
87
90
  apiKey?: string;
88
91
  headers?: Record<string, string>;
@@ -95,6 +98,9 @@ interface IBrizzInitializeOptions {
95
98
  customSpanExporter?: SpanExporter;
96
99
  customLogExporter?: LogRecordExporter;
97
100
  customMetricReader?: MetricReader;
101
+ disableSpanExporter?: boolean;
102
+ resourceAttributes?: Record<string, AttributeValue>;
103
+ beforeSendSpan?: (span: ReadableSpan) => boolean | Promise<boolean>;
98
104
  }
99
105
  declare class _Brizz {
100
106
  private static instance;
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
+ import { AttributeValue, Span } from '@opentelemetry/api';
2
+ export { AttributeValue } from '@opentelemetry/api';
1
3
  import { LogRecordExporter } from '@opentelemetry/sdk-logs';
2
4
  import { MetricReader } from '@opentelemetry/sdk-metrics';
3
- import { SpanExporter } from '@opentelemetry/sdk-trace-base';
5
+ import { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base';
6
+ export { ReadableSpan } from '@opentelemetry/sdk-trace-base';
4
7
  import { LogBody, SeverityNumber } from '@opentelemetry/api-logs';
5
8
  export { SeverityNumber } from '@opentelemetry/api-logs';
6
9
  import { SpanProcessor } from '@opentelemetry/sdk-trace-node';
7
10
  import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
8
- import { Span, AttributeValue } from '@opentelemetry/api';
9
11
 
10
12
  interface IInstrumentModules {
11
13
  openAI?: unknown;
@@ -83,6 +85,7 @@ declare function maskAttributes(attributes: Record<string, unknown>, rules: read
83
85
 
84
86
  interface IBrizzInitializeOptions {
85
87
  appName?: string;
88
+ appVersion?: string;
86
89
  baseUrl?: string;
87
90
  apiKey?: string;
88
91
  headers?: Record<string, string>;
@@ -95,6 +98,9 @@ interface IBrizzInitializeOptions {
95
98
  customSpanExporter?: SpanExporter;
96
99
  customLogExporter?: LogRecordExporter;
97
100
  customMetricReader?: MetricReader;
101
+ disableSpanExporter?: boolean;
102
+ resourceAttributes?: Record<string, AttributeValue>;
103
+ beforeSendSpan?: (span: ReadableSpan) => boolean | Promise<boolean>;
98
104
  }
99
105
  declare class _Brizz {
100
106
  private static instance;
package/dist/index.js CHANGED
@@ -170,7 +170,14 @@ var exceptionLogger = (error) => {
170
170
  };
171
171
  function loadNodeAutoInstrumentations() {
172
172
  try {
173
- const nodeInstrumentations = getNodeAutoInstrumentations();
173
+ const nodeInstrumentations = getNodeAutoInstrumentations({
174
+ // Disabled because @traceloop/instrumentation-openai wraps the same OpenAI
175
+ // prototype with richer span attributes (gen_ai.input.messages /
176
+ // gen_ai.output.messages). Leaving both enabled lets the official one win
177
+ // and route content to log events instead of span attributes, leaving the
178
+ // Brizz backend parser with no payload to read.
179
+ "@opentelemetry/instrumentation-openai": { enabled: false }
180
+ });
174
181
  registerInstrumentations({ instrumentations: nodeInstrumentations });
175
182
  return nodeInstrumentations;
176
183
  } catch (error) {
@@ -274,10 +281,12 @@ function resolveConfig(options) {
274
281
  const resolvedConfig = {
275
282
  ...options,
276
283
  appName: process.env["BRIZZ_APP_NAME"] || options.appName || "unknown-app",
284
+ appVersion: process.env["BRIZZ_APP_VERSION"] || options.appVersion,
277
285
  baseUrl: process.env["BRIZZ_BASE_URL"] || options.baseUrl || "https://telemetry.brizz.dev",
278
286
  headers: { ...options.headers },
279
287
  apiKey: process.env["BRIZZ_API_KEY"] || options.apiKey,
280
288
  disableBatch: process.env["BRIZZ_DISABLE_BATCH"] === "true" || !!options.disableBatch,
289
+ disableSpanExporter: process.env["BRIZZ_DISABLE_SPAN_EXPORTER"] === "true" || !!options.disableSpanExporter,
281
290
  environment: process.env["BRIZZ_ENVIRONMENT"] || options.environment,
282
291
  logLevel: resolvedLogLevel,
283
292
  masking: resolvedMasking
@@ -445,7 +454,7 @@ import {
445
454
 
446
455
  // src/internal/version.ts
447
456
  function getSDKVersion() {
448
- return "0.1.16";
457
+ return "0.1.18";
449
458
  }
450
459
 
451
460
  // src/internal/log/processors/log-processor.ts
@@ -1254,6 +1263,7 @@ var LoggingModule = class _LoggingModule {
1254
1263
  serviceName: config.appName
1255
1264
  });
1256
1265
  const resourceAttributes = {
1266
+ ...config.resourceAttributes,
1257
1267
  "service.name": config.appName,
1258
1268
  [BRIZZ_SDK_VERSION]: getSDKVersion(),
1259
1269
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
@@ -1261,6 +1271,9 @@ var LoggingModule = class _LoggingModule {
1261
1271
  if (config.environment) {
1262
1272
  resourceAttributes["deployment.environment"] = config.environment;
1263
1273
  }
1274
+ if (config.appVersion) {
1275
+ resourceAttributes["service.version"] = config.appVersion;
1276
+ }
1264
1277
  const resource = resourceFromAttributes(resourceAttributes);
1265
1278
  logger.debug("Creating logger provider with resource");
1266
1279
  this.loggerProvider = new LoggerProvider({
@@ -1450,13 +1463,16 @@ function getMetricsReader() {
1450
1463
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
1451
1464
 
1452
1465
  // src/internal/trace/exporters/span-exporter.ts
1466
+ import { ExportResultCode } from "@opentelemetry/core";
1453
1467
  import { resourceFromAttributes as resourceFromAttributes2 } from "@opentelemetry/resources";
1454
1468
  var BrizzSpanExporter = class {
1455
1469
  _delegate;
1456
1470
  _brizzResource;
1471
+ _beforeSendSpan;
1457
1472
  constructor(delegate, config) {
1458
1473
  this._delegate = delegate;
1459
1474
  const resourceAttrs = {
1475
+ ...config.resourceAttributes,
1460
1476
  "service.name": config.appName,
1461
1477
  [BRIZZ_SDK_VERSION]: getSDKVersion(),
1462
1478
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
@@ -1464,15 +1480,47 @@ var BrizzSpanExporter = class {
1464
1480
  if (config.environment) {
1465
1481
  resourceAttrs["deployment.environment"] = config.environment;
1466
1482
  }
1483
+ if (config.appVersion) {
1484
+ resourceAttrs["service.version"] = config.appVersion;
1485
+ }
1467
1486
  this._brizzResource = resourceFromAttributes2(resourceAttrs);
1487
+ this._beforeSendSpan = config.beforeSendSpan;
1468
1488
  }
1469
1489
  export(spans, resultCallback) {
1490
+ if (spans.length === 0) {
1491
+ resultCallback({ code: ExportResultCode.SUCCESS });
1492
+ return;
1493
+ }
1470
1494
  const patchedSpans = spans.map((span) => ({
1471
1495
  ...span,
1472
1496
  resource: span.resource.merge(this._brizzResource),
1473
1497
  spanContext: span.spanContext.bind(span)
1474
1498
  }));
1475
- this._delegate.export(patchedSpans, resultCallback);
1499
+ const filter = this._beforeSendSpan;
1500
+ if (!filter) {
1501
+ this._delegate.export(patchedSpans, resultCallback);
1502
+ return;
1503
+ }
1504
+ const verdicts = patchedSpans.map((span) => {
1505
+ try {
1506
+ return Promise.resolve(filter(span));
1507
+ } catch (error) {
1508
+ logger.warn("beforeSendSpan threw; span will be kept", { error });
1509
+ return Promise.resolve(true);
1510
+ }
1511
+ });
1512
+ Promise.all(verdicts).then((keep) => {
1513
+ const filtered = patchedSpans.filter((_, i) => keep[i] !== false);
1514
+ if (filtered.length === 0) {
1515
+ resultCallback({ code: ExportResultCode.SUCCESS });
1516
+ return;
1517
+ }
1518
+ this._delegate.export(filtered, resultCallback);
1519
+ return;
1520
+ }).catch((error) => {
1521
+ logger.warn("beforeSendSpan rejected; all spans will be kept", { error });
1522
+ this._delegate.export(patchedSpans, resultCallback);
1523
+ });
1476
1524
  }
1477
1525
  async shutdown() {
1478
1526
  return this._delegate.shutdown();
@@ -1595,6 +1643,15 @@ var TracingModule = class _TracingModule {
1595
1643
  */
1596
1644
  setup(config) {
1597
1645
  logger.info("Setting up tracing module");
1646
+ if (config.disableSpanExporter) {
1647
+ logger.info(
1648
+ "Span exporter disabled via disableSpanExporter; skipping exporter and processor setup"
1649
+ );
1650
+ this.spanExporter = null;
1651
+ this.spanProcessor = null;
1652
+ _TracingModule.instance = this;
1653
+ return;
1654
+ }
1598
1655
  this.initSpanExporter(config);
1599
1656
  this.initSpanProcessor(config);
1600
1657
  _TracingModule.instance = this;
@@ -1933,6 +1990,7 @@ var _Brizz = class __Brizz {
1933
1990
  const registry = InstrumentationRegistry.getInstance();
1934
1991
  const manualInstrumentations = registry.getManualInstrumentations();
1935
1992
  const resourceAttributes = {
1993
+ ...resolvedConfig.resourceAttributes,
1936
1994
  "service.name": resolvedConfig.appName,
1937
1995
  [BRIZZ_SDK_VERSION]: getSDKVersion(),
1938
1996
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
@@ -1940,8 +1998,11 @@ var _Brizz = class __Brizz {
1940
1998
  if (resolvedConfig.environment) {
1941
1999
  resourceAttributes["deployment.environment"] = resolvedConfig.environment;
1942
2000
  }
2001
+ if (resolvedConfig.appVersion) {
2002
+ resourceAttributes["service.version"] = resolvedConfig.appVersion;
2003
+ }
1943
2004
  this._sdk = new NodeSDK({
1944
- spanProcessors: [getSpanProcessor()],
2005
+ spanProcessors: resolvedConfig.disableSpanExporter ? [] : [getSpanProcessor()],
1945
2006
  metricReader: getMetricsReader(),
1946
2007
  resource: resourceFromAttributes3(resourceAttributes),
1947
2008
  instrumentations: manualInstrumentations