sentryR is an unofficial R SDK for Sentry. It includes an error handler for Plumber for uncaught exceptions.

Installation

You can install the current development version of sentryR with:

Using sentryR

configure_sentry and capture are the two core functions of sentryR. The first sets up an isolated environment with your Sentry project’s DSN, optionally your app’s name, version and the environment it’s running in. Both configure_sentry and any of the capture_ functions accept additional fields to pass on to Sentry as named lists. NULLifying a field will remove it.

library(sentryR)

configure_sentry(dsn = Sys.getenv("SENTRY_DSN"),
                 app_name = "myapp", app_version = "8.8.8",
                 environment = Sys.getenv("APP_ENV"),
                 tags = list(foo = "tag1", bar = "tag2"),
                 runtime = NULL)

capture(message = "my message", level = "info")

You are encouraged to use the two wrappers around capture included: capture_exception, which handles the error object and then reports the error to Sentry, and capture_message for transmitting messages. Refer to the Sentry docs for a full list of available fields.

By default sentryR will send the following fields to Sentry:

capture_exception further adds the exception field to the payload.

Example with Plumber

In a Plumber API, besides the initial configuration for Sentry, you’ll also have to set the error handler.

sentryR ships with the default plumber error handler wrapped in the convenience function sentry_error_handler, but you can use your own function and wrap it as below:

and wrap your endpoint functions with with_captured_calls

once this is done, Plumber will handle any errors, send them to Sentry using capture_exception, and respond with status 500 and the error message. You don’t need to do any further configuration.

Acknowledgements

sentryR took inspiration from raven-clj a Clojure interface to Sentry.

Contributing

PRs and issues are welcome! 🎉