@brizz/sdk 0.1.10 → 0.1.12

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
@@ -62,7 +62,6 @@ var import_instrumentation_anthropic = require("@traceloop/instrumentation-anthr
62
62
  var import_instrumentation_bedrock = require("@traceloop/instrumentation-bedrock");
63
63
  var import_instrumentation_chromadb = require("@traceloop/instrumentation-chromadb");
64
64
  var import_instrumentation_cohere = require("@traceloop/instrumentation-cohere");
65
- var import_instrumentation_langchain = require("@traceloop/instrumentation-langchain");
66
65
  var import_instrumentation_llamaindex = require("@traceloop/instrumentation-llamaindex");
67
66
  var import_instrumentation_openai = require("@traceloop/instrumentation-openai");
68
67
  var import_instrumentation_pinecone = require("@traceloop/instrumentation-pinecone");
@@ -238,7 +237,6 @@ function loadGenAIInstrumentations() {
238
237
  { class: import_instrumentation_vertexai.VertexAIInstrumentation, name: "Vertex AI" },
239
238
  { class: import_instrumentation_bedrock.BedrockInstrumentation, name: "Bedrock" },
240
239
  { class: import_instrumentation_pinecone.PineconeInstrumentation, name: "Pinecone" },
241
- { class: import_instrumentation_langchain.LangChainInstrumentation, name: "LangChain" },
242
240
  { class: import_instrumentation_llamaindex.LlamaIndexInstrumentation, name: "LlamaIndex" },
243
241
  { class: import_instrumentation_chromadb.ChromaDBInstrumentation, name: "ChromaDB" },
244
242
  { class: import_instrumentation_qdrant.QdrantInstrumentation, name: "Qdrant" },
@@ -280,7 +278,7 @@ function autoInitializeInstrumentations() {
280
278
  autoInitializeInstrumentations();
281
279
 
282
280
  // src/internal/sdk.ts
283
- var import_resources2 = require("@opentelemetry/resources");
281
+ var import_resources3 = require("@opentelemetry/resources");
284
282
  var import_sdk_node = require("@opentelemetry/sdk-node");
285
283
 
286
284
  // src/internal/config.ts
@@ -346,7 +344,7 @@ function resolveConfig(options) {
346
344
  });
347
345
  } catch (error) {
348
346
  logger.error("Failed to parse BRIZZ_HEADERS environment variable", { error });
349
- throw new Error("Invalid JSON in BRIZZ_HEADERS environment variable");
347
+ throw new Error("Invalid JSON in BRIZZ_HEADERS environment variable", { cause: error });
350
348
  }
351
349
  }
352
350
  logger.debug("Configuration resolved with environment variables", {
@@ -370,11 +368,11 @@ var BRIZZ_SDK_LANGUAGE = "brizz.sdk.language";
370
368
  var SDK_LANGUAGE = "typescript";
371
369
 
372
370
  // src/internal/instrumentation/registry.ts
371
+ var import_openinference_instrumentation_langchain = require("@arizeai/openinference-instrumentation-langchain");
373
372
  var import_instrumentation_anthropic2 = require("@traceloop/instrumentation-anthropic");
374
373
  var import_instrumentation_bedrock2 = require("@traceloop/instrumentation-bedrock");
375
374
  var import_instrumentation_chromadb2 = require("@traceloop/instrumentation-chromadb");
376
375
  var import_instrumentation_cohere2 = require("@traceloop/instrumentation-cohere");
377
- var import_instrumentation_langchain2 = require("@traceloop/instrumentation-langchain");
378
376
  var import_instrumentation_llamaindex2 = require("@traceloop/instrumentation-llamaindex");
379
377
  var import_instrumentation_openai2 = require("@traceloop/instrumentation-openai");
380
378
  var import_instrumentation_pinecone2 = require("@traceloop/instrumentation-pinecone");
@@ -448,7 +446,6 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
448
446
  },
449
447
  { class: import_instrumentation_bedrock2.BedrockInstrumentation, name: "Bedrock", module: this.manualModules?.bedrock },
450
448
  { class: import_instrumentation_pinecone2.PineconeInstrumentation, name: "Pinecone", module: this.manualModules?.pinecone },
451
- { class: import_instrumentation_langchain2.LangChainInstrumentation, name: "LangChain", module: this.manualModules?.langchain },
452
449
  {
453
450
  class: import_instrumentation_llamaindex2.LlamaIndexInstrumentation,
454
451
  name: "LlamaIndex",
@@ -471,9 +468,65 @@ var InstrumentationRegistry = class _InstrumentationRegistry {
471
468
  }
472
469
  }
473
470
  }
471
+ if (this.manualModules?.langchain?.callbackManagerModule) {
472
+ try {
473
+ const lcInst = new import_openinference_instrumentation_langchain.LangChainInstrumentation();
474
+ lcInst.manuallyInstrument(this.manualModules.langchain.callbackManagerModule);
475
+ instrumentations.push(lcInst);
476
+ logger.debug("Manual instrumentation enabled for LangChain");
477
+ } catch (error) {
478
+ logger.error(`Failed to load LangChain instrumentation: ${String(error)}`);
479
+ }
480
+ }
474
481
  }
475
482
  };
476
483
 
484
+ // src/internal/instrumentation/langchain-instrumentation.ts
485
+ var import_node_module = require("module");
486
+ var import_node_url = require("url");
487
+ var import_openinference_instrumentation_langchain2 = require("@arizeai/openinference-instrumentation-langchain");
488
+ var initialized = false;
489
+ async function importCallbackManager() {
490
+ try {
491
+ return await import("@langchain/core/callbacks/manager");
492
+ } catch {
493
+ }
494
+ const resolvers = [
495
+ () => (0, import_node_module.createRequire)((0, import_node_url.pathToFileURL)(process.cwd() + "/package.json").href),
496
+ () => {
497
+ const main = process.argv[1];
498
+ if (!main) {
499
+ throw new Error("no main");
500
+ }
501
+ return (0, import_node_module.createRequire)((0, import_node_url.pathToFileURL)(main).href);
502
+ }
503
+ ];
504
+ for (const getRequire of resolvers) {
505
+ try {
506
+ const req = getRequire();
507
+ const cjsPath = req.resolve("@langchain/core/callbacks/manager");
508
+ const esmPath = cjsPath.replace(/\.cjs$/, ".js");
509
+ return await import((0, import_node_url.pathToFileURL)(esmPath).href);
510
+ } catch {
511
+ }
512
+ }
513
+ return null;
514
+ }
515
+ async function setupLangChainInstrumentation() {
516
+ if (initialized) {
517
+ return;
518
+ }
519
+ const callbackManagerModule = await importCallbackManager();
520
+ if (!callbackManagerModule) {
521
+ logger.debug("@langchain/core not found \u2014 skipping LangChain instrumentation");
522
+ return;
523
+ }
524
+ const instrumentation = new import_openinference_instrumentation_langchain2.LangChainInstrumentation();
525
+ instrumentation.manuallyInstrument(callbackManagerModule);
526
+ initialized = true;
527
+ logger.info("LangChain instrumentation enabled (OpenInference)");
528
+ }
529
+
477
530
  // src/internal/log/logging.ts
478
531
  var import_api_logs = require("@opentelemetry/api-logs");
479
532
  var import_exporter_logs_otlp_http = require("@opentelemetry/exporter-logs-otlp-http");
@@ -482,7 +535,7 @@ var import_sdk_logs2 = require("@opentelemetry/sdk-logs");
482
535
 
483
536
  // src/internal/version.ts
484
537
  function getSDKVersion() {
485
- return "0.1.10";
538
+ return "0.1.12";
486
539
  }
487
540
 
488
541
  // src/internal/log/processors/log-processor.ts
@@ -928,7 +981,9 @@ function getGroupedPattern(patternEntry) {
928
981
  try {
929
982
  new RegExp(patternEntry.pattern);
930
983
  } catch (error) {
931
- throw new Error(`Invalid regex pattern '${patternEntry.pattern}': ${String(error)}`);
984
+ throw new Error(`Invalid regex pattern '${patternEntry.pattern}': ${String(error)}`, {
985
+ cause: error
986
+ });
932
987
  }
933
988
  return `(?<${name}>${patternEntry.pattern})`;
934
989
  }
