1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- Object.defineProperty(exports, '__esModule', { value: true });
- const core = require('@sentry/core');
- const utils = require('@sentry/utils');
- const ACTION_BREADCRUMB_CATEGORY = 'redux.action';
- const ACTION_BREADCRUMB_TYPE = 'info';
- const defaultOptions = {
- attachReduxState: true,
- actionTransformer: action => action,
- stateTransformer: state => state || null,
- };
- function createReduxEnhancer(enhancerOptions) {
-
- const options = {
- ...defaultOptions,
- ...enhancerOptions,
- };
- return (next) =>
- (reducer, initialState) => {
- options.attachReduxState &&
- core.getGlobalScope().addEventProcessor((event, hint) => {
- try {
-
- if (event.type === undefined && event.contexts.state.state.type === 'redux') {
- hint.attachments = [
- ...(hint.attachments || []),
-
- { filename: 'redux_state.json', data: JSON.stringify(event.contexts.state.state.value) },
- ];
- }
- } catch (_) {
-
- }
- return event;
- });
- const sentryReducer = (state, action) => {
- const newState = reducer(state, action);
- const scope = core.getCurrentScope();
-
- const transformedAction = options.actionTransformer(action);
- if (typeof transformedAction !== 'undefined' && transformedAction !== null) {
- scope.addBreadcrumb({
- category: ACTION_BREADCRUMB_CATEGORY,
- data: transformedAction,
- type: ACTION_BREADCRUMB_TYPE,
- });
- }
-
- const transformedState = options.stateTransformer(newState);
- if (typeof transformedState !== 'undefined' && transformedState !== null) {
- const client = core.getClient();
- const options = client && client.getOptions();
- const normalizationDepth = (options && options.normalizeDepth) || 3;
-
- const newStateContext = { state: { type: 'redux', value: transformedState } };
- utils.addNonEnumerableProperty(
- newStateContext,
- '__sentry_override_normalization_depth__',
- 3 +
- normalizationDepth,
- );
- scope.setContext('state', newStateContext);
- } else {
- scope.setContext('state', null);
- }
-
- const { configureScopeWithState } = options;
- if (typeof configureScopeWithState === 'function') {
- configureScopeWithState(scope, newState);
- }
- return newState;
- };
- return next(sentryReducer, initialState);
- };
- }
- exports.createReduxEnhancer = createReduxEnhancer;
|