@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.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>;
@@ -96,6 +99,8 @@ interface IBrizzInitializeOptions {
96
99
  customLogExporter?: LogRecordExporter;
97
100
  customMetricReader?: MetricReader;
98
101
  disableSpanExporter?: boolean;
102
+ resourceAttributes?: Record<string, AttributeValue>;
103
+ beforeSendSpan?: (span: ReadableSpan) => boolean | Promise<boolean>;
99
104
  }
100
105
  declare class _Brizz {
101
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>;
@@ -96,6 +99,8 @@ interface IBrizzInitializeOptions {
96
99
  customLogExporter?: LogRecordExporter;
97
100
  customMetricReader?: MetricReader;
98
101
  disableSpanExporter?: boolean;
102
+ resourceAttributes?: Record<string, AttributeValue>;
103
+ beforeSendSpan?: (span: ReadableSpan) => boolean | Promise<boolean>;
99
104
  }
100
105
  declare class _Brizz {
101
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,6 +281,7 @@ 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,
@@ -446,7 +454,7 @@ import {
446
454
 
447
455
  // src/internal/version.ts
448
456
  function getSDKVersion() {
449
- return "0.1.17";
457
+ return "0.1.18";
450
458
  }
451
459
 
452
460
  // src/internal/log/processors/log-processor.ts
@@ -1255,6 +1263,7 @@ var LoggingModule = class _LoggingModule {
1255
1263
  serviceName: config.appName
1256
1264
  });
1257
1265
  const resourceAttributes = {
1266
+ ...config.resourceAttributes,
1258
1267
  "service.name": config.appName,
1259
1268
  [BRIZZ_SDK_VERSION]: getSDKVersion(),
1260
1269
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
@@ -1262,6 +1271,9 @@ var LoggingModule = class _LoggingModule {
1262
1271
  if (config.environment) {
1263
1272
  resourceAttributes["deployment.environment"] = config.environment;
1264
1273
  }
1274
+ if (config.appVersion) {
1275
+ resourceAttributes["service.version"] = config.appVersion;
1276
+ }
1265
1277
  const resource = resourceFromAttributes(resourceAttributes);
1266
1278
  logger.debug("Creating logger provider with resource");
1267
1279
  this.loggerProvider = new LoggerProvider({
@@ -1451,13 +1463,16 @@ function getMetricsReader() {
1451
1463
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
1452
1464
 
1453
1465
  // src/internal/trace/exporters/span-exporter.ts
1466
+ import { ExportResultCode } from "@opentelemetry/core";
1454
1467
  import { resourceFromAttributes as resourceFromAttributes2 } from "@opentelemetry/resources";
1455
1468
  var BrizzSpanExporter = class {
1456
1469
  _delegate;
1457
1470
  _brizzResource;
1471
+ _beforeSendSpan;
1458
1472
  constructor(delegate, config) {
1459
1473
  this._delegate = delegate;
1460
1474
  const resourceAttrs = {
1475
+ ...config.resourceAttributes,
1461
1476
  "service.name": config.appName,
1462
1477
  [BRIZZ_SDK_VERSION]: getSDKVersion(),
1463
1478
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
@@ -1465,15 +1480,47 @@ var BrizzSpanExporter = class {
1465
1480
  if (config.environment) {
1466
1481
  resourceAttrs["deployment.environment"] = config.environment;
1467
1482
  }
1483
+ if (config.appVersion) {
1484
+ resourceAttrs["service.version"] = config.appVersion;
1485
+ }
1468
1486
  this._brizzResource = resourceFromAttributes2(resourceAttrs);
1487
+ this._beforeSendSpan = config.beforeSendSpan;
1469
1488
  }
1470
1489
  export(spans, resultCallback) {
1490
+ if (spans.length === 0) {
1491
+ resultCallback({ code: ExportResultCode.SUCCESS });
1492
+ return;
1493
+ }
1471
1494
  const patchedSpans = spans.map((span) => ({
1472
1495
  ...span,
1473
1496
  resource: span.resource.merge(this._brizzResource),
1474
1497
  spanContext: span.spanContext.bind(span)
1475
1498
  }));
1476
- 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
+ });
1477
1524
  }
1478
1525
  async shutdown() {
1479
1526
  return this._delegate.shutdown();
@@ -1943,6 +1990,7 @@ var _Brizz = class __Brizz {
1943
1990
  const registry = InstrumentationRegistry.getInstance();
1944
1991
  const manualInstrumentations = registry.getManualInstrumentations();
1945
1992
  const resourceAttributes = {
1993
+ ...resolvedConfig.resourceAttributes,
1946
1994
  "service.name": resolvedConfig.appName,
1947
1995
  [BRIZZ_SDK_VERSION]: getSDKVersion(),
1948
1996
  [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
@@ -1950,6 +1998,9 @@ var _Brizz = class __Brizz {
1950
1998
  if (resolvedConfig.environment) {
1951
1999
  resourceAttributes["deployment.environment"] = resolvedConfig.environment;
1952
2000
  }
2001
+ if (resolvedConfig.appVersion) {
2002
+ resourceAttributes["service.version"] = resolvedConfig.appVersion;
2003
+ }
1953
2004
  this._sdk = new NodeSDK({
1954
2005
  spanProcessors: resolvedConfig.disableSpanExporter ? [] : [getSpanProcessor()],
1955
2006
  metricReader: getMetricsReader(),