@@ -1480,6 +1535,39 @@ function getMetricsReader() {
1480
1535
  // src/internal/trace/tracing.ts
1481
1536
  var import_exporter_trace_otlp_proto = require("@opentelemetry/exporter-trace-otlp-proto");
1482
1537
 
1538
+ // src/internal/trace/exporters/span-exporter.ts
1539
+ var import_resources2 = require("@opentelemetry/resources");
1540
+ var BrizzSpanExporter = class {
1541
+ _delegate;
1542
+ _brizzResource;
1543
+ constructor(delegate, config) {
1544
+ this._delegate = delegate;
1545
+ const resourceAttrs = {
1546
+ "service.name": config.appName,
1547
+ [BRIZZ_SDK_VERSION]: getSDKVersion(),
1548
+ [BRIZZ_SDK_LANGUAGE]: SDK_LANGUAGE
1549
+ };
1550
+ if (config.environment) {
1551
+ resourceAttrs["deployment.environment"] = config.environment;
1552
+ }
1553
+ this._brizzResource = (0, import_resources2.resourceFromAttributes)(resourceAttrs);
1554
+ }
1555
+ export(spans, resultCallback) {
1556
+ const patchedSpans = spans.map((span) => ({
1557
+ ...span,
1558
+ resource: span.resource.merge(this._brizzResource),
1559
+ spanContext: span.spanContext.bind(span)
1560
+ }));
1561
+ this._delegate.export(patchedSpans, resultCallback);
1562
+ }
1563
+ async shutdown() {
1564
+ return this._delegate.shutdown();
1565
+ }
1566
+ async forceFlush() {
1567
+ return this._delegate.forceFlush?.();
1568
+ }
1569
+ };
1570
+
1483
1571
  // src/internal/trace/processors/span-processor.ts
1484
1572
  var import_api4 = require("@opentelemetry/api");
1485
1573
  var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
@@ -1605,16 +1693,17 @@ var TracingModule = class _TracingModule {
1605
1693
  }
1606
1694
  if (config.customSpanExporter) {
1607
1695
  logger.debug("Using custom span exporter");
1608
- this.spanExporter = config.customSpanExporter;
1696
+ this.spanExporter = new BrizzSpanExporter(config.customSpanExporter, config);
1609
1697
  logger.debug("Custom span exporter initialized successfully");
1610
1698
  return;
1611
1699
  }
1612
1700
  const tracesUrl = config.baseUrl.replace(/\/$/, "") + "/v1/traces";
1613
1701
  logger.debug("Initializing default OTLP span exporter", { url: tracesUrl });
1614
- this.spanExporter = new import_exporter_trace_otlp_proto.OTLPTraceExporter({
1702
+ const otlpExporter = new import_exporter_trace_otlp_proto.OTLPTraceExporter({
1615
1703
  url: tracesUrl,
1616
1704
  headers: config.headers
1617
1705
  });
1706
+ this.spanExporter = new BrizzSpanExporter(otlpExporter, config);
1618
1707
  logger.debug("OTLP span exporter initialized successfully");
1619
1708
  }
1620
1709
  /**
@@ -1824,6 +1913,7 @@ var _Brizz = class __Brizz {
1824
1913
  const resolvedConfig = resolveConfig(options);
1825
1914
  this.initializeModules(resolvedConfig);
1826
1915
  this.setupInstrumentation(options);
1916
+ this.initLangChainInstrumentation();
1827
1917
  this.createAndStartNodeSDK(options, resolvedConfig);
1828
1918
  this._initialized = true;
1829
1919
  logger.info("Brizz SDK initialization completed successfully", {
@@ -1831,9 +1921,18 @@ var _Brizz = class __Brizz {
1831
1921
  });
1832
1922
  } catch (error) {
1833
1923
  logger.error("Failed to initialize Brizz SDK", { error });
1834
- throw new Error(`Failed to initialize SDK: ${String(error)}`);
1924
+ throw new Error(`Failed to initialize SDK: ${String(error)}`, { cause: error });
1835
1925
  }
1836
1926
  }
1927
+ /**
1928
+ * Async LangChain instrumentation setup (fire-and-forget).
1929
+ * @private
1930
+ */
1931
+ initLangChainInstrumentation() {
1932
+ setupLangChainInstrumentation().catch((error) => {
1933
+ logger.debug(`LangChain instrumentation skipped: ${String(error)}`);
1934
+ });
1935
+ }
1837
1936
  /**
1838
1937
  * Set up instrumentation registry and configure manual modules.
1839
1938
  * @private
@@ -1867,7 +1966,7 @@ var _Brizz = class __Brizz {
1867
1966
  this._sdk = new import_sdk_node.NodeSDK({
1868
1967
  spanProcessors: [getSpanProcessor()],
1869
1968
  metricReader: getMetricsReader(),
1870
- resource: (0, import_resources2.resourceFromAttributes)(resourceAttributes),
1969
+ resource: (0, import_resources3.resourceFromAttributes)(resourceAttributes),
1871
1970
  instrumentations: manualInstrumentations
1872
1971
  });
1873
1972
  this._sdk.start();