compute-rust-sentry

Crates.iocompute-rust-sentry
lib.rscompute-rust-sentry
version0.1.3
sourcesrc
created_at2023-04-21 15:19:40.117049
updated_at2024-11-01 16:06:14.938394
descriptionSend error reports from Compute@Edge to Sentry
homepage
repositoryhttps://github.com/fastly/compute-rust-sentry
max_upload_size
id845386
size454,739
Kailan Blanks (kailan)

documentation

README

compute-rust-sentry

Send error reports to Sentry from Fastly Compute services written in Rust.

A screenshot of the Sentry dashboard displaying an error in a Compute@Edge application

Usage

Add the crate to your Cargo.toml:

compute-rust-sentry = "0.1.1"

Configure the sentry backend locally (optional):

[local_server]

  [local_server.backends]

    [local_server.backends.sentry]
      url = "https://o122324.ingest.sentry.io"

Configure the sentry backend on your Fastly service:

$ fastly backend create --address o122324.ingest.sentry.io --version latest --autoclone

Wrap your main logic with an error handler in order to catch exceptions:

#[fastly::main]
fn main(req: Request) -> Result<Response, fastly::Error> {
    // Clone the request metadata so it can be attached to any reports later.
    let req_metadata = req.clone_without_body().with_header(header::COOKIE, "REDACTED");

    let raven = Raven::from_dsn_and_backend(
        Url::parse(
            "https://abcdef@o122324.ingest.sentry.io/1234",
        )?,
        "sentry",
    );

    match handle_request(req) {
      Ok(resp) => Ok(resp),
      Err(err) => {
          raven.report_error(err, &req_metadata)?;
          Ok(Response::from_status(500))
      }
    }
}

fn handle_request(req: Request) -> Result<Response, fastly::Error> {
    let beresp = req.send("origin_0")?;
    Ok(beresp)
}

Re-deploy your application, trigger an error, and check the Sentry dashboard for the error report:

$ fastly compute publish
Commit count: 10

cargo fmt