# OpenTelemetry export

1. **invoke_agent openprogram** one turn: tokens, cost, outcome; chat and execute_tool spans under it
2. **Your collector** over OTLP

## Turn on

Off by default. Nothing is sent anywhere until you turn it on; then the data goes only to the collector you name. Settings apply when the worker starts.

```
openprogram config set telemetry.otel.enabled true
openprogram config set telemetry.otel.endpoint http://localhost:4318
openprogram restart
```

| Setting | Effect |
| --- | --- |
| `telemetry.otel.enabled` | Export traces and metrics. `OPENPROGRAM_ENABLE_TELEMETRY=1` also turns it on; `OTEL_SDK_DISABLED=true` keeps it off |
| `telemetry.otel.endpoint` | The collector's base address; `/v1/traces` and `/v1/metrics` are added for HTTP. Empty: `OTEL_EXPORTER_OTLP_ENDPOINT`, then `localhost` |
| `telemetry.otel.protocol` | `auto`, `http/protobuf` or `grpc`. `auto` reads `OTEL_EXPORTER_OTLP_PROTOCOL`, then uses `http/protobuf` |
| `telemetry.otel.headers` | Headers for every export, such as an `Authorization` header. Empty: `OTEL_EXPORTER_OTLP_HEADERS` |
| `telemetry.otel.log_user_prompts` | Add the prompt text to each turn |
| `telemetry.otel.log_tool_details` | Add tool arguments and result text to each tool call |

The other standard variables work too: `OTEL_SERVICE_NAME`, `OTEL_RESOURCE_ATTRIBUTES`, `OTEL_METRIC_EXPORT_INTERVAL`, and `OTEL_TRACES_EXPORTER=none` or `OTEL_METRICS_EXPORTER=none` to send only one of the two. The App exports over HTTP; gRPC needs a source install with the `telemetry-grpc` extra.

## What is sent

| Span | Attributes |
| --- | --- |
| `invoke_agent openprogram` | Session, turn, prompt length, total tokens and cost, model and tool call counts, outcome |
| `chat <model>` | Provider, model, input, output and cache tokens, cost, time to first token, outcome. A title, compaction or memory write is its own span under the turn |
| `execute_tool <tool>` | Tool name, call id, duration, result length, outcome |

| Metric, each named `openprogram.` + this | Labels |
| --- | --- |
| `token.usage` | `type` (input, output, cache_read, cache_write), model, provider, call_kind |
| `cost.usage` (USD) | model, provider, call_kind |
| `model.request.count` | model, provider, call_kind |
| `tool.call.count`, `tool.call.duration` (ms) | tool, outcome |
| `turn.count`, `turn.duration` (ms) | outcome |
| `session.count` |  |

Span names and `gen_ai.*` attributes follow the OpenTelemetry GenAI semantic conventions, so GenAI views in collectors read them as they are.

## Prompts and tool content

- **Default**: No prompt, reply, tool argument or tool result leaves the computer: only lengths, names, counts and timings
- **Opted in**: Text passes through secret removal (API keys, tokens, private keys, passwords in assignments) and is cut at 64 KiB
- **Never**: Credentials, and the export headers, which go only to the collector

Prompt text is taken from messages typed in an OpenProgram window; a turn started from a channel carries only its length.

[Configuration](https://openprogram.io/docs/server/configuration.html) · [Troubleshooting](https://openprogram.io/docs/server/troubleshooting.html)
