Exporters
Send AgentCost data to your existing observability stack.
OpenTelemetry
Export trace data as OpenTelemetry spans to Datadog, Jaeger, Grafana Tempo, or any OTel-compatible backend.
Installation
Setup
from agentcost.otel import install_otel_exporter
# OTLP gRPC (Jaeger, Grafana Tempo)
install_otel_exporter(endpoint="http://localhost:4317")
# OTLP HTTP (Datadog)
install_otel_exporter(
endpoint="https://trace.agent.datadoghq.com",
headers={"DD-API-KEY": "your-key"},
protocol="http",
)
What Gets Exported
Each trace becomes an OTel span with attributes:
agentcost.model— Model nameagentcost.provider— Provider nameagentcost.project— Project nameagentcost.cost— Cost in USDagentcost.input_tokens— Input token countagentcost.output_tokens— Output token countagentcost.latency_ms— Latency in millisecondsagentcost.status— success/error
Prometheus
Expose metrics for Prometheus scraping and Grafana dashboards.
Setup
The /metrics endpoint is available automatically when the server is running:
Available Metrics
| Metric | Type | Description |
|---|---|---|
agentcost_trace_total |
Counter | Total trace events |
agentcost_cost_total |
Counter | Total cost in USD |
agentcost_tokens_total |
Counter | Total tokens (input + output) |
agentcost_latency_ms |
Histogram | Request latency distribution |
agentcost_errors_total |
Counter | Total error events |
Labels: model, provider, project, status
Grafana Dashboard
Import the included Grafana dashboard:
- Open Grafana → Dashboards → Import
- Upload
examples/grafana-dashboard.json - Select your Prometheus data source