Rust
1. Install
Section titled “1. Install”cargo add opentelemetry opentelemetry_sdk opentelemetry-otlp opentelemetry-appender-tracingcargo add tracing tracing-subscriber tracing-opentelemetry2. Set up the exporters
Section titled “2. Set up the exporters”Add this at the start of main. It sends tracing events as logs and tracing spans as traces:
let spans = SpanExporter::builder().with_http().build().unwrap();let tracer_provider = SdkTracerProvider::builder().with_batch_exporter(spans).build();let metrics = MetricExporter::builder().with_http().build().unwrap();let meter_provider = SdkMeterProvider::builder().with_periodic_exporter(metrics).build();let logs = LogExporter::builder().with_http().build().unwrap();let logger_provider = SdkLoggerProvider::builder().with_batch_exporter(logs).build();global::set_meter_provider(meter_provider.clone());tracing_subscriber::registry() .with(OpenTelemetryTracingBridge::new(&logger_provider)) .with(tracing_opentelemetry::layer().with_tracer(tracer_provider.tracer("checkout"))) .init();Before your program exits, call shutdown() on the three providers so buffered data is sent.
3. Configure
Section titled “3. Configure”Set these where your app runs. Replace YOUR_INGEST_KEY with your key and checkout with your service name.
export OTEL_SERVICE_NAME=checkoutexport OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=productionexport OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.siteqwality.comexport OTEL_EXPORTER_OTLP_HEADERS=Authorization=YOUR_INGEST_KEYexport OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf4. Send a log
Section titled “4. Send a log”Keep using the tracing macros. Events inside a span are linked to its trace:
tracing::info!(order_id = 42, "order placed");5. Record a metric (optional)
Section titled “5. Record a metric (optional)”let orders = global::meter("checkout").u64_counter("orders.placed").build();
orders.add(1, &[]);See your data
Section titled “See your data”Open Logs, Traces or Metrics. New data usually shows up within a minute, and a page that says it is waiting for data switches to your data on its own.
The code on this page comes from a runnable example that is checked against our ingest rules every month.
Nothing arriving? Check that the key is an ingest key for this account, that your account has early access, and the status codes in Ingest routes and limits.