Get a DemoStart Free TrialSign In

OpenTelemetry Rust Configuration

Ship traces from Rust to Opensearch with OpenTelemetry (via gRPC)

Use OpenTelemetry to easily send Rust traces to your Logit.io Stack.

Send Your DataAPMLanguages & LibrariesOpenTelemetry Rust Configuration Guide

Follow this step by step guide to get 'traces' from your system to Logit.io:

Step 1 - Getting Started

You can get help Getting Started with OpenTelemetry for Rust by referring to the official documentation.

This example uses the snippet found here as its basis.

use opentelemetry_api::{KeyValue, trace::Tracer};
use opentelemetry_sdk::{trace::{self, RandomIdGenerator, Sampler}, Resource};
use opentelemetry_sdk::util::tokio_interval_stream;
use opentelemetry_otlp::{Protocol, WithExportConfig, ExportConfig};
use std::time::Duration;
use tonic::metadata::*;

fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    let mut map = MetadataMap::with_capacity(1);

    map.insert("authorization", "Basic <your-encoded-opentelemetry-auth-header-value>".parse().unwrap());

    let tracer = opentelemetry_otlp::new_pipeline()
        .tracing()
        .with_exporter(
            opentelemetry_otlp::new_exporter()
            .tonic()
            .with_endpoint("https://<your-opentelemetry-endpoint-address>:<your-opentelemetry-endpoint-port>")
            .with_metadata(map)
        )
        // The trace config below should be amended to your requirements
        .with_trace_config(
            trace::config()
                .with_sampler(Sampler::AlwaysOn)
                .with_id_generator(RandomIdGenerator::default())
                .with_max_events_per_span(64)
                .with_max_attributes_per_span(16)
                .with_max_events_per_span(16)
                .with_resource(Resource::new(vec![KeyValue::new("service.name", "example")])),
        )
        .install_batch(opentelemetry::runtime::Tokio)?;

    let export_config = ExportConfig {
        endpoint: "https://<your-opentelemetry-endpoint-address>:<your-opentelemetry-endpoint-port>".to_string(),
        protocol: Protocol::<your-opentelemetry-protocol>
    };

    tracer.in_span("doing_work", |cx| {
        // Traced app logic here...
    });

    Ok(())
}

For more information about exporter configuration with Rust please see the documentation here

Step 2 - Check Logit.io for your traces

Data should now have been sent to your Stack.

View my data

If you don't see traces please take a look at How to diagnose no data in Stack below for how to diagnose common issues.

Step 3 - how to diagnose no data in Stack

If you don't see data appearing in your Stack after following the steps, visit the Help Centre guide for steps to diagnose no data appearing in your Stack or Chat to support now.

Return to Search
Sign Up

© 2024 Logit.io Ltd, All rights reserved.