OpenTelemetry
Reference for the spans, attributes, and metrics emitted by libsy and its LLM client.
Host setup
Your application installs a tracing-opentelemetry subscriber and global OTel meter
provider, and owns exporters, filtering, sampling, context propagation, and flushing.
Libsy installs none of these and sends no telemetry itself. Environment variables
alone do not enable collection. See OTel Rust setup
and OTLP configuration.
Spans and attributes
Hosts driving run_stream without the LLM client driver instrument their own model I/O.
libsy.decision_call records algorithm, selected_model, and terminal outcome.
Successful replies add available input_tokens, output_tokens, total_tokens,
reasoning_tokens, gen_ai.response.id, and gen_ai.response.model fields.
Unknown values are omitted; request content, answers, and error details are not recorded.
Routing outcome fields
On libsy.run:
RoutingOutcome.metadata is available in Rust and Python. Its optional JSON evidence
exports only the listed keys with matching types; unknown keys and wrong types are
omitted. Evidence may be absent. Scores and confidence have algorithm-specific meanings.
Failed runs return typed errors, not outcome metadata; successful fail-open decisions
may carry a fixed reason_code.
Model-call fields
The LLM client driver records these on libsy.client_call:
gen_ai.provider.name is intentionally unset: an endpoint or model name does not
reliably identify the provider. Usage fields are omitted when unavailable, not
invented as zero. Available counts are capped at OTel’s signed integer maximum.
Metrics
Metrics use the switchyard meter scope. The tables use OTel instrument names.
Routing and client metrics
Algorithm/call outcome is ok or error. HTTP attempt outcome is ok for
2xx, retryable_error for 408/429/5xx or failures without a status, and
other_error otherwise. code is an allowlisted status, a status-class bucket,
or none. Classifier reason is timeout, transport, upstream_5xx,
upstream_non_5xx, invalid_response, parse_error, client_error, or call_error.
Client requests, routing decisions, model calls, and HTTP attempts have separate
counts. For switchyard.llm_calls and switchyard.llm_call_duration_ms, each
routing-time offloaded call and each terminal answer candidate contributes one
observation. HTTP retries stay within the same candidate’s count and duration.
Reusing a response produced during routing keeps only its routing-time call observation.
For example, one buffered client request with no judge calls or retries, a failed
primary, and a successful fallback produces one client response, one routing decision,
two llm_calls, and two llm_call_duration_ms samples. The primary has
selected_model=<primary> and outcome=error; the fallback has
selected_model=<fallback> and outcome=ok. For terminal answer-candidate observations,
selected_model identifies the model called. For routing-time observations, it
identifies the initial routing candidate. For switchyard.decisions, it identifies
the initial routing selection.
The five request/error/latency instruments above record each answer candidate after
routing, not each HTTP attempt. A failed candidate followed by a successful fallback
adds two to total_requests, one to total_errors, one to errors for the failed
model, and one to requests for the successful model. Routing-time calls and failures
before a routing outcome do not contribute. A response reused from routing contributes
one to total_requests and one to either requests or errors (also total_errors
on failure), but no model_call_latency_ms sample. The model label is the
candidate’s configured model ID (the serving model for a reused response).
For terminal answer candidates, it matches selected_model on llm_calls and
llm_call_duration_ms. The two total gauges are cumulative process-wide
compatibility values.
For streams, these five instruments record when the response stream ends or is dropped.
Stream errors count as failures. Dropping an unfinished stream also counts as a failure;
a terminal message permits a successful drop. Failed calls have no
model_call_latency_ms sample.
Algorithm-specific metrics
Stage Router instruments use the prefix switchyard.stage_router.:
These histograms contain unitless values from 0 to 1. They are recorded when tool signals reach the scorer, including when it defers to a classifier. They are not one sample per application request and are not split by route or session.
Advisor Gate instruments use the prefix switchyard.advisor_gate.:
Limits
Timing and streaming
libsy.runmay finish before the answer call. Nested algorithms have separate run spans.- Decision calls record
errorwhen failed or dropped without a reply, including cancellation. Cancelled calls do not poll further host work. A response completed during a cancellation race may still record its result. These metrics work with any host and do not require a client observer. libsy.llm_calland routing-time call metrics end when the host fulfills the offloaded call. They include host queueing. The LLM client driver buffers routing streams before fulfilling the call. The span’sinput_tokens,output_tokens,total_tokens, andreasoning_tokensfields are buffered-response only.- For terminal answer candidates,
switchyard.llm_callsandswitchyard.llm_call_duration_msrecord when the response stream ends or is dropped. Duration includes that candidate’s retries and stream consumption. Stream errors and unfinished drops recordoutcome=error; a terminal message permits a successful drop. libsy.client_callremains open while its stream is consumed. IDs, usage, and finish reasons update from normalized events. An unfinished stream dropped by its consumer recordscancelled; a stream error recordserror.
Data exposure
Built-in evidence excludes prompts, responses, and raw errors. Custom evidence is
checked for field names and types, not string contents or lengths. Client spans may
include error descriptions and upstream addresses; algorithm logs may include content
such as Advisor Gate’s reply_head. Supplied session/correlation IDs are included.
Review collected data before exporting it outside your deployment.
Custom algorithms can record OTel instruments directly. Keep metric labels to configured names and fixed categories, not request/session IDs or user text.
Source and stability
These are current implementation names, not a separately versioned telemetry schema. Debug spans and log events are not a stable field contract.