How to push data back to NewRelic

Since jMeter is not a real ‘Browser’ it does not execute any Javascript after receiving the response from web server. NewRelic frontend timing and Browser session tracking is dependent on Javascript execution to send required data asynchronously back to NewRelic, therefore when we use jMeter we are not able to use features in Browser app section of NewRelic (we are interested in transactions breakdown in browser section). To overcome this problem we need to extract the required parameters from the page response and also fake some metrics then make a separate request to NewRelic server and push the data.

Step-by-step guide

    1. In order for NewRelic agent to inject variables into page source we need to have a User-Agent which is more modern than jMeter’s default User-Agent, since NewRelic agent on server does not inject these data for old User-Agents. What has worked for me is just to set my normal chrome User-Agent like this in the request headers:
    2. Now we are sure that NewRelic agent injects some Json data into page that we can parse:
    3. As you see NREUM Json object now contains some data which we can parse using jMeter’s ‘Regular Expression Extractor’ like this:
    4. Now that we have a Json object we can use jMeter’s ‘JSON path extractor’ to simply fetch the value of each variable in the Json:
    5. At this step we have extracted all NewRelic variables form the page and we can push them to NewRelic. The request should be a GET request to${nrLicence} where nrLicence is already extracted from Json and the rest of parameters are as following::
  • Parameter Name
  • Value
  • Description
  • a
  • ${nrAppId}
  • ApplicationId already extracted from Json
  • pl
  • ${__javaScript(new Date().getTime();)}
  • jMeter Javascript code to get current time (this will be used as a reference for calculating other front-end timings) not important the is accurate.
  • v
  • 768.2acc9fa
  • Javascript code version. If it changes just simply check what is sent to NewRelic in a normal page view.
  • to
  • ${nrTransactionName}
  • Hashed value of transaction name which is Magento’s module/controller/action, already extracted from Json.
  • ap
  • ${nrApplicationTime}
  • Application time in milliseconds, already extracted from Json.
  • be
  • Hard Coded integer of milliseconds
  • BE time including network, DNS and content download, since it’s not possible/important to calculate the exact value this can be hardcoded to anything.
  • fe
  • Hard Coded integer of milliseconds
  • whole FE time, since it’s not possible/important to calculate the exact value this can be hardcoded to anything.
  • dc
  • Hard Coded integer of milliseconds
  • ?
  • f
  • []
  • ?
  • perf
  • Hardcoded to:
     Expand source

  • This will be a Json with values of browser performance timing which is get from: performance.timing
  • command, since jMeter does not render anything in FE this should be hardcoded. 
  • at
  • ${nrAtts}
  • Obfuscated value of any custom attributes injected to the page, this is already extracted from Json.
  • jsonp
  • NREUM.setToken
  1. We are nearly done now, and just need to make sure we have Json extractor PostProcessors inside every request sampler and also a request sampler which is making the get request to NewRelic right after it:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s