Skip to content
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

use pathname as transaction name for route change #297

Closed
vigneshshanmugam opened this issue Jun 20, 2019 · 3 comments · Fixed by #827
Closed

use pathname as transaction name for route change #297

vigneshshanmugam opened this issue Jun 20, 2019 · 3 comments · Fixed by #827

Comments

@vigneshshanmugam
Copy link
Member

  • While patching the history API, we use title from the history.pushState as the transaction name. Instead we need to use path as the default transaction name.

Scenario (SPA)

  1. go to www.example.com
  2. navigate to www.example.com/a , history.pushState fires with these parameters (state, title, url) -> ({}, null, '/a')

Note: Title is also ignored by some browsers(FF)

Right now our transactions are named as UNKNOWN which does not give much benefit for the user. Instead we could have transaction name as /a. To handle cardinality problems, We can remove query params and other hashes from the URL. We can add the full URL to the context object.

If you want to test real website.

  1. Go to https://www.flipkart.com/
  2. paste this JS in the console
 const nativePushState = history.pushState
  if (typeof nativePushState === 'function') {
    history.pushState = function(state, title, url) {
      const task = {
          state,
          title,
          url
      }
      console.log(task)
      nativePushState.apply(this, arguments)
    }
  }
  1. Navigate to any link from the menu bar. Check the console for the URL

/cc @jahtalab @roncohen

@pgross41
Copy link

pgross41 commented Apr 6, 2020

In case anyone else comes here looking for a quick workaround;

apmAgent.observe('transaction:start', (transaction) => {
  if (transaction.type === 'route-change' && transaction.name === 'Unknown') {
    transaction.name = window.location.pathname
  }
});

@vigneshshanmugam
Copy link
Member Author

@pgross41 Yeah thats a nice workaround and it should work. But its required only if you are not using one of our supported framework integrations https://www.elastic.co/guide/en/apm/agent/rum-js/current/framework-integrations.html

If you use the framework integrations, the path would be automatically picked up by the RUM agent and transaction names would be set accordingly.

const routes - [blog/122, blog/214, blog/342]
// 3 transactions with workaround
/blog/122
/blog/214
/blog/342

// framework integrations
/blog/:id 

@titusjoyson
Copy link

I'm also having the same issue and I'm using the react implementation and I have tried with both instrumenting application routes and instrumenting individual react components except the initial transaction name provided all the transactions are names as UNKNOWN

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.

4 participants