Skip to main content

OTEL Metrics Export

Export session metrics to your existing observability platform. Styrby sends data using the OpenTelemetry OTLP/HTTP protocol, so it works with any OTLP-compatible backend. Included on Pro and Growth.

Exported Metrics

After each session, Styrby exports these 7 metrics to your configured endpoint:

MetricTypeAttributes
styrby.session.duration_msGaugeagent, model, status
styrby.tokens.inputSumagent, model
styrby.tokens.outputSumagent, model
styrby.tokens.cache_readSumagent, model
styrby.tokens.cache_writeSumagent, model
styrby.cost.usdSumagent, model
styrby.errors.countSumagent, error_source

All metrics include service.name as a resource attribute (defaults to "styrby-cli").

Configuration

There are two ways to configure OTEL export. Both produce the same result.

  1. Go to Settings in the web dashboard
  2. Scroll to the OTEL Metrics Export section
  3. Select your provider preset (Grafana Cloud, Datadog, Honeycomb, New Relic, or Custom)
  4. Paste your endpoint URL and authentication credentials
  5. Click Save
  6. Copy the generated environment variables from the preview panel
  7. Add them to your shell profile (~/.zshrc or ~/.bashrc)

Option B: Environment Variables (direct)

Set these in your shell profile or .env file:

export STYRBY_OTEL_ENABLED=true
export STYRBY_OTEL_ENDPOINT="https://your-endpoint/v1/metrics"
export STYRBY_OTEL_HEADERS='{"Authorization":"Bearer your-key"}'
export STYRBY_OTEL_SERVICE="styrby-cli"
export STYRBY_OTEL_TIMEOUT_MS="5000"

Grafana Cloud

Grafana Cloud accepts OTLP/HTTP data at a per-stack gateway endpoint. You need your stack's instance ID and an API token with the "metrics:write" scope.

Steps

  1. Sign in at grafana.com and open your stack
  2. Go to My Account → Access Policies (left sidebar under Security)
  3. Click Create access policy
  4. Give it a name like "Styrby Metrics", select the metrics:write scope, and choose your Grafana Cloud stack
  5. Click Create, then Add token
  6. Copy the token (you will not see it again)
  7. Note your Instance ID (shown at the top of the Access Policies page, or under your stack details)
  8. Create the Base64 credentials: echo -n "INSTANCE_ID:API_TOKEN" | base64
  9. Find your OTLP gateway zone from your stack URL (e.g., prod-us-east-0)

Environment Variables

export STYRBY_OTEL_ENABLED=true
export STYRBY_OTEL_ENDPOINT="https://otlp-gateway-prod-us-east-0.grafana.net/otlp/v1/metrics"
export STYRBY_OTEL_HEADERS='{"Authorization":"Basic <BASE64_INSTANCE_ID:API_TOKEN>"}'

Replace the zone (prod-us-east-0) with your stack's zone, and the Base64 string with the value from step 8.

Datadog

Datadog accepts OTLP metrics directly at their intake API. No Datadog Agent or Collector required. You need a Datadog API key.

Steps

  1. Sign in at app.datadoghq.com
  2. Go to Organization Settings → API Keys (bottom of the left sidebar)
  3. Click New Key, name it "Styrby Metrics"
  4. Copy the key value
  5. Note your Datadog site domain (e.g., datadoghq.com for US1, datadoghq.eu for EU, us3.datadoghq.com for US3, etc.)

Environment Variables

export STYRBY_OTEL_ENABLED=true
export STYRBY_OTEL_ENDPOINT="https://api.datadoghq.com/api/intake/otlp/v1/metrics"
export STYRBY_OTEL_HEADERS='{"DD-API-KEY":"<YOUR_DATADOG_API_KEY>"}'

If your Datadog account is in EU, replace api.datadoghq.com with api.datadoghq.eu. For US3, use api.us3.datadoghq.com. For US5, use api.us5.datadoghq.com.

Honeycomb

Honeycomb accepts OTLP metrics natively. You need a Honeycomb Ingest API key. Metrics appear under the dataset you specify (or default to "styrby-cli").

Steps

  1. Sign in at ui.honeycomb.io
  2. Click the gear icon in the lower-left corner to open Environment Settings
  3. Go to API Keys
  4. Click Create API Key
  5. Name it "Styrby Metrics" and check Can create datasets
  6. Copy the key (you will not see it again after this page)

Environment Variables

export STYRBY_OTEL_ENABLED=true
export STYRBY_OTEL_ENDPOINT="https://api.honeycomb.io/v1/metrics"
export STYRBY_OTEL_HEADERS='{"X-Honeycomb-Team":"<YOUR_API_KEY>"}'

For EU accounts, replace api.honeycomb.io with api.eu1.honeycomb.io. To set a custom dataset name, add "X-Honeycomb-Dataset":"your-dataset" to the headers JSON.

New Relic

New Relic accepts OTLP/HTTP at their dedicated ingest endpoint. You need your account's license key (not the REST API key or User API key).

Steps

  1. Sign in at one.newrelic.com
  2. Click your account name in the bottom-left corner
  3. Go to Administration → API Keys
  4. Find your INGEST - LICENSE key (or click Create a key with type "Ingest - License")
  5. Click the three-dot menu next to the key and select Copy key

Environment Variables

export STYRBY_OTEL_ENABLED=true
export STYRBY_OTEL_ENDPOINT="https://otlp.nr-data.net/v1/metrics"
export STYRBY_OTEL_HEADERS='{"api-key":"<YOUR_LICENSE_KEY>"}'

For EU accounts, replace otlp.nr-data.net with otlp.eu01.nr-data.net. Use the license key (starts with a long hex string), not the User or REST API key.

Custom OTLP Endpoint

Any backend that accepts OTLP/HTTP JSON at a /v1/metrics path will work. This includes self-hosted OpenTelemetry Collectors, Prometheus with the OTLP receiver, Jaeger, SigNoz, and others.

export STYRBY_OTEL_ENABLED=true
export STYRBY_OTEL_ENDPOINT="https://your-collector:4318/v1/metrics"
export STYRBY_OTEL_HEADERS='{"Authorization":"Bearer your-token"}'

Verifying the Integration

After adding the environment variables to your shell profile:

  1. Open a new terminal (or run source ~/.zshrc)
  2. Start a Styrby session: styrby
  3. Send a prompt, wait for the agent to respond, then stop the session
  4. Check your observability platform for metrics with service.name = styrby-cli

If metrics do not appear, check for warnings in the Styrby CLI output. The exporter logs connection errors but does not interrupt your session. Common issues:

  • 401 Unauthorized - Check that your API key or token is correct and has write permissions
  • Connection timeout - Verify the endpoint URL is reachable from your machine. Increase STYRBY_OTEL_TIMEOUT_MS if behind a slow proxy
  • No data in dashboard - It can take 1-2 minutes for metrics to appear. Check that you are looking at the correct service name and time range

Building a Dashboard

Once metrics are flowing, create a dashboard with panels for:

  • Daily AI spend - Sum of styrby.cost.usd grouped by day
  • Token usage by agent - styrby.tokens.input + styrby.tokens.output grouped by agent attribute
  • Session duration trend - Average of styrby.session.duration_ms over time
  • Cache hit ratio - styrby.tokens.cache_read / (styrby.tokens.input + styrby.tokens.cache_read)
  • Error rate - styrby.errors.count as a time series, alert when it spikes

Set alerts on styrby.cost.usdto get paged when daily spend exceeds your threshold. This works alongside Styrby's built-in budget alerts for defense-in-depth cost control.