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
})