Skip to content

Enable additional context to be sent as part of the error via the request object. #1787

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

Closed
wants to merge 3 commits into from

Conversation

forrestmid
Copy link

@forrestmid forrestmid commented Dec 7, 2018

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

I'm not entirely sure whether this should be tested or not. It's a relatively trivial change for some behavior that could potentially cause some significant issues (if a user passed a function as part of the object and all that).

@kamilogorek
Copy link
Contributor

You can already achieve this behavior with the code below after your requestHandler.

function sentryExtraContextMiddleware(req, res, next) {
  Sentry.getCurrentHub().configureScope(scope =>
    scope.addEventProcessor(async event => {
      if (Object.prototype.toString.call(req.extraContext) === '[object Object]') {
        event.extra = {
          ...event.extra,
          ...req.extraContext,
        };
      }
      return event;
    }),
  );

  next();
}

app.use(sentryExtraContextMiddleware);

We don't want to add custom attributes to the request itself, as we'd have to keep documentation in-sync, as well as provide this feature for every framework.

@forrestmid
Copy link
Author

@kamilogorek That is exactly what I needed. Thanks!

@kamilogorek
Copy link
Contributor

Anytime!

@kamilogorek kamilogorek closed this Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants