getsentry / sentry-rust

Official Sentry SDK for Rust
https://sentry.io/
Apache License 2.0
620 stars 153 forks source link

Setup Instructions not working in Rust 1.80.1 #684

Closed PJUllrich closed 1 month ago

PJUllrich commented 1 month ago

Environment

Rust: 1.80.1 Sentry: 0.34.0

Steps to Reproduce

I'm building a Trauri app and I copy&pasted the setup instructions into my main.rs:

let _guard = sentry::init(("my-dsn", sentry::ClientOptions {
  release: sentry::release_name!(),
  ..Default::default()
}));
   | ^^^ consider using `const` or `static` instead of `let` for global variables

However, the Rust compiler complains and I can't get it to work. These are some code variations and the errors I've encountered:

Replace let with const or static

const _guard = sentry::init(("my-dsn", sentry::ClientOptions {
  release: sentry::release_name!(),
  ..Default::default()
}));
cannot call non-const fn `sentry::init::<(&str, ClientOptions)>` in statics

Remove let altogether

sentry::init(("my-dsn", sentry::ClientOptions {
  release: sentry::release_name!(),
  ..Default::default()
}));
sentry::init(("my-dsn", ....
            ^ expected one of `!` or `::`

Remove duplicate bracket

sentry::init("my-dsn", sentry::ClientOptions {
  release: sentry::release_name!(),
  ..Default::default()
});
sentry::init("my-dsn", ....
            ^ expected one of `!` or `::`

Remove ClientOptions

sentry::init( "my-dsn" );
   |  sentry::init( "my-dsn" );
   |              ^ expected one of `!` or `::`

Expected Result

The setup instructions work.

Actual Result

They don't work.

ReactorScram commented 1 month ago

You have it inside fn main(), right? You can't do let assignments outside of a function

PJUllrich commented 1 month ago

Ah sorry, my mistake. I added it outside the fn main() function. Now, I see that you also show that in the setup instructions. My bad! Thanks for the reply ❤