An open API service indexing awesome lists of open source software.

https://github.com/ellmetha/marten-raven-middleware

Raven.cr integration for the Marten web framework.
https://github.com/ellmetha/marten-raven-middleware

crystal framework marten raven sentry sentry-client web

Last synced: 28 days ago
JSON representation

Raven.cr integration for the Marten web framework.

Awesome Lists containing this project

README

        

# Marten Raven Middleware

[![CI](https://github.com/ellmetha/marten-raven-middleware/workflows/Specs/badge.svg)](https://github.com/ellmetha/marten-raven-middleware/actions)
[![CI](https://github.com/ellmetha/marten-raven-middleware/workflows/QA/badge.svg)](https://github.com/ellmetha/marten-raven-middleware/actions)

**Marten Raven Middleware** provides a [Raven.cr](https://github.com/Sija/raven.cr) integration that allows you to get automatic error reporting for the [Marten web framework](https://github.com/martenframework/marten) by using a dedicated [middleware](https://martenframework.com/docs/handlers-and-http/middlewares).

## Installation

Simply add the following entry to your project's `shard.yml`:

```yaml
dependencies:
marten_raven_middleware:
github: ellmetha/marten-raven-middleware
```

And run `shards install` afterward.

## Configuration

First, add the following requirement to your project's `src/project.cr` file:

```crystal
require "marten_raven_middleware"
```

You should then ensure that Raven.cr is [properly configured](https://github.com/Sija/raven.cr#usage). In a Marten project, you'll likely create a `config/initializers/raven.cr` initializer where you require and configure the Raven client for your project. For example:

```crystal
# config/initializers/raven.cr

require "raven"

Raven.configure do |config|
config.dsn = "your_dsn"
end
```

To get automatic error reporting for your project, you then need to add the `Raven::Marten::Middleware` middleware class to the [`middleware`](https://martenframework.com/docs/development/reference/settings#middleware) Marten setting. Ideally, this middleware should be placed near the beginning of the `middleware` array to ensure that it can catch any errors raised by the following middlewares in the stack. For example:

```crystal
# config/settings/base.cr

Marten.configure do |config|
config.middleware = [
Raven::Marten::Middleware,
# Other middlewares...
Marten::Middleware::GZip,
Marten::Middleware::XFrameOptions,
Marten::Middleware::StrictTransportSecurity,
]
end
```

That's it! From now on every exception that is raised by your handlers and middlewares will be reported to Sentry automatically.

## Authors

Morgan Aubert ([@ellmetha](https://github.com/ellmetha)) and
[contributors](https://github.com/ellmetha/marten-raven-middleware/contributors).

## License

MIT. See ``LICENSE`` for more details.