elastic / apm-agent-rum-js

https://www.elastic.co/guide/en/apm/agent/rum-js/current/index.html
MIT License
279 stars 134 forks source link

Consider patching console.error to capture errors #160

Open hmdhk opened 5 years ago

hmdhk commented 5 years ago

Something like:

    var origError = console.error
    console.error = function (error) {
      try {
        if (typeof error === 'string' || error instanceof Error) {
          elasticApm.captureError(error)
        }
      } finally {
        origError.apply(console, arguments)
      }
    }
vigneshshanmugam commented 5 years ago

I am totally in for this, except there is a caveat that our script wont be able to capture any errors if its lazy loaded and not in the head. Right now, this would happen even for XHR and Fetch, but we can work around that using Resource timing information.

Also, We cannot make any assumptions that our script should be loaded in the head, it is not viable since it can degrade page performance.

hmdhk commented 5 years ago

A possible solution is to document this snippet!

dougse commented 3 years ago

The ability to long js console.* is critical to us because we want to log angular/react - so we are bypassing apm.js and sending directly to endpoint.