OpenTelemetry Rust Configuration
Ship traces from Rust to OpenSearch with OpenTelemetry
Use OpenTelemetry to easily send Rust traces to your Logit.io Stack.
APM
Install Integration
Getting Started
You can get help Getting Started with OpenTelemetry for Rust by referring to the official documentation (opens in a new tab).
This example uses the snippet found here (opens in a new tab) 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 @opentelemetry.base64encodedAuthString".parse().unwrap());
let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint("https://@opentelemetry.endpointAddress:@opentelemetry.httpsPort")
.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://@opentelemetry.endpointAddress:@opentelemetry.httpsPort".to_string(),
protocol: Protocol::http/protobuf
};
tracer.in_span("doing_work", |cx| {
// Traced app logic here...
});
Ok(())
}
For more information about exporter configuration with Rust please refer to the official documentation (opens in a new tab).
Launch Logit.io to view your traces
Data should now have been sent to your Stack.
View My DataIf you don't see take a look at How to diagnose no data in Stack below for how to diagnose common issues.
How to diagnose no data in Stack
If you don't see data appearing in your stack after following this integration, take a look at the troubleshooting guide for steps to diagnose and resolve the problem or contact our support team and we'll be happy to assist.