opentelemetry-rust icon indicating copy to clipboard operation
opentelemetry-rust copied to clipboard

[Bug]: Simple exporter missing tokio runtime

Open joonnna opened this issue 11 months ago • 3 comments

What happened?

The following example results in a panic, but works fine with the batch exporter. There clearly exists a tokio runtime, any ideas?

use opentelemetry_otlp::WithExportConfig;
use std::collections::HashMap;
use tracing::{info, span, Level};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::Registry;

#[tokio::main]
async fn main() {
    let api_key = "...";
    let mut metadata = HashMap::new();
    metadata.insert("x-honeycomb-team".to_string(), api_key.to_string());

    let tracer = opentelemetry_otlp::new_pipeline()
        .tracing()
        .with_exporter(
            opentelemetry_otlp::new_exporter()
                .http()
                .with_endpoint("https://api.honeycomb.io")
                .with_headers(metadata),
        )
        .install_simple()
        .unwrap();

    let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);

    let registry = Registry::default().with(telemetry);
    tracing::subscriber::set_global_default(registry).unwrap();

    test();
}

fn test() {
    let span = span!(Level::INFO, "test");
    let _enter = span.enter();

    info!("test");
}

Cargo.toml

[package]
name = "play"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.36", features = ["full"] }
tracing = "0.1.40"
tracing-log = { version = "0.2.0" }
tracing-opentelemetry = { version = "0.23.0" }
tracing-subscriber = { version = "0.3.18" }
opentelemetry = { version = "0.22.0", features = ["metrics", "trace"] }
opentelemetry_sdk = { version = "0.22.0", features = ["rt-tokio"] }
opentelemetry-otlp = { version = "0.15.0", features = [
    "http-proto",
    "reqwest-client",
    "reqwest-rustls",
] }

API Version

0.15

SDK Version

0.22.0

What Exporters are you seeing the problem on?

OTLP

Relevant log output

thread 'opentelemetry-exporter' panicked at /home/jon/.config/cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.28/src/client/connect/dns.rs:121:24:
there is no reactor running, must be called from the context of a Tokio 1.x runtime

joonnna avatar Mar 22 '24 11:03 joonnna

I'd recommend against using simple span processor in async runtime as it's blocking and may prevent your runtime from moving forward

TommyCpp avatar Apr 07 '24 21:04 TommyCpp

I see, I'm trying to export spans of a program that immediately exits after doing some work and saw the synchronous exporter as the natural solution. Manually flushing all spans would also solve my case, is there any way to do this?

joonnna avatar Apr 08 '24 06:04 joonnna

mm.. The upcoming release should fix the issue : https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-sdk/CHANGELOG.md#vnext

We previously spun up a thread, even for SimpleSpanProcessor, and that is replaced now (in next release).

I'm trying to export spans of a program that immediately exits after doing some work

Based on this description, SimpleSpanProcessor is your best bet.

@TommyCpp What are the potential issues to be aware of when using this?

cijothomas avatar Apr 08 '24 17:04 cijothomas