# OTLP

`otlp()` sends telemetry for each Invocation (one Agent run) to any OpenTelemetry receiver that accepts standard logs and traces, over OTLP HTTP JSON. It registers a trace exporter, adds no model tool, and wraps no Server Primitive.

## Configure OTLP export

Pass the receiver's base endpoint. ViteHub adds `/v1/logs` and `/v1/traces`.

```ts [server/agents/support.ts]
import { defineAgent } from 'vite-hub/agent'
import { otlp } from 'vite-hub/agent/capabilities'

export default defineAgent({
  capabilities: [
    otlp({
      endpoint: process.env.OTLP_ENDPOINT!,
      headers: {
        authorization: `Bearer ${process.env.OTLP_TOKEN!}`,
      },
      resource: {
        'service.namespace': 'support',
      },
      live: true,
    }),
  ],
  driver: { model: 'openai/gpt-5.1-mini' },
  name: 'support',
})
```

## How OTLP export works

ViteHub always sends one completed trace with timing and `gen_ai.*` span attributes.

### The configuration event

Without `live`, the root span also has the run's Trace Events, including `vitehub.agent.configured`. It describes the Agent Definition, secrets removed: Agent identity, Capability metadata, known Driver and model identity, tool names, runtime, and Workspace name, mode, and Sources.

Its `vitehub.agent.configuration.fingerprint` hashes these facts and the final instructions, not Capability inspection snapshots:

- Public configurations get a stable `sha256_...` digest.
- Configurations with redacted credentials get an `hmac_sha256_...` digest with a private runtime key, so credentials cannot be guessed offline. These compare only within one runtime and change on restart.

### Live export

With `live: true`, each Trace Event goes once as an OTLP LogRecord during the run:

- Records share the completed trace's trace and span IDs.
- Each carries `agent.invocation.id` and `vitehub.event.sequence` for de-duplication.
- Batches go after five seconds or 512 new events, whichever is first, and the rest at the end.
- When all records arrive, the completed trace omits span events. If a batch fails, it keeps them, so no data is lost.

ViteHub only appends. It never polls or resends a changing open-span snapshot. OTLP over HTTP and gRPC is request and response, so there is no receiver-specific SSE or WebSocket channel.

## Custom Capability metadata

Every Capability adds its public `metadata`. A custom Capability can also add facts learned during the run, without knowing the exporter:

```ts fragment
import { defineCapability } from 'vite-hub/agent'

export const repository = defineCapability({
  id: 'repository',
  metadata: { provider: 'github' },
  async resolve(context) {
    const installation = await resolveInstallation(context)
    context.telemetry.metadata({ installation: installation.slug })
  },
})
```

They go in its configuration event entry, with no extra stream or receiver-specific code.

## Delivery behavior

- The exporter retries temporary HTTP failures and obeys `Retry-After`.
- Export is best effort through the host's `waitUntil()`. A down receiver does not change Agent output.
- Receiver failures log a short local error with Capability ID, invocation ID, run ID, and export phase.

> [!NOTE]
> Retries can resend requests. De-duplicate spans by trace and span ID, and live records by `agent.invocation.id` and `vitehub.event.sequence`.

Streamed command output is trace activity, not a log drain. Command start, output parts, and provider completion share a tool-call ID, so a session UI can group them without parsing terminal escape sequences.

## Requirements

- A full `http:` or `https:` base endpoint.
- A receiver accepting OTLP/HTTP JSON at `/v1/traces`, and `/v1/logs` with `live`.

## Security and approval

There is no model tool, so no approval step. By default, only metadata goes to the receiver, not content.

The configuration event is not a user message. The trace content policy controls prompts and model or tool content; this exporter sends their metadata.

Capability tool start, finish, and error events carry `capability.id`; unused Capabilities add none. Tool input and output need content export.

Agent instructions are prompt content, left out by default. Turn them on for a trusted receiver:

```ts
import { otlp } from 'vite-hub/agent/capabilities'

otlp({
  endpoint: process.env.OTLP_ENDPOINT!,
  content: {
    inputs: true,
    instructions: true,
    outputs: true,
  },
})
```

Secret-shaped metadata keys become `[redacted]`. Keep receiver credentials in `headers`; the endpoint and headers never appear in Agent metadata.

## Driver support

| Agent Driver | Support |
| --- | --- |
| Model-backed | Trace with model and tool activity. |
| Provider-backed | Trace with normalized provider tool and command activity. |
| Custom-run-backed | Trace recorded around `driver.run`. |

