npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sandfox/redux-sentry-middleware

v0.1.4

Published

Redux middleware for propagating Redux state/actions to use with new @sentry/react-native

Downloads

4,171

Readme

Build Status Latest Version Downloads per month

Sentry Middleware for Redux

Fork of https://github.com/vidit-sh/redux-sentry-middleware

  • de-babel-ified, relies on react-native's implicit babel-ing of dependencies
  • de-travis'd
  • minor internal changes

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

It's a rewrite of raven-for-redux but with new Sentry unified APIs.

Installation

npm install --save @sandfox/redux-sentry-middleware

Usage

// store.js

import * as Sentry from "@sentry/browser"; 
// For usage with node 
// import * as Sentry from "@sentry/node";

import { createStore, applyMiddleware } from "redux";
import createSentryMiddleware from "@sandfox/redux-sentry-middleware";

import { reducer } from "./my_reducer";

Sentry.init({
  dsn: '<your dsn>'
});


export default createStore(
    reducer,
    applyMiddleware(
        // Middlewares, like `redux-thunk` that intercept or emit actions should
        // precede `redux-sentry-middleware`.
        createSentryMiddleware(Sentry, {
            // Optionally pass some options here.
        })
    )
);

API: createSentryMiddleware(Sentry, [options])

Arguments

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

Options

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

breadcrumbDataFromAction (Function)

Default: action => undefined

Sentry 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: undefined

By default the last action is not attached to the event as in some cases your actions may be extremely large, or contain sensitive data. If you want to optionally modify 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 [beforeSend] when you configured Sentry, note that actionTransformer will be applied before your specified beforeSend.

stateTransformer (Function)

Default: undefined

By default the state is not attached to the event as in some cases your state may be extremely large, or contain sensitive data. If you want optionally 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 [ beforeSend] when you configured Raven, note that stateTransformer will be applied before your specified beforeSend.

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.

getUserContext (Optional Function)

Signature: state => userContext

Sentry 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 [beforeSend] when you configured Raven, note that getUserContext will be applied before your specified beforeSend. When a getUserContext function is given, it will override any previously set user context.

getTags (Optional Function)

Signature: state => tags

Sentry 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.

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.