#sentry #error #reports #send #compute-edge #back-end #service

compute-rust-sentry

将 Compute@Edge 的错误报告发送到 Sentry

1 个不稳定版本

0.1.2 2023年4月21日

#4 in #compute-edge

MIT 许可证

410KB
149

compute-rust-sentry

将 Rust Compute@Edge 服务的错误报告发送到 Sentry。

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

用法

将 crate 添加到您的 Cargo.toml

compute-rust-sentry = "0.1.1"

本地配置 sentry 后端(可选)

[local_server]

  [local_server.backends]

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

在您的 Fastly 服务上配置 sentry 后端

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

使用错误处理程序包裹主逻辑以捕获异常

#[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://[email protected]/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)
}

重新部署应用程序,触发错误,并在 Sentry 仪表板中检查错误报告

$ fastly compute publish

依赖关系

~6MB
~136K SLoC