## Verify OTLP export

1. Run once against a local OpenTelemetry Collector with a debug exporter.
2. One trace with a `vitehub.agent.configured` event reaches `/v1/traces`, and LogRecords reach `/v1/logs` with `live`.
3. With the receiver stopped, output is unchanged and a local export error appears.

## Options

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `endpoint` | `string` | Required | Absolute base endpoint. `/v1/logs` and `/v1/traces` are appended. |
| `headers` | `Record<string, string>` or resolver | None | Headers resolved per export. |
| `resource` | OTLP resource attributes or resolver | Agent and runtime defaults | Additional resource attributes. |
| `content.inputs` | `boolean` | `false` | Export user and tool input content. |
| `content.instructions` | `boolean` | `false` | Export resolved Agent instructions. |
| `content.outputs` | `boolean` | `false` | Export assistant, tool, and result output. |
| `live` | `boolean` | `false` | Send Trace Events as correlated OTLP logs during the run. |

## Related pages

- [Agent invocations](https://vitehub.dev/docs/agents/invocations)
- [diagnostics()](https://vitehub.dev/docs/agents/capabilities/diagnostics)
- [Custom capabilities](https://vitehub.dev/docs/agents/capabilities/custom)
- [Official capabilities](https://vitehub.dev/docs/agents/capabilities/official)

<!-- vitehub-docs:section-links -->
## In this section

- [Start](https://vitehub.dev/raw/docs/agents.md)
- [Define and run](https://vitehub.dev/raw/docs/agents/agent-definitions.md)
- [Instructions and tools](https://vitehub.dev/raw/docs/agents/instructions.md)
- [History and context](https://vitehub.dev/raw/docs/agents/chat-history-sessions.md)
- [Channels](https://vitehub.dev/raw/docs/agents/channels.md)
- [Inspect and evaluate](https://vitehub.dev/raw/docs/agents/observability.md)
- [Advanced](https://vitehub.dev/raw/docs/agents/agent-presets.md)
- [Recipes](https://vitehub.dev/raw/docs/agents/support-agent.md)
- [Presets](https://vitehub.dev/raw/docs/agents/presets.md)
- Capabilities
  - [Access](https://vitehub.dev/raw/docs/agents/capabilities/access.md)
  - [Chat](https://vitehub.dev/raw/docs/agents/capabilities/chat.md)
  - [Input commands](https://vitehub.dev/raw/docs/agents/capabilities/input-commands.md)
  - [Skills](https://vitehub.dev/raw/docs/agents/capabilities/skills.md)
  - [Git](https://vitehub.dev/raw/docs/agents/capabilities/git.md)
  - [Forge](https://vitehub.dev/raw/docs/agents/capabilities/forge.md)
  - [Gmail](https://vitehub.dev/raw/docs/agents/capabilities/gmail.md)
  - [MCP](https://vitehub.dev/raw/docs/agents/capabilities/mcp.md)
  - [OTLP](https://vitehub.dev/raw/docs/agents/capabilities/otlp.md) (this page)
  - [Diagnostics](https://vitehub.dev/raw/docs/agents/capabilities/diagnostics.md)
  - [Papercuts](https://vitehub.dev/raw/docs/agents/capabilities/papercuts.md)
  - [Web search](https://vitehub.dev/raw/docs/agents/capabilities/web-search.md)
  - [Fetch](https://vitehub.dev/raw/docs/agents/capabilities/fetch.md)
  - [Page](https://vitehub.dev/raw/docs/agents/capabilities/page.md)
  - [OpenAPI](https://vitehub.dev/raw/docs/agents/capabilities/openapi.md)
  - [Transcribe](https://vitehub.dev/raw/docs/agents/capabilities/transcribe.md)
  - [Memory](https://vitehub.dev/raw/docs/agents/capabilities/memory.md)
  - [Title](https://vitehub.dev/raw/docs/agents/capabilities/title.md)
  - [Progress summary](https://vitehub.dev/raw/docs/agents/capabilities/progress-summary.md)
  - [Budget](https://vitehub.dev/raw/docs/agents/capabilities/budget.md)
  - [Usage](https://vitehub.dev/raw/docs/agents/capabilities/usage.md)

Next: [AGENT_R0295](https://vitehub.dev/raw/docs/agents/diagnostics/agent_r0295.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
