Skip to content

docs: Update Rust docs and snippets for upcoming release #1765

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

Merged
merged 6 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions __tests__/__snapshots__/documentation.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,7 @@ Array [
"platforms/react-native/ram-bundles/index.html",
"platforms/react-native/sourcemaps/index.html",
"platforms/rust/actix/index.html",
"platforms/rust/env_logger/index.html",
"platforms/rust/error_chain/index.html",
"platforms/rust/failure/index.html",
"platforms/rust/index.html",
"platforms/rust/log/index.html",
"platforms/rust/panic/index.html",
"project-resources/index.html",
"sdks/javascript/index.html",
"sitemap.xml",
Expand Down
2 changes: 1 addition & 1 deletion src/_data/platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@
name: Rust
wizard_parent: rust
wizard: true
version: 0.6.0
version: 0.19.0
version_key: SENTRY_VERSION
case_style: snake_case
-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
```rust
use sentry::{Level, with_scope};
use sentry::integrations::failure::capture_error;
use failure::err_msg;

with_scope(|scope| {
sentry::with_scope(|scope| {
scope.set_tag("my-tag", "my value");
scope.set_level(Some(Level::Warning));
}, || {
// will be tagged with my-tag="my value"
capture_error(err_msg("my error"))
sentry::capture_message("my error", sentry::Level::Error)
});

// will not be tagged with my-tag
capture_error(err_msg("my other error"))
sentry::capture_message("my other error", sentry::Level::Error)
```

*Note that in Rust two callbacks are invoked. One for configuring the scope, and a second
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
In Rust you can capture errors that implement the `Fail` trait or that are `failure::Error`
objects:
In Rust, you can capture any `std::error::Error` type.

```rust
use sentry::integrations::failure::capture_error;
let result = match function_returns_error() {
Ok(result) => result,
Err(err) => {
sentry::capture_error(&err);
return Err(err);
}
};
```

Integrations may provide more specialized capturing methods.

```rust
use sentry::integrations::anyhow::capture_anyhow;

let result = match function_that_might_fail() {
let result = match function_returns_anyhow() {
Ok(result) => result,
Err(err) => {
capture_error(&err);
capture_anyhow(&err);
return Err(err);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
```rust
use sentry::{capture_message, Level};

capture_message("Something went wrong", Level::Info);
sentry::capture_message("Something went wrong", sentry::Level::Info);
```
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
```rust
sentry::init(sentry::ClientOptions {
before_send: Some(Arc::new(Box::new(|mut event| {
before_send: Some(Arc::new(|mut event| {
// Modify event here
event.server_name = None; // Don't send server name
Some(event)
}))),
})),
..Default::default()
});
```
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Options are passed to the `init()` as tuple where the first argument is the DSN and the second the options:

```rust
use sentry;

sentry::init(("___PUBLIC_DSN___", sentry::ClientOptions {
max_breadcrumbs: 50,
debug: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ the guard and make sure it disposes on shutdown. Alternatively the client can b

```rust
use std::time::Duration;
use sentry::Hub;

if let Some(client) = Hub.current().client() {
if let Some(client) = sentry::Hub::current().client() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd slightly prefer to keep the import.

client.close(Some(Duration::from_secs(2)));
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ happen as part of the `init()` call, in some others, different patterns apply.
{:.config-key}
### `integrations`

{% unsupported csharp aspnetcore rust %}
{% unsupported csharp aspnetcore %}
In some SDKs, the integrations are configured through this parameter on library initialization.
For more information, have a look at the specific integration documentation.
{% endunsupported %}

{:.config-key}
### `default-integrations`

{% unsupported csharp aspnetcore rust %}
{% unsupported csharp aspnetcore %}
This can be used to disable integrations that are added by default. When set to `false` no
default integrations are added.
{% endunsupported %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ The quickest way to verify Sentry in your Rust application is to cause a panic:

```rust
fn main() {
// Initialize sentry here

sentry::integrations::panic::register_panic_handler();
let _guard = sentry::init("___PUBLIC_DSN___");

// Sentry will capture this
panic!("Everything is on fire!");
Expand Down
3 changes: 1 addition & 2 deletions src/collections/_documentation/platforms/rust/actix.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ In your `Cargo.toml`:
```toml
[dependencies]
sentry = "{% sdk_version sentry.rust %}"
sentry-actix = "{% package_version cargo:sentry-actix %}"
sentry-actix = "{% sdk_version sentry.rust %}"
```

And your Rust code:
Expand All @@ -45,7 +45,6 @@ fn failing(_req: &HttpRequest) -> Result<String, Error> {
fn main() {
let _guard = sentry::init("___PUBLIC_DSN___");
env::set_var("RUST_BACKTRACE", "1");
sentry::integrations::panic::register_panic_handler();

server::new(|| {
App::new()
Expand Down
27 changes: 0 additions & 27 deletions src/collections/_documentation/platforms/rust/env_logger.md

This file was deleted.

33 changes: 0 additions & 33 deletions src/collections/_documentation/platforms/rust/error_chain.md

This file was deleted.

29 changes: 0 additions & 29 deletions src/collections/_documentation/platforms/rust/failure.md

This file was deleted.

34 changes: 12 additions & 22 deletions src/collections/_documentation/platforms/rust/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,26 @@ protocol for Rust and provides convenient helpers for sending common types of
events to Sentry.

The Rust SDK follows the new unified SDK architecture. To get started have a
look at the [quickstart](/error-reporting/quickstart/?platform=rust) docs.
look at the [quickstart](/error-reporting/quickstart/?platform=rust) docs and the crates [API Docs](https://docs.rs/sentry).

## Quick Start

```rust
let _guard = sentry::init("___PUBLIC_DSN___");
sentry::capture_message("Hello World!", sentry::Level::Info);
```

## Integrations

*Integrations* extend the functionality of the SDK for some common frameworks
and libraries.

### Framework integrations

Sentry-Rust supports the following application frameworks:

* [actix-web](/platforms/rust/actix/)

### Error handling integrations

Sentry-Rust supports the most commonly used libraries for advanced error management:

* [failure](/platforms/rust/failure/)
* [error-chain](/platforms/rust/error_chain/)

Additionally you can catch panics using the panic integration:

* [panic](/platforms/rust/panic/)

### Logging integrations
A list of integrations and their feature flags can be found
[in the integration API docs](https://docs.rs/sentry/0/sentry/integrations/index.html).

Logs can be automatically converted into breadcrumbs.
Apart from those, the Rust SDK also supports the following application frameworks:

* [env_logger](/platforms/rust/env_logger/)
* [log](/platforms/rust/log/)
* [actix-web 0.7](/platforms/rust/actix/)

## More Information

Expand Down
34 changes: 0 additions & 34 deletions src/collections/_documentation/platforms/rust/log.md

This file was deleted.

18 changes: 0 additions & 18 deletions src/collections/_documentation/platforms/rust/panic.md

This file was deleted.