Rust

Embed
Preview of the card
<a href="https://forumulate.com/p/watchtower/docs/onboarding-rust"><img src="https://forumulate.com/api/public/orgs/watchtower/spaces/docs/pages/d0211769-a638-4f15-a075-15c98e3deb6e/social-card.svg?v=3e7ae33eec8b" alt="Rust" width="600" height="315"></a>

<!-- status: ga language: rust -->

Rust

Send traces from a Rust service to Watchtower over OTLP/HTTP with the standard OpenTelemetry SDK. Nothing Watchtower-specific is installed: the SDK reads the standard OTEL_* variables.

  1. Create a project, then an ingestion key (wti_...) with the ingest:traces scope. The key is shown once.

  2. Point the SDK at the gateway and pass the key in the x-watchtower-key header (Authorization: Bearer wti_... works too):

export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.example.com
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_HEADERS=x-watchtower-key=wti_YOUR_KEY
export OTEL_SERVICE_NAME=my-service
  1. Add the SDK and run this once. The endpoint above is the gateway's base URL; the SDK appends /v1/traces.

cargo add opentelemetry opentelemetry_sdk
cargo add opentelemetry-otlp --features http-proto,reqwest-rustls
use opentelemetry::global;
use opentelemetry::trace::Tracer;
use opentelemetry_otlp::SpanExporter;
use opentelemetry_sdk::trace::SdkTracerProvider;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // reads OTEL_EXPORTER_OTLP_*
    let exporter = SpanExporter::builder().with_http().build()?;
    let provider = SdkTracerProvider::builder().with_batch_exporter(exporter).build();
    global::set_tracer_provider(provider.clone());

    global::tracer("onboarding").in_span("hello-watchtower", |_| {});
    provider.shutdown()?;
    Ok(())
}
  1. Open the project's onboarding screen. It polls GET /v1/projects/{prj}/onboarding/first-event and turns green when the first span arrives. Then open the trace in the trace explorer.

Use the reqwest-rustls feature, not an OpenSSL one, so the binary builds the same on Linux and Windows.

Updated