بنقرة واحدة
instrument-otel
// Use when instrumenting an application with OpenTelemetry for Agent Health. Provides span structure, required attributes, and config setup for routing traces.
// Use when instrumenting an application with OpenTelemetry for Agent Health. Provides span structure, required attributes, and config setup for routing traces.
| name | instrument-otel |
| description | Use when instrumenting an application with OpenTelemetry for Agent Health. Provides span structure, required attributes, and config setup for routing traces. |
Add OpenTelemetry instrumentation following GenAI semantic conventions so traces are compatible with Agent Health.
Install OTel dependencies for the project's language (Python: opentelemetry-api, opentelemetry-sdk, opentelemetry-exporter-otlp-proto-http; Node.js: @opentelemetry/api, @opentelemetry/sdk-node, @opentelemetry/exporter-trace-otlp-http)
Initialize tracer with OTLP exporter pointing to OTEL_EXPORTER_OTLP_ENDPOINT using http/protobuf protocol
Create spans in this hierarchy:
Root: invoke_agent (gen_ai.operation.name = "invoke_agent")
├── chat (gen_ai.operation.name = "chat")
├── execute_tool (gen_ai.operation.name = "execute_tool")
└── ...
Set required attributes:
Agent root span:
gen_ai.operation.name: "invoke_agent"gen_ai.agent.name: agent namegen_ai.system: provider (e.g., "aws.bedrock", "openai", "anthropic")gen_ai.request.id: unique run/session IDLLM spans:
gen_ai.operation.name: "chat"gen_ai.request.model: full model ID (e.g., "anthropic.claude-sonnet-4-20250514-v1:0")gen_ai.usage.input_tokens: integergen_ai.usage.output_tokens: integerTool spans:
gen_ai.operation.name: "execute_tool"gen_ai.tool.name: tool nameSet environment variables to emit traces:
export OTEL_TRACES_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_ENDPOINT=<YOUR_OTLP_ENDPOINT>
export OTEL_SERVICE_NAME=my-agent
Configure Agent Health to read traces from the OpenSearch domain:
Option 1: CLI (recommended)
npx @opensearch-project/agent-health setup-telemetry
This writes the observability config to agent-health.config.json automatically.
Option 2: Manual JSON config
Add to agent-health.config.json:
{
"observability": {
"endpoint": "https://search-my-domain.us-west-2.es.amazonaws.com",
"authType": "sigv4",
"awsRegion": "us-west-2",
"awsService": "es",
"tracesIndex": "otel-v1-apm-span-*"
}
}
Verify with npx @opensearch-project/agent-health doctor
span.end() (or use context manager)anthropic.claude-sonnet-4-20250514-v1:0), not short namesgen_ai.operation.name or it falls into "OTHER" categoryFull guide with code examples: docs/INSTRUMENT_WITH_OTEL.md
Create a pull request for Agent Health following all compliance requirements. Use after implementing a feature or fix. Handles SPDX headers, DCO signoff, CHANGELOG, and the PR template.
Diagnose and fix bugs in Agent Health. Use when a user reports a bug, failing test, or unexpected behavior. Follows a systematic diagnosis → fix → verify workflow.
Guided feature implementation for Agent Health. Use when a user wants to add a new capability, endpoint, CLI command, or UI component to the Agent Health project. Ensures correct architecture layer, coding conventions, test coverage, and PR readiness.
Add OpenTelemetry instrumentation to an AI agent for Agent Health observability. Use when a user wants to make their agent's traces visible in Agent Health dashboards, or when debugging why traces aren't appearing. Covers span structure, Gen AI semantic conventions, required attributes, and OTLP exporter setup.
Set up an OpenTelemetry collector or OSIS pipeline to route traces from an agent to OpenSearch for Agent Health consumption. Covers OSIS, OTel Collector, and direct export configurations.
Write tests for Agent Health following project conventions. Use when adding tests for new features, bug fixes, or improving coverage. Covers Jest setup, mocking patterns, path aliases, and coverage thresholds.