cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dynatrace API to get RUM tag inline code

shashank_b_agra
Organizer

Hello, I've been using Dynatrace RUM for a while now and using "Inline Code" method. The drawback of manual injection is that every time I make any changes to the application configuration settings in Dynatrace, I have to update the monitoring code in my application which is not good and prone to errors.

 

I've bee looking into Dynatrace API and I think this can provide certain amount of automation and I don't need to change the code every time I change something. I've couple of questions on how this works -

 

  1. Now the documentation says the API endpoint need to be provided into the build script of your application. What does it mean? Does it mean it will fetch the code during the build of application and not really at the run time i.e. page load time?
  2. For each requests or user action, does it go to the server to fetch the JS tag? does it cause any performance issues? Is this something can be cached at client side?
  3. If I change some setting in Dynatrace, how long does it take to reflect those changes?

 

Note - I am using Dynatrace managed and  have 2 active gates running with a public load balancer which accepts all the RUM traffic from browsers

 

Let me know if anyone can shed some light on this. It will be a massive help.

7 REPLIES 7

Julius_Loman
DynaMight Guru
DynaMight Guru

Hello @shashank_b_agra ,

the API is able to provide you with the snippet you need to include. It's up to you how you are able to automate insertion of the code into your application. Typical process is - whenever the build and deploy task is executed in your app, your build script will pull the API for the Dynatrace JS code snippet.

 

Answers to your questions:

  1. During the build time as stated above.
  2. Not during user actions. If you use inline code, the whole code is inserted at build time. The code is loaded only during load actions, not XHR.
  3. It's again up to you - you will need to update your tag. If you use some sort of automation (point 1) you typically need to redeploy your app. Some changes in application settings require the update (such as session properties from CSS/metadata), some not (user action naming rule based on current placeholders)

I'd really recommend the OneAgent approach - having OneAgent to insert the JS code for you in runtime. Did you ruled out this approach which is default? 

Certified Dynatrace Master | TEMPEST a.s., Slovakia, Dynatrace Master Partner

Hi @Julius_Loman Thank you for your detailed response. We can't use one agent as our application is built on Angular and is serverless i.e. the pages are served from S3.

We kind of have a complex architecture where the front end is hosted on Angular which makes call to Strapi for content and then further XHR calls to downstream systems.

 

In the 2nd point you mentioned that XHR actions won't be loaded. Are you saying I won't be able to see any XHR requests in Dynatrace? Because if that is the case then Dynatrace RUM is not serving it's purpose. As a operations, we would like to see how the page is performing and for that I think we need to understand the XHR calls taking place on that page.

 

Could you elaborate on that please?

Hi @shashank_b_agra ,

OK I understand, you really need the agentless approach in your case.

With the XHR I meant there is not a loading of the Dynatrace JavaScript in the browser. XHRs will be captured of course if you have this option turned on in the application settings. 

So whatever manual injection in the HTML code you are using, the Dynatrace JS gets loaded during Load actions only, but it's monitoring all the user actions (Load, XHR, Custom).

Actually the situation with updating the code is not that bad as it looks like. For many changes in the application settings you don't need to update the inline code. Mostly the update is required if:

  • a new version of the Dynatrace RUM JS code is to be deployed
  • you modify some settings to capture data from the webpage (action/session properties, placehoders for naming)
  • you modify some advanced settings

 

Certified Dynatrace Master | TEMPEST a.s., Slovakia, Dynatrace Master Partner

Hi @Julius_Loman Thanks for the response again. I agree with you but manually updating the inline code is prone to errors and if we use the API, it will retrieve at the build time automatically and less chances of errors. I mean that is my point of view but I don't know how it will work because we haven't tested it.

I have one more concern. If by any chance the API endpoint is down or not responding then the application won't be able to fetch the code and we may lost the monitoring.

So basically during the build time only, we have to make sure that it fetches the code before it gets deployed.

 

Also, one more thing. My application which is built in Angular makes several XHR calls from the browser but Dynatrace is not logging them for some reason. Do you know if there is any config or property I need to change or add specifically to log these XHRs?

 

For example, We have a publically available page https://www.vir:)ginmedia.com/broadband/packages which if you load in the browser you will see lot of XHR calls in the developer tools network tab BUT they don't get logged in Dynatrace. 

Any idea at all why?

 

Really appreciate if you can assist here with your thoughts.

Hi @shashank_b_agra ,
you fetch the inline code during build time. You don't have any runtime dependency on the API from your app. You need to handle situations such as api token not valid or dynatrace environment is not reachble from your build system. They are unlikely, but of course may happen.

The second question - this may occur for several reasons, for answers I'd need to see the waterfall in Dynatrace and the browser's developer tools.

 

  • Do you have the Dynatrace RUM JS injected in each iframe in your application? (this is likely the reason - maybe you are loading a 3rd party content in an iframe and the requests are from this iframe?)
  • Do you have also the support for generic XHRs enabled in addition to the Angular support in the settings for your application in Dynatrace?
  • Typically your XHR may be excluded from user actions (there is an option for that) - check if you are not excluding them. But this would just exclude them from being a trigger of user actions, you will still see them in the waterfalls in Dynatrace if they are part of user action triggered by other XHR.

Julius

Certified Dynatrace Master | TEMPEST a.s., Slovakia, Dynatrace Master Partner

Hi @Julius_Loman Answers below -

  • Yes JS is injected across all the pages
  • support fort XHR's enabled
  • That excluded option is blank.

I've a ticket raised with Dynatrace to investigate this behaviour because If i go into the waterfall analysis of that page, I can see all the XHR calls logged there in the exactly same manner they are called in browser. It's just on the application page where they are not showing. Let's see what they come up with.

 

Also one last help 🙂 

I know if i use inline code then I would have to update my snippet everytime I make changes in Application settings under Capturing -> Advanced setup, BUT what if i use CodeSnippet (deferred) mode?

How does that work? Dynatrace says if you use this format then the changes will automatically reflect in customers browsers. Is it because everytime customer loads the page, the snippet or monitoring code gets loaded at runtime from Dynatrace.

 

For example - the snippet looks like this at first -

da.cfg="app=XXXXXXX|cors=1|rcdec=1209600000|featureHash=A2Vfgqru|cux=1|vcv=2|reportUrl=****

Now I change a param in advanced setup and remove cux=1, then it looks like this -

da.cfg="app=XXXXXXX|cors=1|rcdec=1209600000|featureHash=A2Vfgqru|vcv=2|reportUrl=

you can see that param is gone. But how will it gets reflected in customer browser unless we change the snippet in HTML? I also get a yellow warning message as attached which Dynatrace says that is only for inline code and can be ignored.

shashank_b_agra_0-1639734481941.png

 

Really appreciate if you can shed some light as I have been getting different answers everywhere. 

 

Best Regards,

Shashank

Hi @shashank_b_agra ,

if I remember the setting correctly, the deferred mode tries to be a non-blocking. This is described here and you can see the differences between the options https://www.dynatrace.com/support/help/how-to-use-dynatrace/real-user-monitoring/setup-and-configura... 
In your case I believe you still need to update your pages with an updated tag reflecting the configuration.

For the missing requests in waterfall - you will probably need to talk to support or check the stack (initiator) in the developer options. I think it's likely in from a JavaScript from an iframe that does not have the Dynatrace JavaScript.

Regards
Julius

Certified Dynatrace Master | TEMPEST a.s., Slovakia, Dynatrace Master Partner