Skip to content

Recipes

Each recipe is a few settings, or a few lines of code, for one common situation.

Nothing to do: when standard error isn’t a terminal, oxtel writes one JSON object per line, which every log shipper understands. To be explicit, set OXTEL_LOG_FORMAT=json. If your platform only collects standard output, set OXTEL_LOG_OUTPUT=stdout.

Sending to a backend is a matter of settings. Backends has a page for each common one, with a stack to run on your machine and the settings that send to it:

With oxtel-tower and its axum feature, one layer gives every request a span named by its route (GET /orders/{id}), continues the caller’s trace if it sent one, logs a request line with the status and duration, and records http.server.request.duration:

examples/web.rs
let app = Router::new()
.route("/orders/{id}", get(order))
.layer(oxtel_tower::HttpServerLayer::new());
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await?;
tracing::info!("listening on http://127.0.0.1:3000");
axum::serve(listener, app)
// On Ctrl-C, finish the requests in flight and let main return, so
// the guard is dropped and sends what's pending. Without this,
// Ctrl-C ends the process at once and the last few seconds of
// telemetry are lost.
.with_graceful_shutdown(async {
let _ = tokio::signal::ctrl_c().await;
})
.await?;
  • Call oxtel::init() first, so the layer finds the metrics recorder.
  • Shut down gracefully, as above. Otherwise Ctrl-C ends the process at once, before oxtel can send what’s pending.
  • .with_access_log(false) drops the request lines; RUST_LOG=info,oxtel_tower=warn keeps only those for failed requests.

A web service has the whole program.

Wrap the server with oxtel_rmcp::Instrumented::new(server) and serve the wrapper. Each request gets a span named for what it asks, such as tools/call add, continuing the client’s trace if it sent one:

examples/mcp-stdio.rs
let server = oxtel_rmcp::Instrumented::new(Calculator)
// What `network.transport` records: stdio is a pipe.
.with_transport("pipe")
.serve(rmcp::transport::stdio())
.await?;
// Until the client closes standard input.
server.waiting().await?;
  • Log lines go to standard error by default, which keeps them out of a stdio server’s protocol stream. Don’t set OXTEL_LOG_OUTPUT=stdout for one, or turn on a console exporter.
  • RUST_LOG=info,rmcp=warn keeps rmcp’s own lines and spans out of the way.
  • Over streamable HTTP, rmcp takes a handler rather than a service: wrap the server in oxtel_rmcp::InstrumentedHandler instead.

An MCP server over stdio and an MCP server over HTTP have whole programs.

Wrap a reqwest client with oxtel_reqwest::client, and each request gets a client span and sends the trace along in its headers. A service with oxtel-tower’s HttpServerLayer picks it up, so one trace covers both:

examples/two-services.rs
let inventory = Router::new()
.route("/stock/{item}", get(stock))
.layer(HttpServerLayer::new());
let listener = TcpListener::bind("127.0.0.1:3002").await?;
tokio::spawn(async move { axum::serve(listener, inventory).await });
// After `oxtel::init()`, so the client's durations are in seconds.
let client = oxtel_reqwest::client(reqwest::Client::new());
let shop = Router::new()
.route("/orders/{item}", get(order))
.with_state(client)
.layer(HttpServerLayer::new());
let listener = TcpListener::bind("127.0.0.1:3001").await?;
tokio::spawn(async move { axum::serve(listener, shop).await });

Two services has the whole program.

  • No log lines: OXTEL_LOG_FORMAT=none, or .without_local_logs() in code.
  • Nothing at all except log lines: OTEL_SDK_DISABLED=true.
  • One kind of telemetry: OTEL_TRACES_EXPORTER=none, OTEL_METRICS_EXPORTER=none or OTEL_LOGS_EXPORTER=none.