How to send a debug message to elastic APM Real User Monitoring from my application?

I have a JavaScript application and configured Elastic APM/RUM on that. As soon as I start to interact with the application some metrics start sending to APM Server (page_load for example). I want to know if it's possible to send a specific text message to APM Server after a browser event.

In my code, I'm intercepting the payload in amp.addFilter and editing the payload. However, I think the best way would be using the amp.addTransaction, but I'm not sure.

    elasticApm.addFilter(function (payload) {
      payload.myDebugMessage = debugMessage

      if (payload.errors) {
        payload.errors.forEach(function (error) {
           error.exception.message = error.exception.message.replace('secret', '[REDACTED]')
      if (payload.transactions) {
       payload.transactions.forEach(function (tr) {
         tr.spans.forEach(function (span) {
           if (span.context && span.context.http && span.context.http.url) {
             var url = new URL(span.context.http.url)
             if (url.searchParams.get('token')) {
               url.searchParams.set('token', 'REDACTED')
             span.context.http.url = url.toString()
     // Make sure to return the payload
     return payload

Hi @pablodarde. Welcome to the community!

You can use startTransaction API to start a new transaction manually. Don't forget to call transaction.end().

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