Introduce raven_dart, a Dart client for Sentry

Presently sponsored by Serverless Guru: Your guide to cloud excellence, helping you every step of your serverless journey, including team training, pattern development, mass service migrations, architecting, and developing new solutions. Speak to a Guru today.

Since I’ve been experimenting with Sentry and hacking around in Dart again lately, so what better way is there to combine these two activities than to write a Dart client for Sentry?

That said, there is already a Javascript client library for Sentry, which via the dart:js library you can probably save yourself some code by writing a wrapper around the Javascript library instead. But I chose to write the client from scratch because:

  1. it’s more fun
  2. you can take advantage of Dart’s support for static type checking
  3. you can make use of Dart’s isolates (think F# mailbox or Erlang processes, isolates is Dart’s implementation of Carl Hewitt’s actor model) to abstract over making concurrent requests and handling retries, etc.
  4. wrapping the Javascript library means hard dependency on the Javascript library being present, which means you won’t be able to use it on the server side
  5. it’s more fun!


Update 05/07/2014 : I had previously stated that raven-js had dependencies on jQuery, ember, etc. that was incorrect. As they were in fact raven-js plugins for those frameworks (as stated in its Plugins documentation page here) and the raven-js itself doesn’t have any dependencies.


And the result is a small (~600 LOC) Dart library called raven_dart, that allows you to capture generic messages or exceptions as events in Sentry. The most basic usage would look like this:

Operational params can be used to customize the behaviour of captureMessage and captureException, such as adding tags, or other metadata to go along with the events.

Following the official guidelines on writing a Sentry client, the library supports:

  • DSN configuration via constructor argument
    • null means disabled
  • Graceful failure handling
    • fallback to logging to console when Sentry is disabled
    • retry on error (except for HTTP status codes 400, 401, 403, and 503)
    • configurable max no. of retries
    • exponential delay when retrying
    • temporarily disable if Sentry is unavailable (503)
  • Support for tagging
    • common tags can be provided in the client constructor
    • additional tags are supplied for each event
    • when common and event-specific tags overlap, both are sent as part of the event
  • Non-blocking event submission
    • events are sent to available isolates in round-robin fashion, whom then process them asynchronously and concurrently
    • configurable level of concurrency per core which determines number of isolates running at the same time
  • Basic data sanitization/scrubbing
    • credit card number-like fields are scrubbed
    • Sentry key and secrets are scrubbed
    • Values that look like passwords or secrets are scrubbed


Please give it a try and let me know what you think, if you find any bugs or have feedbacks in general, feel free to add them to the issues page.


Related Links

raven_dart homepage

raven_dart on

Libraries for C# and F# for easier integration with Sentry

Emulating F#’s discriminated unions (aka algebraic data types) in Dart

Emulating enums in Dart

Takeaways from Hewitt, Meijer and Szyperski’s talk on the Actor model

Leave a Comment

Your email address will not be published. Required fields are marked *