sentry-rust: Logs and errors are not showing up in web interface

Environment

sentry version “0.30.0” with feature “anyhow” enabled sentry-log “0.31.5”

Steps to Reproduce

early in main.rs

  let logger = sentry_log::SentryLogger::with_dest(env_logger::builder().build());

  log::set_boxed_logger(Box::new(logger)).unwrap();
  log::set_max_level(secrets.log_level.clone().into());

  let _guard = sentry::init((
      "my dsn",
      ClientOptions {
          release: sentry::release_name!(),
          environment: Some(secrets.environment.to_string().into()),
          sample_rate: secrets.sentry_sample_rate.parse::<f32>().unwrap_or(0.0),
          ..Default::default()
      },
  ));

in cargo.toml

sentry = { version = "0.30.0", features = ["anyhow"] }
sentry-log = "0.31.5"

using the normal log macros ( info!(), warn!(), error!() ), we’re not seeing these errors appear in sentry. Instead, we’ve been using the capture_anyhow!() macro however the insights we get aren’t the best causing debugging issues to be very slow. I’ve seen mixing documentation or lack thereof around integrations regarding this crate but nothing I’ve tried seemed to resolve this. We know errors are occurring because of logs in production. The implementation above is from the example on docs.rs, perhaps this should be updated?

Expected Result

We see errors and breadcrumbs appear in sentry when they occur.

Actual Result

Errors aren’t appearing in sentry

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 26 (13 by maintainers)

Most upvoted comments

Using #[tokio::main] may be the issue. We’re currently updating our documentation to explain why that shouldn’t be done and what to do instead. The problem is that sentry::init must be called before the async runtime is started, but #[tokio::main] prevents that.

Can you rewrite main to a form like this?

fn main() {
  let _guard = sentry::init((
      "my dsn",
      ClientOptions {
          release: sentry::release_name!(),
          environment: Some(secrets.environment.to_string().into()),
          sample_rate: secrets.sentry_sample_rate.parse::<f32>().unwrap_or(0.0),
          ..Default::default()
      },
  ));

  let logger = sentry_log::SentryLogger::with_dest(env_logger::builder().build());

  log::set_boxed_logger(Box::new(logger)).unwrap();
  log::set_max_level(secrets.log_level.clone().into());

  tokio::runtime::Builder::new_multi_thread()
        .enable_all()
        .build()
        .unwrap()
        .block_on(async {
            // the rest of main
        });
}