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

OpenTelemetry log error occurred when dropping the old log_provider, and create a new one #2253

Open
vincenzopalazzo opened this issue Oct 25, 2024 · 1 comment

Comments

@vincenzopalazzo
Copy link

vincenzopalazzo commented Oct 25, 2024

I have the following code

use clap::Parser;

use opentelemetry_log::Opentelemetry;

#[derive(Debug, Parser)]
#[clap(name = "opentelemetry.rs")]
pub struct Args {
    #[clap(short, long, value_parser)]
    pub url: String,
    #[clap(short, long, value_parser)]
    pub message: String,
    #[clap(short, long)]
    pub level: String,
}

// the async main is not required by our application
// but the opentelemetry app is requiring to be
// in an async context, so we use this
#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let args = Args::parse();
    let url = args.url;

    let mut manager = Opentelemetry::new();
    manager.init_log("example", &args.level, &url)?;

    match args.level.as_str() {
        "info" => log::info!("{}", args.message),
        "debug" => log::debug!("{}", args.message),
        _ => anyhow::bail!("level `{}` not found", args.level),
    }
    drop(manager);

    let mut manager = Opentelemetry::new();
    manager.init_log("foo", &args.level, &url)?;

    match args.level.as_str() {
        "info" => log::info!("{}", args.message),
        "debug" => log::debug!("{}", args.message),
        _ => anyhow::bail!("level `{}` not found", args.level),
    }
    Ok(())
}

Where drop(mamager) is just https://github.com/vincenzopalazzo/opentelemetry-log/blob/main/src/lib.rs#L92

When dropping I get the following error

OpenTelemetry log error occurred. cannot send message to batch processor as the channel is closed Error: attempted to set a logger after the logging system was already initialized

A minimal reproducible example of the problem is vincenzopalazzo/opentelemetry-log#3

The use case of this is: Immagine that you have a kind of identifier (user identifier) and you need to switch when inside the application it is switching the profile. I am doing something wrong? or this is a real bug?

@cijothomas
Copy link
Member

Please share a https://stackoverflow.com/help/minimal-reproducible-example so we can investigate. We won't be able to look at external crates, please make sure to use components shipped from this repo only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants