Instrument library in Rust with OpenTelemetry

Im learning tracing in Rust and open-telemetry in Rust. I feel there are too many concepts and too many crates (at least in Rust) to see traces.

I wrote a simple lib app that adds two u32s.

use std::ops::Add;

pub fn add(f: u32, s: u32) -> u32 {
	let span = tracing::info_span!("Add function", ?f, ?s);
	let _guard = span.enter();
	tracing::info!("Info event");

And then Im using the lib in my bin app as below.

use TracedLibrary::add;
use tracing_opentelemetry::OpenTelemetryLayer;
use tracing_subscriber::util::SubscriberInitExt;
use opentelemetry::{global, sdk::propagation::TraceContextPropagator};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::Registry;

fn main() {
	let sum = add::add(1, 2);

fn setup_global_subscriber() {
	let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
		.install().expect("Error initializing Jaeger exporter");
	let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);


The most confusing part is my apps Cargo.toml which looks like

tracing-subscriber = { version = "0.2.15" }
tracing-opentelemetry = { version= "0.11.0"}
opentelemetry = "0.12.0"
opentelemetry-jaeger = {version = "0.11.0" }

What on earth are those different crates are for? The only crate that makes sense is opentelemetry-jaeger. Are others even required?

And to my main question: Im running Jaeger's all-in-one docker container. But when I visit http://localhost:16686...I see no traces.
Does anyone know what's happening?

PS: I have a docker instance of Jaeger all-in-one up and running.

Well..when I create a jaeger pipeline in setup_global_subscriber()... the _uninstall being returned gets dropped at the end of the method.
And what it gets dropped, collector shuts down.

To get traces I had to move contents of setup_global_subscriber() in main().

Spent a day figuring this out. Not sure if it was worth it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.