Recipes
Each recipe is a few settings, or a few lines of code, for one common situation.
JSON logs in a container
Section titled “JSON logs in a container”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.
A backend
Section titled “A backend”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:
- Elastic: over OTLP to APM Server, or as log lines in the Elastic Common Schema with
OXTEL_LOG_FORMAT=ecs. - Grafana, Tempo and Loki: traces, logs and metrics, each to the store that keeps it.
- Hosted backends: an endpoint and a key in a header.
- Jaeger: traces.
- The OpenTelemetry Collector: one address for your programs, sending on to any backend.
- Prometheus: metrics, scraped from oxtel’s
/metricsor pushed over OTLP.
A web service
Section titled “A web service”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:
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 therequestlines;RUST_LOG=info,oxtel_tower=warnkeeps only those for failed requests.
A web service has the whole program.
An MCP server
Section titled “An MCP server”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:
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=stdoutfor one, or turn on a console exporter. RUST_LOG=info,rmcp=warnkeeps 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::InstrumentedHandlerinstead.
An MCP server over stdio and an MCP server over HTTP have whole programs.
Calling another service
Section titled “Calling another service”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:
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.
Turning things off
Section titled “Turning things off”- 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=noneorOTEL_LOGS_EXPORTER=none.