Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add breadcrumbMessageFromAction option to handle a message of breadcrumb #98

Merged
merged 2 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ 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`
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const identity = x => x;
const getUndefined = () => {};
const getType = action => action.type;
const filter = () => true;
function createRavenMiddleware(Raven, options = {}) {
// TODO: Validate options.
const {
breadcrumbDataFromAction = getUndefined,
breadcrumbMessageFromAction = getType,
actionTransformer = identity,
stateTransformer = identity,
breadcrumbCategory = "redux-action",
Expand Down Expand Up @@ -38,7 +40,7 @@ function createRavenMiddleware(Raven, options = {}) {
if (filterBreadcrumbActions(action)) {
Raven.captureBreadcrumb({
category: breadcrumbCategory,
message: action.type,
message: breadcrumbMessageFromAction(action),
data: breadcrumbDataFromAction(action)
});
}
Expand Down
8 changes: 8 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ describe("raven-for-redux", () => {
context.breadcrumbDataFromAction = jest.fn(action => ({
extra: action.extra
}));
context.breadcrumbMessageFromAction = jest.fn(
action => `transformed action ${action.type}`
);
context.filterBreadcrumbActions = action => {
return action.type !== "UNINTERESTING_ACTION";
};
Expand All @@ -211,6 +214,7 @@ describe("raven-for-redux", () => {
stateTransformer: context.stateTransformer,
actionTransformer: context.actionTransformer,
breadcrumbDataFromAction: context.breadcrumbDataFromAction,
breadcrumbMessageFromAction: context.breadcrumbMessageFromAction,
filterBreadcrumbActions: context.filterBreadcrumbActions,
getUserContext: context.getUserContext,
getTags: context.getTags
Expand Down Expand Up @@ -252,7 +256,11 @@ describe("raven-for-redux", () => {
expect(context.mockTransport).toHaveBeenCalledTimes(1);
const { breadcrumbs } = context.mockTransport.mock.calls[0][0].data;
expect(breadcrumbs.values.length).toBe(2);
expect(breadcrumbs.values[0].message).toBe(
"transformed action INCREMENT"
);
expect(breadcrumbs.values[0].data).toMatchObject({ extra: "FOO" });
expect(breadcrumbs.values[1].message).toBe("transformed action THROW");
expect(breadcrumbs.values[1].data).toMatchObject({ extra: "BAR" });
});
it("transforms the user context on data callback", () => {
Expand Down