Skip to content

Observability

Every run in the terminal client and in the hosted API reports what it did as spans and metrics through @felix/telemetry. The package defines its own small contract and owns no backend: the host hands a run a TelemetryContext, and that context’s adapter decides where spans go. Without one, a run records nothing.

context.startSpan({ name, attributes? }, (span) => …) runs the callback inside a new span and resolves or rejects as the callback does. The span the callback receives is the parent for the work below it: nesting is passed explicitly, never through global state. A span ends when the callback’s promise settles: ok, or error (with the error’s name only) when it throws, unless the callback set a status. setAttributes merges, addEvent records a point in time, and every call after the end is ignored. A context may also carry metrics (counters, up-down counters, histograms) and propagation, which turns a context into a W3C traceparent carrier and back, so a trace can continue in another process. packages/telemetry/src/testing.ts is a conformance suite any adapter can run.

Adapter Does
NOOP_TELEMETRY Records nothing. The default.
TelemetryRecorder Keeps settled spans and metric aggregates (per series per ten seconds) in a bounded queue until its owner takes them as a batch, for a store to write.
MemoryTelemetry A recorder that keeps what it records in the process and answers findTraces, getTrace and findMetrics.
otelTelemetry(options?) (@felix/telemetry/otel) Writes through the OpenTelemetry JavaScript API, for a host app that already runs an OpenTelemetry SDK. See Inside an OpenTelemetry app.

runTelemetry({ context, attributes?, pricing?, model?, provider?, conversationId? }) opens the run’s span and returns hooks. model, provider and conversationId fill the GenAI attributes described under Spans.

Hook Call it from Does
emit(event) The run’s emit callback Records token usage, tool starts and the end reason.
observe(event) The run’s observe callback Opens model-turn spans, closes tool spans, adds span events. Unknown event types are ignored.
finish(error?) After the run settles Ends every open span; pass the error when the run failed. Resolves once they have all settled.
Surface Code Run attributes Prices
Terminal client apps/cli/src/conversation/chat.ts (ChatOptions.telemetry) felix.surface: cli From settings, when set for the model.
Hosted API apps/api/src/routes/chat.ts (ChatConfig.telemetry) felix.surface: api, felix.thread: hosted or stateless None, so no cost metric.

The hosted API reads a traceparent header and puts the run under that span, so a client’s trace continues on the server. It is diagnostics only, never authorization. Each terminal prompt and each hosted run request is one invoke_agent felix span. Child runs started through delegation are not traced on their own; the delegating call appears as one execute_tool span.

sqliteTelemetryStore keeps settled spans (one row each), a row per trace and metric aggregates in SQLite, for seven days by default. It takes a small executor rather than a driver, so the same store runs on a Durable Object’s SQL storage and on node:sqlite.

Surface Store Read it with
Hosted The TelemetryDatabase Durable Object, bound as TELEMETRY. Each run sends its recorder’s batch when it ends. GET /v1/traces, GET /v1/traces/<id>, GET /v1/metrics?name= (the operator token or a signed-in admin), or the client’s traces, trace and metrics.
Terminal ~/.felix/telemetry.sqlite (or $FELIX_HOME), on node:sqlite, shared by every felix on the machine. A run’s batch is written when its invoke_agent felix span settles. "telemetry": false in personal settings turns it off. pnpm chat --traces: recent runs with their outcome, model turns, tool calls and tokens.

A trace is listed by its first span: the earliest, and at the same start a span whose parent is not stored. A run that continues a caller’s trace (through traceparent) is listed by its run span.

