Package com.tnsai.quality.observability
package com.tnsai.quality.observability
Observability and telemetry integration using OpenTelemetry.
This package provides instrumentation for monitoring agent behavior, performance, and debugging through distributed tracing and metrics.
OpenTelemetry Integration
┌─────────────────────────────────────────────────────────────┐ │ Observability Stack │ ├─────────────────────────────────────────────────────────────┤ │ │ │ Agent ──► Tracer ──► Spans ──► OTLP Exporter │ │ │ │ │ ▼ │ │ ┌─────────────────┐ │ │ │ Jaeger/Zipkin │ │ │ │ Grafana/etc. │ │ │ └─────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────┘
Traced Operations
| Operation | Span Name | Attributes |
|---|---|---|
| Agent run | agent.run | agent.name, input.length |
| LLM call | llm.chat | model, tokens.input, tokens.output |
| Tool call | tool.execute | tool.name, duration |
| Memory ops | memory.save/load | message.count |
Usage Example
// Enable observability (auto-configured via OpenTelemetry SDK)
// Set environment variables:
// OTEL_SERVICE_NAME=my-agent-app
// OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
// Traces are automatically created for:
Agent agent = new MyAgent(principal, scope); // passes a wired ActionExecutor, see com.tnsai.agents
String response = agent.run("Hello"); // Creates agent.run span
// Custom spans
Tracer tracer = GlobalOpenTelemetry.getTracer("my-component");
Span span = tracer.spanBuilder("custom-operation").startSpan();
try (Scope scope = span.makeCurrent()) {
// Your code here
} finally {
span.end();
}
Semantic Conventions
Follows OpenTelemetry semantic conventions for:
- General AI/ML spans
- HTTP client spans (for LLM API calls)
- Database spans (for memory operations)
Configuration
Specure via environment variables or programmatically:
OTEL_SERVICE_NAME: Service identifierOTEL_EXPORTER_OTLP_ENDPOINT: Collector endpointOTEL_TRACES_SAMPLER: Sampling strategy
- See Also:
-
ClassDescriptionOpenTelemetry instrumentation for TnsAI agents.Structured logger for agent operations with automatic trace context propagation.Bounds the number of distinct values a Prometheus label can take.Builder.OpenTelemetry instrumentation for LLM calls following semantic conventions.Builder for creating LLM spans with full configuration.Simple metrics collection for agent operations.Bridge between TnsAI's Metrics and OpenTelemetry metrics.Bridge between TnsAI's TraceContext and OpenTelemetry tracing.A scope wrapper for OpenTelemetry spans that implements AutoCloseable.Prometheus metrics exporter for TnsAI.Builder for PrometheusMetricsExporter.Canonical span-name and metric-name builder for TnsAI OpenTelemetry data.Central configuration for OpenTelemetry in TnsAI framework.Builder for TnsAITelemetry configuration.Distributed tracing context for tracking operations across agents.Span status values.