@cloudbase/agent-observability 0.0.16 → 0.0.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/server.js CHANGED
@@ -1348,15 +1348,133 @@ var init_esm4 = __esm({
1348
1348
  var server_exports = {};
1349
1349
  __export(server_exports, {
1350
1350
  ExporterType: () => ExporterType,
1351
+ SingleLineConsoleSpanExporter: () => SingleLineConsoleSpanExporter,
1352
+ isSingleLineConsoleExporterEnabled: () => isSingleLineConsoleExporterEnabled,
1351
1353
  setupObservability: () => setupObservability
1352
1354
  });
1353
1355
  module.exports = __toCommonJS(server_exports);
1354
1356
 
1357
+ // src/core/constants.ts
1358
+ var import_openinference_semantic_conventions = require("@arizeai/openinference-semantic-conventions");
1359
+ var OBSERVABILITY_TRACER_NAME = "agui-tracer";
1360
+ var OtelSpanAttributes = {
1361
+ // OpenInference - re-export all standard conventions
1362
+ ...import_openinference_semantic_conventions.SemanticConventions,
1363
+ // Trace attributes (non-standard)
1364
+ TRACE_NAME: "trace.name",
1365
+ TRACE_TAGS: "trace.tags",
1366
+ TRACE_PUBLIC: "trace.public",
1367
+ TRACE_METADATA: "trace.metadata",
1368
+ TRACE_INPUT: "trace.input",
1369
+ TRACE_OUTPUT: "trace.output",
1370
+ // Observation attributes (non-standard)
1371
+ OBSERVATION_TYPE: "observation.type",
1372
+ OBSERVATION_LEVEL: "observation.level",
1373
+ OBSERVATION_STATUS_MESSAGE: "observation.status_message",
1374
+ OBSERVATION_INPUT: "observation.input",
1375
+ OBSERVATION_OUTPUT: "observation.output",
1376
+ OBSERVATION_METADATA: "observation.metadata",
1377
+ // LLM-specific (non-standard)
1378
+ LLM_COMPLETION_START_TIME: "llm.completion_start_time",
1379
+ LLM_MODEL_PARAMETERS: "llm.model_parameters",
1380
+ LLM_USAGE_DETAILS: "llm.usage_details",
1381
+ LLM_COST_DETAILS: "llm.cost_details",
1382
+ // Retriever-specific (non-standard)
1383
+ RETRIEVER_NAME: "retriever.name",
1384
+ RETRIEVER_QUERY: "retriever.query",
1385
+ RETRIEVER_INDEX_ID: "retriever.index_id",
1386
+ RETRIEVER_TOP_K: "retriever.top_k",
1387
+ // General (non-standard)
1388
+ ENVIRONMENT: "environment",
1389
+ RELEASE: "release",
1390
+ VERSION: "version"
1391
+ };
1392
+
1393
+ // src/server/SingleLineConsoleSpanExporter.ts
1394
+ var SingleLineConsoleSpanExporter = class {
1395
+ /**
1396
+ * Export spans as single-line JSON.
1397
+ */
1398
+ export(spans, resultCallback) {
1399
+ try {
1400
+ for (const span of spans) {
1401
+ const spanDict = this.spanToDict(span);
1402
+ const jsonLine = JSON.stringify(spanDict);
1403
+ console.log(jsonLine);
1404
+ }
1405
+ resultCallback({ code: 0 /* SUCCESS */ });
1406
+ } catch (error) {
1407
+ resultCallback({ code: 1 /* FAILED */, error });
1408
+ }
1409
+ }
1410
+ /**
1411
+ * Shutdown the exporter.
1412
+ */
1413
+ shutdown() {
1414
+ return Promise.resolve();
1415
+ }
1416
+ /**
1417
+ * Force flush the exporter.
1418
+ */
1419
+ forceFlush() {
1420
+ return Promise.resolve();
1421
+ }
1422
+ /**
1423
+ * Convert a ReadableSpan to a dictionary for JSON serialization.
1424
+ */
1425
+ spanToDict(span) {
1426
+ try {
1427
+ const context = span.spanContext();
1428
+ const parentId = span.parentSpanId || span.parentSpanContext?.spanId;
1429
+ const result = {
1430
+ name: span.name,
1431
+ context: {
1432
+ trace_id: context.traceId,
1433
+ span_id: context.spanId,
1434
+ trace_flags: context.traceFlags
1435
+ },
1436
+ kind: span.kind,
1437
+ parent_id: parentId,
1438
+ start_time: span.startTime,
1439
+ end_time: span.endTime,
1440
+ status: {
1441
+ status_code: span.status.code,
1442
+ description: span.status.message
1443
+ },
1444
+ attributes: span.attributes,
1445
+ events: span.events.map((event) => ({
1446
+ name: event.name,
1447
+ timestamp: event.time,
1448
+ attributes: event.attributes
1449
+ })),
1450
+ links: span.links.map((link) => ({
1451
+ context: {
1452
+ trace_id: link.context.traceId,
1453
+ span_id: link.context.spanId
1454
+ },
1455
+ attributes: link.attributes
1456
+ })),
1457
+ resource: {
1458
+ attributes: span.resource.attributes
1459
+ }
1460
+ };
1461
+ result["_log_from"] = OBSERVABILITY_TRACER_NAME;
1462
+ return result;
1463
+ } catch {
1464
+ return {};
1465
+ }
1466
+ }
1467
+ };
1468
+ function isSingleLineConsoleExporterEnabled() {
1469
+ const value = process.env.CONSOLE_EXPORTER_SINGLE_LINE?.toLowerCase() || "true";
1470
+ return ["true", "1", "yes", "on"].includes(value);
1471
+ }
1472
+
1355
1473
  // src/server/setup.ts
1356
1474
  var TRUTHY_ENV_VALUES = /* @__PURE__ */ new Set(["true", "1", "yes", "on"]);
1357
1475
  var DEFAULT_BATCH_CONFIG = {
1358
1476
  maxExportBatchSize: 100,
1359
- scheduledDelayMillis: 5e3,
1477
+ scheduledDelayMillis: 1e3,
1360
1478
  maxQueueSize: 2048,
1361
1479
  exportTimeoutMillis: 3e4
1362
1480
  };
@@ -1404,33 +1522,29 @@ async function setupConsoleExporter(config) {
1404
1522
  const { trace } = await import("@opentelemetry/api");
1405
1523
  const { resourceFromAttributes } = await import("@opentelemetry/resources");
1406
1524
  const { NodeTracerProvider } = await import("@opentelemetry/sdk-trace-node");
1407
- const { ConsoleSpanExporter, BatchSpanProcessor } = await import("@opentelemetry/sdk-trace-base");
1408
- const batchConfig = resolveBatchConfig(config.batch);
1525
+ const { ConsoleSpanExporter, SimpleSpanProcessor } = await import("@opentelemetry/sdk-trace-base");
1526
+ const useSingleLine = isSingleLineConsoleExporterEnabled();
1527
+ const exporter = useSingleLine ? new SingleLineConsoleSpanExporter() : new ConsoleSpanExporter();
1528
+ const exporterType = useSingleLine ? "single-line" : "multi-line";
1409
1529
  let provider = trace.getTracerProvider();
1410
1530
  const isRealProvider = "addSpanProcessor" in provider;
1531
+ const processor = new SimpleSpanProcessor(exporter);
1411
1532
  if (isRealProvider) {
1412
- const exporter = new ConsoleSpanExporter();
1413
- const processor = new BatchSpanProcessor(exporter, batchConfig);
1414
1533
  provider.addSpanProcessor(processor);
1415
- console.info(
1416
- `[Observability] Console exporter configured (batch=${batchConfig.maxExportBatchSize}, delay=${batchConfig.scheduledDelayMillis}ms)`
1417
- );
1418
1534
  } else {
1419
1535
  const resource = resourceFromAttributes({
1420
1536
  "service.name": process.env.OTEL_SERVICE_NAME || "ag-ui-server",
1421
1537
  "service.version": "1.0.0"
1422
1538
  });
1423
- const exporter = new ConsoleSpanExporter();
1424
- const processor = new BatchSpanProcessor(exporter, batchConfig);
1425
1539
  const tracerProvider = new NodeTracerProvider({
1426
1540
  resource,
1427
1541
  spanProcessors: [processor]
1428
1542
  });
1429
1543
  tracerProvider.register();
1430
- console.info(
1431
- `[Observability] Console exporter configured (batch=${batchConfig.maxExportBatchSize}, delay=${batchConfig.scheduledDelayMillis}ms)`
1432
- );
1433
1544
  }
1545
+ console.info(
1546
+ `[Observability] Console exporter configured (${exporterType}, simple processor)`
1547
+ );
1434
1548
  }
1435
1549
  async function setupOTLPExporter(config) {
1436
1550
  const { trace } = await import("@opentelemetry/api");
@@ -1525,6 +1639,8 @@ var ExporterType = {
1525
1639
  // Annotate the CommonJS export names for ESM import in node:
1526
1640
  0 && (module.exports = {
1527
1641
  ExporterType,
1642
+ SingleLineConsoleSpanExporter,
1643
+ isSingleLineConsoleExporterEnabled,
1528
1644
  setupObservability
1529
1645
  });
1530
1646
  //# sourceMappingURL=server.js.map