Skip to content

Commit a3f138b

Browse files
Nikita Mostovoycaptbaritone
authored andcommitted
Add breadcrumbMessageFromAction option to handle a message of breadcrumb (#98)
* add breadcrumbMessageFromAction * fix review notes of breadcrumbMessageFromAction option
1 parent 0ab4e52 commit a3f138b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ While the default configuration should work for most use cases, Raven for Redux
8181
can be configured by providing an options object with any of the following
8282
optional keys.
8383

84+
#### `breadcrumbMessageFromAction` _(Function)_
85+
86+
Default: `action => action.type`
87+
88+
`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.
89+
90+
By default `breadcrumbMessageFromAction` returns `action.type`.
91+
92+
Finally, be careful not to mutate your `action` within this function.
93+
94+
See the Sentry [Breadcrumb documentation].
95+
8496
#### `breadcrumbDataFromAction` _(Function)_
8597

8698
Default: `action => undefined`

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const identity = x => x;
22
const getUndefined = () => {};
3+
const getType = action => action.type;
34
const filter = () => true;
45
function createRavenMiddleware(Raven, options = {}) {
56
// TODO: Validate options.
67
const {
78
breadcrumbDataFromAction = getUndefined,
9+
breadcrumbMessageFromAction = getType,
810
actionTransformer = identity,
911
stateTransformer = identity,
1012
breadcrumbCategory = "redux-action",
@@ -38,7 +40,7 @@ function createRavenMiddleware(Raven, options = {}) {
3840
if (filterBreadcrumbActions(action)) {
3941
Raven.captureBreadcrumb({
4042
category: breadcrumbCategory,
41-
message: action.type,
43+
message: breadcrumbMessageFromAction(action),
4244
data: breadcrumbDataFromAction(action)
4345
});
4446
}

index.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ describe("raven-for-redux", () => {
200200
context.breadcrumbDataFromAction = jest.fn(action => ({
201201
extra: action.extra
202202
}));
203+
context.breadcrumbMessageFromAction = jest.fn(
204+
action => `transformed action ${action.type}`
205+
);
203206
context.filterBreadcrumbActions = action => {
204207
return action.type !== "UNINTERESTING_ACTION";
205208
};
@@ -211,6 +214,7 @@ describe("raven-for-redux", () => {
211214
stateTransformer: context.stateTransformer,
212215
actionTransformer: context.actionTransformer,
213216
breadcrumbDataFromAction: context.breadcrumbDataFromAction,
217+
breadcrumbMessageFromAction: context.breadcrumbMessageFromAction,
214218
filterBreadcrumbActions: context.filterBreadcrumbActions,
215219
getUserContext: context.getUserContext,
216220
getTags: context.getTags
@@ -252,7 +256,11 @@ describe("raven-for-redux", () => {
252256
expect(context.mockTransport).toHaveBeenCalledTimes(1);
253257
const { breadcrumbs } = context.mockTransport.mock.calls[0][0].data;
254258
expect(breadcrumbs.values.length).toBe(2);
259+
expect(breadcrumbs.values[0].message).toBe(
260+
"transformed action INCREMENT"
261+
);
255262
expect(breadcrumbs.values[0].data).toMatchObject({ extra: "FOO" });
263+
expect(breadcrumbs.values[1].message).toBe("transformed action THROW");
256264
expect(breadcrumbs.values[1].data).toMatchObject({ extra: "BAR" });
257265
});
258266
it("transforms the user context on data callback", () => {

0 commit comments

Comments
 (0)