Instrument
Add observability to your AI agents using OpenTelemetry. AgentHealth captures traces, tool calls, token usage, and more.
Option A: Auto-Instrumentation
Section titled “Option A: Auto-Instrumentation”For supported frameworks, just initialize the SDK:
from opensearch_agenthealth import AgentHealth
# Initialize - automatic instrumentation beginsagenthealth = AgentHealth( endpoint="http://localhost:4317", # OTEL Collector service_name="my-agent")
# Your agent code runs as normal - traces are captured automaticallyresult = my_agent.run("Analyze this error log")Option B: Manual Instrumentation
Section titled “Option B: Manual Instrumentation”For custom agents, wrap your code with trace contexts:
from opentelemetry import trace
tracer = trace.get_tracer("my-agent")
with tracer.start_as_current_span("agent_task") as span: # Add attributes span.set_attribute("gen_ai.request.model", "claude-sonnet-4")
# Your agent logic response = llm.generate(prompt)
# Record token usage span.set_attribute("gen_ai.usage.input_tokens", response.input_tokens) span.set_attribute("gen_ai.usage.output_tokens", response.output_tokens)