Skip to content

@sentry/tracing inconsistent transaction names when using history with basename #3595

@tzimmermann

Description

@tzimmermann

Package + Version

  • @sentry/react
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other: @sentry/tracing

Version:

6.4.1

Description

We're using the reactRouterV5Instrumentation and would like to generate the same route names for pageload and for navigation transactions.
For example:
Given the relative path in the browser:
/my/base/path/foo/some-dynamic-id/
then I expect to get a transaction named:
/foo/:id

The base path should be stripped from the name as its passed as basename to the history as suggested in #3107 (comment)

What we observe though is that only the navigation events are being named correctly (/foo/:id), the initial pageload receives the full path (/my/base/path/foo/some-dynamic-id/).

After some digging in the code, it's quite clear why this happens:
This

name: getTransactionName(global.location.pathname),

should be

name: getTransactionName(history.location.pathname),

The history wrapper object needs to be used (instead of global.location) in order to have the expected basename handling applied. For navigations events, this is already the case, as these are using history.listen some lines below.

Would you see any issues with that change? Otherwise I'll happily provide a PR 😃

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions