Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Simple exporter missing tokio runtime #1637

Open
joonnna opened this issue Mar 22, 2024 · 3 comments
Open

[Bug]: Simple exporter missing tokio runtime #1637

joonnna opened this issue Mar 22, 2024 · 3 comments
Labels
bug Something isn't working triage:todo Needs to be traiged.

Comments

@joonnna
Copy link

joonnna commented Mar 22, 2024

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 joonnna added bug Something isn't working triage:todo Needs to be traiged. labels Mar 22, 2024
@TommyCpp
Copy link
Contributor

TommyCpp commented Apr 7, 2024

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

@joonnna
Copy link
Author

joonnna commented Apr 8, 2024

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?

@cijothomas
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage:todo Needs to be traiged.
Projects
None yet
Development

No branches or pull requests

3 participants