Sentry (OCaml) - WORK IN PROGRESS
This is an unofficial work-in-progress Sentry library for
This currently requires the Async scheduler to be running or data will not
Only supports Async (pull requests to factor out Lwt/Unix are welcome!)
Global unhandled exception handler isn't implemented yet.
Probably other things
See the example program.
In general, you should use this like:
let () = let spec = Command.Spec.(...) in Command.async_spec ~summary:"..." spec @@ fun args () -> (* Using [SENTRY_DSN] from the environment *) Sentry.with_exn_handler @@ fun () -> (* your normal code here *)
To release the warning above: The Async schedule must be running.
This will execute your code as usual, and if it throws an exception, it will be
uploaded to Sentry:
Then the exception will be re-thrown so your program will exit and print the
backtrace to stderr as usual (if you want to continue after errors, wrap
Sentry.with_exn_handler in another error handler or use
Sentry.with_error_and_exn_handler exists (which handles both exceptions and
Or_error.t), but using exceptions exclusively is recommended because they have
backtraces (and wrapping exceptions in
Error.t loses whatever backtrace did
exist in most cases).
We upload some data by default. From environment variables, we get:
You can override any of these with
You can also upload custom tags using either
Sentry.merge_tags or by passing
~tags to a
capture function. Tags will be merged for the
current async job, so you only need to pass additional tags:
Sentry.merge_tags [ "app_name", "http_server" ]; Sentry.with_exn_handler @@ fun () -> ... Sentry.merge_tags [ "method", "GET", "path", "/example" ]; ... (* This will upload with default tags + app_name, method, path, and user_id *) Sentry.capture_message ~tags:[ "user_id", user_id ] "invalid login"
dev & >= "2.0.0"