Built by the creator of tx|Primitives for memory, tasks & orchestrationVisit tx docs
tx-agent-kit
Packages

Observability

OpenTelemetry bootstrap helpers for traces, metrics, and logs with configurable backend routing.

Observability (packages/observability)

The observability package provides OpenTelemetry (OTEL) bootstrap helpers that configure trace, metric, and log exporters for the entire stack. All services call startTelemetry() on startup to initialize the SDK.

Usage

import { startTelemetry, stopTelemetry } from '@tx-agent-kit/observability'

// On startup
await startTelemetry('tx-agent-kit-api')

// On shutdown
await stopTelemetry()

What Gets Exported

The SDK configures three signal types:

SignalExporterEndpoint
TracesOTLP HTTP${OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces
MetricsOTLP HTTP (periodic, 5s interval)${OTEL_EXPORTER_OTLP_ENDPOINT}/v1/metrics
LogsOTLP HTTP (batched)${OTEL_EXPORTER_OTLP_ENDPOINT}/v1/logs

Log exporting can be disabled by setting OTEL_LOGS_EXPORTER=none.

Backend Routing

The OTEL collector routes telemetry to different backends based on OTEL_COLLECTOR_BACKEND:

BackendTracesMetricsLogs
gcpCloud TraceCloud MonitoringCloud Logging
oss (default)JaegerPrometheusLoki

Environment Configuration

Configuration is centralized in packages/observability/src/env.ts:

VariableDescription
OTEL_EXPORTER_OTLP_ENDPOINTOTLP collector endpoint
OTEL_COLLECTOR_BACKENDgcp or oss
OTEL_LOG_LEVELSet to debug for diagnostic output
OTEL_LOGS_EXPORTERSet to none to disable log export
NODE_ENVAttached as deployment environment attribute

Smoke Testing

The package exports a smoke test helper for verifying the telemetry pipeline:

import { emitNodeTelemetrySmoke } from '@tx-agent-kit/observability'

// Emits a test span and increments the startup counter
emitNodeTelemetrySmoke('tx-agent-kit-api')

Integration Testing

The stack integration suite at packages/observability/src/stack.integration.test.ts validates end-to-end telemetry flow across all four services (api, worker, web, mobile). It checks:

SignalValidation
TracesData appears in Jaeger
MetricsData appears in Prometheus
CountersService-specific counters and queries resolve correctly

On this page