How to capture user-interactions such as click which do not have network activities?

Hi,

I'm currently using Angular to track user-interactions. I know we can use custom-transactions to capture non-network user-interactions. But doing so will lead to huge amount of transactions since our application is quite big. Moever, in future for adding any new functionality, we'll always need to make sure to add apm transactions as well. Is there any way I can capture the user-interactions like click of a button, blur, scroll etc since these are normal user interactions without having to create many transactions.

Thanks,
Aman

Hi @Aman50 ,

Thanks for reaching out!

There is an alternative to custom transactions that might help you. The idea is to combine the usage of apm.getCurrentTransaction with the creation of a span.

Bear in mind that by default the agent automatically creates a transaction every time there is a click (although such transaction would be discarded if there are no spans related, like the ones that a network activity would create)

Thanks to such behaviour, you are able to do something like this (I added comments to the code):

your.addEventListener("click", (event) => {
   // Gets the transaction created by the agent
   const transaction = elasticApm.getCurrentTransaction();
   if (transaction) {
        // create your own span
       const span = transaction.startSpan("my-span", "my-span-type", { blocking: true });
       // Since a span should have an end to be taken into account I'm setting an arbitrary end time
       // Depending on your flow you could decide to skip the "span._start + 1" 
       // if you can assure that you are calling span.end() after some logic of yours that tends to last 
       // more than 0ms. Although if the main goal is to have the transaction visible in Kibana then it's ok

       span.end(span._start + 1)
   }
})

Important to mention that the agent creates user-interaction transactions only with clicks. Other interactions like scroll, keypress, etc are not currently handled by the agent. There are no plans to adding them in the mid-term.

Thanks,
Alberto

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.