• Stars
    star
    295
  • Rank 140,211 (Top 3 %)
  • Language
    JavaScript
  • Created over 7 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Raven middleware for Redux

Travis Codecov .

Deprecated

Sentry now recommends using their new SDK @sentry/browser rather than Raven. Check out redux-sentry-middleware for an API compatible fork of this library that supports the new SDK!

Raven Middleware for Redux

Note: Requires Raven >= 3.9.0. Raven 3.14.0 has a bug which this library triggers

Logs the type of each dispatched action to Raven as "breadcrumbs" and attaches your last action and current Redux state as additional context.

Inspired by redux-raven-middleware but with a slightly different approach.

Installation

npm install --save raven-for-redux

Usage

Browser

// store.js

import Raven from "raven-js"; // Or, you might already have this as `window.Raven`.
import { createStore, applyMiddleware } from "redux";
import createRavenMiddleware from "raven-for-redux";

import { reducer } from "./my_reducer";

Raven.config("<YOUR_DSN>").install();

export default createStore(
    reducer,
    applyMiddleware(
        // Middlewares, like `redux-thunk` that intercept or emit actions should
        // precede `raven-for-redux`.
        createRavenMiddleware(Raven, {
            // Optionally pass some options here.
        })
    )
);

For a working example, see the example directory.

TypeScript

raven-for-redux has TypeScript bindings available through DefinitelyTyped. Please note the import style below, as it differs from the JavaScript example and is required for these typings.

import * as Raven from "raven-js";
import * as createRavenMiddleware from "raven-for-redux";
import { applyMiddleware, createStore } from "redux";

//... (same as JavaScript example, but now with proper typings)

Improvements

This library makes, what I think are, a few improvements over redux-raven-middlware:

  1. Raven is injected rather than being setup inside the middleware. This allows for more advanced configuration of Raven, as well as cases where Raven has already been initialized. For example, if you include Raven as its own <script> tag.
  2. Adds your state and last action as context to all errors, not just reducer exceptions.
  3. Allows filtering action breadcrumbs before sending to Sentry
  4. Allows you to define a user context mapping from the state

API: createRavenMiddleware(Raven, [options])

Arguments

  • Raven (Raven Object): A configured and "installed" Raven object.
  • [options] (Object): See below for detailed documentation.

Options

While the default configuration should work for most use cases, Raven for Redux can be configured by providing an options object with any of the following optional keys.

breadcrumbMessageFromAction (Function)

Default: action => action.type

breadcrumbMessageFromAction allows you to specify a transform function which is passed the action object and returns a string that will be used as the message of the breadcrumb.

By default breadcrumbMessageFromAction returns action.type.

Finally, be careful not to mutate your action within this function.

See the Sentry Breadcrumb documentation.

breadcrumbDataFromAction (Function)

Default: action => undefined

Raven allows you to attach additional context information to each breadcrumb in the form of a data object. breadcrumbDataFromAction allows you to specify a transform function which is passed the action object and returns a data object. Which will be logged to Sentry along with the breadcrumb.

Ideally we could log the entire content of each action. If we could, we could perfectly replay the user's entire session to see what went wrong.

However, the default implementation of this function returns undefined, which means no data is attached. This is because there are a few gotchas:

  • The data object must be "flat". In other words, each value of the object must be a string. The values may not be arrays or other objects.
  • Sentry limits the total size of your error report. If you send too much data, the error will not be recorded. If you are going to attach data to your breadcrumbs, be sure you understand the way it will affect the total size of your report.

Finally, be careful not to mutate your action within this function.

See the Sentry Breadcrumb documentation.

actionTransformer (Function)

Default: action => action

In some cases your actions may be extremely large, or contain sensitive data. In those cases, you may want to transform your action before sending it to Sentry. This function allows you to do so. It is passed the last dispatched action object, and should return a serializable value.

Be careful not to mutate your action within this function.

If you have specified a dataCallback when you configured Raven, note that actionTransformer will be applied before your specified dataCallback.

stateTransformer (Function)

Default: state => state

In some cases your state may be extremely large, or contain sensitive data. In those cases, you may want to transform your state before sending it to Sentry. This function allows you to do so. It is passed the current state object, and should return a serializable value.

Be careful not to mutate your state within this function.

If you have specified a dataCallback when you configured Raven, note that stateTransformer will be applied before your specified dataCallback.

breadcrumbCategory (String)

Default: "redux-action"

