Skip to content

event.transaction reports wrong URL when Express is used with a Router #3004

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
Rush opened this issue Apr 13, 2020 · 1 comment · Fixed by #3084
Closed

event.transaction reports wrong URL when Express is used with a Router #3004

Rush opened this issue Apr 13, 2020 · 1 comment · Fixed by #3084
Assignees

Comments

@Rush
Copy link

Rush commented Apr 13, 2020

Important Details

How are you running Sentry? @sentry/[email protected]
Environment: N/A, can reproduce both locally, in docker and anywhere else

Description

When doing:

const router = new Router();
router.get('/bar', (req, res, next) => {  next(new Errror('Foo'));  });
app.use('/foo', someOtherRouter);

sentry would set the event.transaction to /bar as this is what req.url will point to.

See this doc.
https://expressjs.com/en/api.html#req.originalUrl

Steps to Reproduce

  1. Setup routing using express router https://expressjs.com/en/api.html#router
  2. Handle an exception thrown from the router.
  3. event.transaction (and issue title in Sentry) will include only the router's part of the URL

What you expected to happen

Given my example in the description, I would expect to see full URL:

GET|/foo/bar

Possible Solution

Sentry should try to get the URL from req.originalUrl. I am currently using this workaround:

const sentryRequestHandler = Sentry.Handlers.requestHandler();
  app.use((req, res, next) => {
    sentryRequestHandler(req, res, () => {
      Sentry.getCurrentHub().configureScope(scope => {
        scope.addEventProcessor((event) => {
          event.transaction = `${req.method}|${req.originalUrl}`;
          return event;
        });
      });
      next();
    });
  });

This is patching the transaction to use .originalUrl

@BYK BYK transferred this issue from getsentry/sentry Oct 25, 2020
@optinirr
Copy link

any news on this? the "possible solution" doesn't work either for me.

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 a pull request may close this issue.

3 participants