Surface How What is sent
Terminal Set the standard OTEL_EXPORTER_OTLP_ENDPOINT (/v1/traces and /v1/metrics are appended), or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT and OTEL_EXPORTER_OTLP_METRICS_ENDPOINT for each, and, if the backend needs them, OTEL_EXPORTER_OTLP_HEADERS (key=value,…; …_TRACES_HEADERS and …_METRICS_HEADERS override it per name). OTEL_TRACES_EXPORTER=none or OTEL_METRICS_EXPORTER=none turns one off; OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES (key=value,…) set the resource. Each run’s spans and its metric aggregates, as one OTLP/HTTP JSON request each when the run ends (service name felix-cli), whether or not the local store is on. Metrics use delta temporality: each point covers its series’ ten-second interval since the previous run’s export. Counters are sums, and histograms carry their count, sum, min and max with their own buckets.
Hosted Set FELIX_TRACING=on, turn on the Worker’s traces (observability.traces.enabled in its Wrangler configuration) and add an OTLP destination for it in the Cloudflare dashboard. Each span is also opened on Workers tracing (teeTelemetry beside the store’s recorder), so it reaches that destination with the platform’s own spans. Events become <name>.count attributes. A span started outside its parent’s callback, such as a tool span, may appear beside the run span rather than under it; the store keeps the exact tree.
Hosted metrics Set OTEL_EXPORTER_OTLP_METRICS_ENDPOINT (or OTEL_EXPORTER_OTLP_ENDPOINT, with /v1/metrics appended) as a Worker variable, and the backend’s headers as the secret OTEL_EXPORTER_OTLP_HEADERS (or …_METRICS_HEADERS). Needs TELEMETRY. OTEL_METRICS_EXPORTER=none turns it off; OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES (key=value,…) set the resource. Every run’s metric aggregates, merged per series in the trace store and sent from its alarm once a minute as one OTLP/HTTP JSON request (service name felix-api), with delta temporality covering the time since the last export. The store is the only sender, so concurrent runs never send overlapping windows; a failed export (a network error, 408, 429 or a 5xx) is retried with the next one, and one the backend refuses for good (another 4xx) is dropped. Workers’ own OpenTelemetry export carries traces and logs but not custom metrics, so this is separate from FELIX_TRACING.

teeTelemetry(a, b, …) records every span in several adapters at once and passes the conformance suite. otlpTraceRequest(spans) and otlpMetricsRequest(metrics) build the OTLP JSON for any stored spans and metric aggregates.

A host app that embeds Felix and already registers an OpenTelemetry SDK can pass otelTelemetry() as the run’s telemetry context. Install @opentelemetry/api (1.10 or later; it is an optional peer dependency, so nothing else in Felix needs it).

import { otelTelemetry } from '@felix/telemetry/otel';
const telemetry = otelTelemetry(); // the global tracer, meter and propagator, all named `felix`
  • A Felix run span starts under whatever span the host has active, so a run that serves a request nests under that request’s span.
  • Inside a Felix span’s callback, that span is the active one, so the host’s own instrumentation (HTTP clients, database drivers) nests under it.
  • Metrics go to the host’s meter with the names under Metrics. Carriers go through the host’s propagator.
  • Span kinds, statuses and the content policy are the same as for Felix’s own stores. A status message is the error’s name only.

Pass tracer, meter (or meter: false for none) or propagator to use something other than the globals. With no SDK registered, the OpenTelemetry API records nothing, and neither does the adapter. The adapter passes the same conformance suite as the built-in adapters, run against the OpenTelemetry SDK.

Span names, kinds and gen_ai.* attributes follow the OpenTelemetry GenAI semantic conventions (still marked Development upstream), so GenAI-aware backends group and chart Felix runs without configuration. Felix’s own felix.* attributes sit beside them. Content attributes the conventions leave opt-in (messages, tool arguments and results) are never recorded.

Model-call and tool spans are children of the run span. A model-call span ends when its usage is reported, when a tool call starts, or when the next turn starts.

Span (kind) Attributes
invoke_agent felix (internal) The run attributes; gen_ai.operation.name: invoke_agent, gen_ai.agent.name: felix, gen_ai.provider.name, gen_ai.request.model, gen_ai.conversation.id (the hosted thread id, or a hash of the terminal session’s path); felix.end_reason (complete or limit) when the run reaches an end; felix.fallback_model when it moved to the deployment’s fallback model (with a felix.model_fallback event, carrying the failure’s http.response.status_code, on the model call that failed); error.type when it failed, with the failure’s fixed facts below.
chat <model> (client) The run attributes; gen_ai.operation.name: chat, gen_ai.provider.name, gen_ai.request.model, gen_ai.usage.input_tokens (including cached input, as the conventions count it), gen_ai.usage.output_tokens, gen_ai.usage.cache_read.input_tokens and gen_ai.usage.cache_creation.input_tokens when non-zero; felix.model_turn, felix.tool_calls, felix.tokens.input, felix.tokens.output, felix.tokens.cached_input, felix.tokens.cache_write_input. The call that was running when a run failed gets error.type and the failure’s fixed facts below.
execute_tool <tool> (internal) The run attributes; gen_ai.operation.name: execute_tool, gen_ai.tool.name, gen_ai.tool.call.id, gen_ai.tool.type: function; felix.tool.name, felix.tool.call_id, felix.tool.outcome (ok, error or blocked); error.type when it failed.

A failed run, and its failed model call, record the failure’s fixed facts and never its message: http.response.status_code for a provider’s HTTP status, felix.error.retryable, and felix.error.reason for a reply the provider sent but Felix could not use (output_limit, incomplete, invalid_response, invalid_tool_call, too_large or inference_failed; every model adapter reports it). The run’s trace in the web app’s Activity shows them on the failed span, such as invalid tool call or HTTP 429.

The provider is cloudflare.workers_ai, anthropic, openai, mistral_ai, gcp.gemini, gcp.vertex_ai or aws.bedrock. A tool call that fails, or that policy or approval blocks, gets an error status and error.type named ToolError or Blocked. A tool span still open when the run ends gets Unfinished. A failed run gets the error’s name only.

Event On Attributes
felix.retry The current model-turn span, otherwise the run span felix.attempt, felix.delay_ms
felix.context_overflow Run span felix.recovered
felix.steer Run span felix.count (steering messages delivered)
felix.limit Run span felix.limit (toolCalls, inputTokens, outputTokens or deadline)
felix.compaction Run span felix.outcome (compacted, nothing_to_compact or failed)
felix.tool_results_cleared Run span None. Large old tool results were cleared from the model’s context before summarizing.
felix.interrupted_calls Run span None

Every metric carries the run attributes as well as the ones listed. Stores keep them aggregated per series per ten seconds: a count, sum, minimum and maximum, and for a histogram whose instrument names bucket bounds (boundaries, finite and strictly increasing), a count per bucket, so percentiles can be read back. Aggregates with different bounds keep no buckets when they merge.

Metric Type Unit Attributes
felix.tokens Counter {token} felix.token.kind: input, output, cached_input when cached tokens were reported, or cache_write_input when cache writes were
felix.cost Counter USD None. Recorded only when prices are configured.
felix.tool.calls Counter {call} felix.tool.name, felix.tool.outcome
felix.tool.duration Histogram ms felix.tool.name. Recorded when the run measured the call. Buckets at 10, 25, 50, 100, 250 and 500 ms, 1, 2.5, 5, 10 and 30 seconds, and 1, 2 and 5 minutes.
felix.model.duration Histogram ms gen_ai.provider.name, gen_ai.request.model, felix.outcome (ok or error). From a model request to its complete reply, retries included. Buckets at 100, 250 and 500 ms, 1, 2.5, 5, 10, 20 and 30 seconds, and 1, 2, 5 and 10 minutes.
felix.model.first_chunk Histogram ms gen_ai.provider.name, gen_ai.request.model. From a model request to its first streamed text, reasoning or tool call, once per request. Buckets at 50, 100, 250 and 500 ms, 1, 2, 5, 10, 20 and 30 seconds, and 1 minute.
felix.retries Counter {retry} http.response.status_code, when the provider returned one

