gleam_sentry

Report runtime exceptions to https://sentry.io

Usage

Intialise a client with your DSN and environment name.

  import gleam_sentry as sentry

  let dsn = "https://public_key@o0.ingest.sentry.io/123"
  let environment = "production"
  assert Ok(client) = sentry.init(dsn, environment)

Capture an exception

sentry.capture_exception(client, reason, stacktrace, timestamp)

The types for reason and stacktrace are defined in the gleam/beam project along with cast functions that allow you to get these values form logger events.

Logger integration

// my_app/logger.gleam
import gleam/beam.{ExitReason, Stacktrace}

pub fn handle(client, reason: ExitReason, stacktrace: Stacktrace, timestamp) {
  sentry.capture_exception(client, reason, stacktrace, timestamp)
  Nil
}
// During startup
import gleam/beam/logger
import my_app/logger as my_logger

pub fn start(){
  logger.add_handler(my_logger.handle(client, _, _, _))
}

Future

gleam_sentry currently reports errors from the beam runtime system, and as such could be implemented as an erlang library. I have not used existing projects (see prior art below) as only Elixir projects are based on the new logger.

I would like this project to be useful in erlang projects. It would also be interesting to have a more general purpose span/context/error handling framework that this could plug in to.

Prior Art

Raven

https://github.com/artemeff/raven-erlang

erlang project, integrates with lager and error_logger.

Sparrow

https://github.com/ExpressApp/sparrow/tree/master/lib/sparrow

Elixir project, uses new logger