Skip to main content

Instrument

Add observability to your AI agents using OpenTelemetry. AgentHealth captures traces, tool calls, token usage, and more.


For supported frameworks, just initialize the SDK:

from opensearch_agenthealth import AgentHealth
# Initialize - automatic instrumentation begins
agenthealth = AgentHealth(
endpoint="http://localhost:4317", # OTEL Collector
service_name="my-agent"
)
# Your agent code runs as normal - traces are captured automatically
result = my_agent.run("Analyze this error log")

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)

Full Instrumentation Guide →