From bb82c2b6b7c6527dea5f316b8c4aa834e6ed8c48 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Mon, 14 Aug 2023 17:10:24 +0200 Subject: [PATCH 1/7] fix(rust): Add warning about #[tokio::main] --- src/platforms/rust/index.mdx | 40 +++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/platforms/rust/index.mdx b/src/platforms/rust/index.mdx index 18f3040b14d37..f14c0d05d4893 100644 --- a/src/platforms/rust/index.mdx +++ b/src/platforms/rust/index.mdx @@ -32,7 +32,7 @@ sentry = "{{@inject packages.version('sentry.rust') }}" The most convenient way to use this library is the `sentry::init` function, which starts a Sentry client with a default set of integrations, and binds it to the current Hub. -The `sentry::init` function returns a guard that, when dropped, will flush Events that were not yet sent to the Sentry service. It has a two second deadline for this, so shutdown of applications might slightly delay as a result. Keeping the guard around or sending events will not work. +The `sentry::init` function returns a guard that, when dropped, will flush Events that were not yet sent to the Sentry service. It has a two second deadline for this, so shutdown of applications might slightly delay as a result. Keep the guard around or sending events will not work. @@ -45,6 +45,44 @@ let _guard = sentry::init(("___PUBLIC_DSN___", sentry::ClientOptions { **Important:** Note your DSN. The DSN (Data Source Name) tells the SDK where to send events. If you forget it, view Settings -> Projects -> Client Keys (DSN) in sentry.io. +### Async main function + +The Sentry client must be initialized before any async runtime is started or threads are spawned. Unfortunately, this makes it impossible to use macros such as `#[tokio::main]` or `#[actix_web::main]`, because they start the runtime first. Thus, instead of + +```rust {filename:main.rs} +// WRONG +#[tokio::main] +async fn main() { +let _guard = sentry::init(("___PUBLIC_DSN___", sentry::ClientOptions { + release: sentry::release_name!(), + ..Default::default() +})); + +// implementation of main +} +``` + +do this: + +```rust {filename:main.rs} +// RIGHT +fn main() { +let _guard = sentry::init(("___PUBLIC_DSN___", sentry::ClientOptions { + release: sentry::release_name!(), + ..Default::default() +})); + +tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() + .block_on(async { + // implementation of main + }); +} +``` + + ## Verify Setup The quickest way to verify Sentry in your Rust application is to cause a panic: From 22a786625e80372dccaa4bc80397896713b04d18 Mon Sep 17 00:00:00 2001 From: "getsantry[bot]" <66042841+getsantry[bot]@users.noreply.github.com> Date: Mon, 14 Aug 2023 15:14:33 +0000 Subject: [PATCH 2/7] style(lint): Auto commit lint changes --- src/platforms/rust/index.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/platforms/rust/index.mdx b/src/platforms/rust/index.mdx index f14c0d05d4893..d8ad77d39d79c 100644 --- a/src/platforms/rust/index.mdx +++ b/src/platforms/rust/index.mdx @@ -82,7 +82,6 @@ tokio::runtime::Builder::new_multi_thread() } ``` - ## Verify Setup The quickest way to verify Sentry in your Rust application is to cause a panic: From 9fbbdda47f10ab72a84e79b14e34a7db75ede4f4 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 16 Aug 2023 08:58:56 +0200 Subject: [PATCH 3/7] Update src/platforms/rust/index.mdx Co-authored-by: Liza Mock --- src/platforms/rust/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/rust/index.mdx b/src/platforms/rust/index.mdx index d8ad77d39d79c..b2a1ae455f33c 100644 --- a/src/platforms/rust/index.mdx +++ b/src/platforms/rust/index.mdx @@ -32,7 +32,7 @@ sentry = "{{@inject packages.version('sentry.rust') }}" The most convenient way to use this library is the `sentry::init` function, which starts a Sentry client with a default set of integrations, and binds it to the current Hub. -The `sentry::init` function returns a guard that, when dropped, will flush Events that were not yet sent to the Sentry service. It has a two second deadline for this, so shutdown of applications might slightly delay as a result. Keep the guard around or sending events will not work. +The `sentry::init` function returns a guard that when dropped, will flush Events that weren't yet sent to Sentry. It has a two-second deadline, so application shutdown may be slightly delayed as a result. Be sure to keep the guard or you won't be able to send events. From 0c9995fe64b9da7c755c2dc604e36b7cb56c66b1 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 16 Aug 2023 08:59:05 +0200 Subject: [PATCH 4/7] Update src/platforms/rust/index.mdx Co-authored-by: Liza Mock --- src/platforms/rust/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/rust/index.mdx b/src/platforms/rust/index.mdx index b2a1ae455f33c..6aa32c1aa56f9 100644 --- a/src/platforms/rust/index.mdx +++ b/src/platforms/rust/index.mdx @@ -45,7 +45,7 @@ let _guard = sentry::init(("___PUBLIC_DSN___", sentry::ClientOptions { **Important:** Note your DSN. The DSN (Data Source Name) tells the SDK where to send events. If you forget it, view Settings -> Projects -> Client Keys (DSN) in sentry.io. -### Async main function +### Async Main Function The Sentry client must be initialized before any async runtime is started or threads are spawned. Unfortunately, this makes it impossible to use macros such as `#[tokio::main]` or `#[actix_web::main]`, because they start the runtime first. Thus, instead of From 7809adee2dcc4b2cd9f395208afa0415ba159554 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 16 Aug 2023 08:59:16 +0200 Subject: [PATCH 5/7] Update src/platforms/rust/index.mdx Co-authored-by: Liza Mock --- src/platforms/rust/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/rust/index.mdx b/src/platforms/rust/index.mdx index 6aa32c1aa56f9..6e4e552effe2e 100644 --- a/src/platforms/rust/index.mdx +++ b/src/platforms/rust/index.mdx @@ -43,7 +43,7 @@ let _guard = sentry::init(("___PUBLIC_DSN___", sentry::ClientOptions { })); ``` -**Important:** Note your DSN. The DSN (Data Source Name) tells the SDK where to send events. If you forget it, view Settings -> Projects -> Client Keys (DSN) in sentry.io. +**Important:** Remember your DSN. The DSN (Data Source Name) tells the SDK where to send events. If you forget it you can find it be going to: Settings -> Projects -> Client Keys (DSN) in sentry.io. ### Async Main Function From 136772dc9a7e2efd074ade06a0485eda51b9398f Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 16 Aug 2023 09:02:25 +0200 Subject: [PATCH 6/7] Update src/platforms/rust/index.mdx Co-authored-by: Liza Mock --- src/platforms/rust/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/rust/index.mdx b/src/platforms/rust/index.mdx index 6e4e552effe2e..159c53770732d 100644 --- a/src/platforms/rust/index.mdx +++ b/src/platforms/rust/index.mdx @@ -62,7 +62,7 @@ let _guard = sentry::init(("___PUBLIC_DSN___", sentry::ClientOptions { } ``` -do this: +Do this instead: ```rust {filename:main.rs} // RIGHT From 5b1328743c41499e457ebd97cfd859ff2b26d0d6 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 16 Aug 2023 10:32:05 +0200 Subject: [PATCH 7/7] Rewrite paragraph --- src/platforms/rust/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/rust/index.mdx b/src/platforms/rust/index.mdx index 159c53770732d..fd9ff196ba411 100644 --- a/src/platforms/rust/index.mdx +++ b/src/platforms/rust/index.mdx @@ -47,7 +47,7 @@ let _guard = sentry::init(("___PUBLIC_DSN___", sentry::ClientOptions { ### Async Main Function -The Sentry client must be initialized before any async runtime is started or threads are spawned. Unfortunately, this makes it impossible to use macros such as `#[tokio::main]` or `#[actix_web::main]`, because they start the runtime first. Thus, instead of +In a multithreaded application, spawned threads should inherit the Hub from the main thread. In order for that to happen, the Sentry client must be initialized before starting an async runtime or spawning threads. This means you'll have to avoid using macros such as `#[tokio::main]` or `#[actix_web::main]`, because they start the runtime first. So rather than doing this: ```rust {filename:main.rs} // WRONG