Each breadcrumb is assigned a category. By default all action breadcrumbs are given the category "redux-action". If you would prefer a different category name, specify it here.

filterBreadcrumbActions (Function)

Default: action => true

If your app has certain actions that you do not want to send to Sentry, pass a filter function in this option. If the filter returns a truthy value, the action will be added as a breadcrumb, otherwise the action will be ignored. Note: even when the action has been filtered out, it may still be sent to Sentry as part of the extra data, if it was the last action before an error.

This option was introduced in version 1.1.1.

getUserContext (Optional Function)

Signature: state => userContext

Raven allows you to associcate a user context with each error report. getUserContext allows you to define a mapping from your Redux state to the user context. When getUserContext is specified, the result of getUserContext will be used to derive the user context before sending an error report. Be careful not to mutate your state within this function.

If you have specified a dataCallback when you configured Raven, note that getUserContext will be applied before your specified dataCallback. When a getUserContext function is given, it will override any previously set user context.

This option was introduced in version 1.2.0.

getTags (Optional Function)

Signature: state => tags

Raven allows you to associate tags with each report. getTags allows you to define a mapping from your Redux state to an object of tags (key → value). Be careful not to mutate your state within this function.

This option was introduced in version 1.3.1.

Changelog

1.4.0

  • Add breadcrumbMessageFromAction method. (#98)

1.3.1

  • Add getTags option. (#69)

1.3.0

  • The Raven "extras" that we add are merged with existing extras rather than replacing them. (#59)

1.2.0

  • Add getUserContext option. (#49)

1.1.1

  • Add filterBreadcrumbActions option. (#39)

1.0.0

  • No changes. Just bringing the project out of beta.

0.7.1

  • Refactor: Use implicit binding to track the state/last action. (1def9a7)

0.7.0

  • Return the next middleware's (or the actual dispatch function's) return value. (#11)

0.6.0

  • actionTransformer and stateTransformer are only run when reporting an error, rather than on every action. (#8)

More Repositories

1

webamp

Winamp 2 reimplemented for the browser
TypeScript
9,999
star
2

grats

Implementation-First GraphQL for TypeScript
TypeScript
296
star
3

urlmeme

A meme generator where the URL is the user interface
JavaScript
118
star
4

codeception-mailcatcher-module

Test emails in your Codeception acceptance tests
PHP
111
star
5

dotfiles

My configuration files
Vim Script
91
star
6

hashbin

A paste bin that never sees the contents of its pastes
HTML
71
star
7

markdown.today

Store your journal as an encrypted markdown file on Dropbox and edit/view it from any browser
JavaScript
62
star
8

better-indent-support-for-php-with-html

This script allows you to indent HTML sections in PHP files
Vim Script
51
star
9

eel-wasm

Compile Nullsoft's EEL code to Web Assembly
TypeScript
48
star
10

vscode-implicit-parentheses

Clarify JavaScript operator precedence by showing implicit parentheses as inline decorations.
TypeScript
29
star
11

redux-to-relay-with-live-resolvers-example

Demonstrating migrating from Redux to Relay using Live Resolvers
JavaScript
22
star
12

transcode-to-mp3-stream

Php library for streaming various audio files as mp3 by transcoding on the fly
PHP
21
star
13

awesome-atwoods-law

A curated list of applications reimplemented in JavaScript
20
star
14

jerkll

A tiny(!) JavaScript clone of Jekyll inspired by RequireJS
JavaScript
20
star
15

mailcatcher-codeception-helper

Test emails in your Codeception acceptance tests
PHP
12
star
16

whatthefuckshouldibeforhalloween

What The Fuck Should I Be For Halloween
HTML
8
star
17

snake.js

A minimal JavaScript implementation of the game Snake
JavaScript
6
star
18

tdd-jest-backbone

An example of using Jest --watch to write/test a Backbone view
JavaScript
6
star
19

daniel.cash

Daniel Cash's (former) Website. Now offline.
HTML
5
star
20

lilypond-hub

An index of Lilypond scores on GitHub
5
star
21

pong-js

A very simple implementation of Pong in JS using Canvas and Web Audio API
JavaScript
4
star
22

uribin

A self-replicating paste bin that lives in URL shorteners
JavaScript
4
star
23

butterchurn

Butterchurn is a WebGL implementation of the Milkdrop Visualizer
JavaScript
4
star
24

winamp-skins

A collection of winamp skins for use with winamp2-js
4
star
25

eldredge-shepard_tone

Endlessly rising Shepard Tone Lilypond source file
4
star
26

jordaneldredge.com

My personal website
JavaScript
4
star
27

idle-chains

Generate Idle Thumbs episode descriptions using Markov Chain
Python
4
star
28

clusterfach-py

A recommendation engine
Python
3
star
29

hss-urlmeme

Post images to HSS chat rooms with ease
Python
3
star
30

PHP-Chord-Name-Parser

A class that parses musical chord names into their component notes
PHP
3
star
31

eslint-plugin-indexof

JavaScript
3
star
32

weighin-server

JavaScript
3
star
33

hex_game

Python
2
star
34

vim-vigilant

A Vim plugin to quickly spin off asyncronous Python tests in a Tmux Split
Vim Script
2
star
35

weighin-cli

JavaScript
2
star
36

singer-website

Code for my singer website
HTML
2
star
37

eslint-plugin-hss-i18n

Detect common errors when using I18n at Hearsay Social
JavaScript
2
star
38

fachme

JavaScript
2
star
39

grats-relay-example

Example project using Grats and Relay
TypeScript
2
star
40

guides

Documentation for routine tasks I used to have to continually look up
2
star
41

webamp-music

2
star
42

winamp-eqf

JavaScript library to parse Winamp equalizer files
JavaScript
2
star
43

eldredge-you_beside_my_side

Original barbershop tag typeset in Lilypond
2
star
44

online-ukulele-tuner

An online JavaScript Ukulele tuner
2
star
45

jpg.sexy

A clone of http://jpg.to
Python
2
star
46

vimrc-survey

Looking for the most common lines in .vimrc files on GitHub
Python
2
star
47

album-cover-generator

Randomly generated album covers
Perl
2
star
48

demo-app

A simple demo app created commit by commit with tutorial videos
JavaScript
1
star
49

myTodo

A vim syntax file for my todo.txt format
Vim Script
1
star
50

react-hello-world-es5

JavaScript
1
star
51

weighin-example

JavaScript
1
star
52

eldredge-our_love_will_last_as_long

Original doo-wop micro-song typeset using Lilypond
1
star
53

groundline

The groundline javascript library
1
star
54

beach-op_150_trio

Parts for Amy Beach's Piano Trio Op. 150
1
star
55

repo-vimrc

Keep per-repository .vimrc files in your .vim directory
Vim Script
1
star
56

skeleton-html

Easily bootstrap a front-end project
JavaScript
1
star
57

eldredge-dixie_land_parallel_fifths

Classic Barbershop tag typeset in parallel fifths in Lilypond
1
star
58

eslint-plugin-switch-literal

Disallow switching on string literals
JavaScript
1
star
59

redux-dropbox-middleware

Persist/rehydrate your redux state to/from Dropbox
JavaScript
1
star
60

gounod-le_crucifix

Lilypond engraving of Charles Gounod's choral work "Le Crucifix"
1
star
61

eldredge-nammies_four_hands

Lilypond engraving of a piano four-hands arrangement of Tom Hollow's bedtime song
1
star
62

blob

data dump
HTML
1
star
63

shouldibuybitcoin.today

A simple website where people can vote whether you should buy bitcoin today or not.
JavaScript
1
star
64

open-ani-online

Created with CodeSandbox
1
star
65

workshop-dotfiles

A minial set of dotfiles, useful as an introduction to vim
Vim Script
1
star
66

webvs

Audio Visualization rendering library for the browser
TypeScript
1
star
67

indigo

TypeScript
1
star
68

pixyll

A simple, beautiful Jekyll theme that's mobile first.
CSS
1
star
69

eldredge-thats_why_i_love_you

Rough transcription of "That's Why I Love You" by The Flamingos typeset using Lilypond
1
star
70

sadtrombone.vim

Trigger SadTrombone.com mp3 from within vim
Vim Script
1
star
71

llama

1
star
72

datejs

Automatically exported from code.google.com/p/datejs
JavaScript
1
star
73

intro-to-vim

Slides for my beginners Vim talk
JavaScript
1
star
74

crab_canon

The Crab Cannon from J.S. Bach's The Musical Offering
LilyPond
1
star
75

wedding-newspaper

1
star
76

eldredge-lazy_afternoon

Original barbershop tag typeset in Lilypond
1
star
77

twitter-limericks

Python
1
star
78

home

Use Github's issue tracker to track home repairs
1
star
79

solarsystem

CSS
1
star
80

throwaway

Testing if gitter will follow a repo to a new organization
1
star