Token counts are what the provider reported for each inference. Felix does not count tokens itself.

Message text, reasoning, tool arguments, tool results and error messages never reach a span, an event or a metric. A failed run keeps only the error’s name, because a message can quote file contents or user text. Retries record the HTTP status, never the response body. Credentials are never read by the instrumentation. The suite in packages/telemetry/src/test/index.test.ts feeds it text, a tool call with a file path, a compaction summary and a failing run, then checks that none of it appears in what was recorded.

Each inference produces a usage event with input, output and, when the provider reports it, cached input tokens. The hosted API forwards it to clients as a usage event in the run stream. The terminal client shows it as a status line for each model turn, and pnpm chat --json writes it as a line of JSON.

Cost is an estimate from prices you supply. Felix ships no price list. In the terminal client, set pricing for a model under models in ~/.felix/settings.json or the workspace’s .felix/settings.json, in US dollars per million tokens:

{
"models": {
"@cf/zai-org/glm-5.3": { "pricing": { "input": 1.4, "output": 4.4, "cachedInput": 0.26 } }
}
}
Field Required Meaning
input Yes Dollars per million input tokens.
output Yes Dollars per million output tokens.
cachedInput No Dollars per million cached input tokens. Without it, cached tokens are charged at the input price.
cacheWrite No Dollars per million input tokens written to the prompt cache. Without it, writes are charged at the input price.
cacheWriteLong No Dollars per million input tokens written to the one-hour prompt cache. Without it, they are charged at cacheWrite.
tiers No Long-context rate sets, each {inputTokensAbove, input, output, …}; a request whose input exceeds a threshold is charged wholly at the highest such tier.

The terminal client prints one usage line per model call: tokens (model turn N): 1200 input (900 cached) · 80 output, naming cache writes too when the provider reports them (1200 input (900 cached, 300 written to cache)). With prices set for the selected model it adds an estimated cost and the conversation’s running total (about $0.0021 · session about $0.0140). When a provider reports cached tokens and much less of the prompt was cached than last time, it adds cache miss: about N tokens re-read, with after N min idle when the gap was long enough for the cache to expire.

With prices set, felix.cost is also recorded when telemetry is on. usageCost in @felix/ai does the arithmetic.

A run reports what happens through two callbacks. emit receives AgentEvents, the stream that the hosted API forwards to clients. observe receives RunEvents, extra detail for local observers that never goes over the wire. Both are awaited, and a failure in either stops the run.

emit event Fields When
usage modelTurn, usage After each inference.
text text Streamed reply text.
reasoning text Streamed model reasoning, for display only.
reasoning_reset The reasoning streamed for the inference in progress is withdrawn: it failed before any text or tool call and is being asked again.
message message A message was checkpointed.
tool_start callId, name A tool call is about to run.
end reason (complete or limit) The run finished.
observe event Fields When
turn_start modelTurn Before each inference.
tool_end callId, name, error, blocked, durationMs A tool result was checkpointed. durationMs is the execution time, when measured.
tool_progress callId, name, text A tool reported progress, such as recent command output.
retry modelTurn, attempt, delayMs, status A transient provider failure will be retried.
model_fallback modelTurn, to, status The run moved to its fallback model after the model failed.
tool_call_delta modelTurn, index, name, callId, text A piece of the argument JSON of a tool call the model is still writing, for showing progress.
context_overflow modelTurn, recovered The provider rejected the context as too large.
steer count Steering messages were delivered between model turns.
limit limit A tool-call, token or time budget ended the run.

Runs started through the harness’s prompt add two more observe events: compaction, with an outcome and the token estimate before compaction, and interrupted_calls, listing tool calls left unresolved by an earlier crash or cancellation that were closed with an unknown outcome. See Architecture for where these packages sit.