newrelic / newrelic-browser-agent

New Relic Browser Agent
Apache License 2.0
84 stars 43 forks source link

Route console log to new relic logs #761

Closed murphpdx closed 4 months ago

murphpdx commented 1 year ago

I'd like a setting in the new relic brower agent that will automatically hook into the console.log/console.error functions and send the logs to new relic logging. I would also like it to not log in the browser. Alternatively, an api call that will send logs to new relic. It does not have to hook into console but it would be nice if it did.

Summary

Forward logs to new relic via the browser agent.

Desired Behavior

Conditionally override the console.log, console.error, console.debug, console.info etc functions so that they send logs to new relic and do not log in the console.

Possible Solution

Additional context

workato-integration[bot] commented 1 year ago

https://issues.newrelic.com/browse/NR-168151

patrickhousley commented 1 year ago

Hi @murphpdx and thanks for the feature request. This is actually on our roadmap for the quarter starting in January. We did do some work in a past version of the agent to gauge the data that would be sent if we automatically instrumented the console global. Unfortunately we found that extremely large objects are sometimes logged to the console in production systems resulting in a performance issue when we have to serialize it for sending to New Relic.

If you, or any community member or customer, has any suggestions around what you would like to see with this feature, please let us know either here, in our forums, or by reaching out to customer engagement or support.

Some things that we are trying to consider:

workato-integration[bot] commented 1 year ago

https://new-relic.atlassian.net/browse/NR-168151

sconzof commented 9 months ago

Hi! Piggy-backing on the request from @murphpdx This feature set would be very useful for some of our internal applications.

CavalcanteLeo commented 6 months ago

any news about this?

patrickhousley commented 6 months ago

@CavalcanteLeo this work is on our roadmap to start this quarter.

FranciscoKloganB commented 6 months ago

Just shimming in, this feature might be nice as an opt-in.

Some projects allow the use of console.debug (and friends) freely in the code for development reasons and remove them for production builds using vite/webpack/rollup directives.

CavalcanteLeo commented 6 months ago

For me, instead of sending the console.log automatically, I would prefer something to manually send it to new relic, something like newrelic.log(text: string), and on the frontend I can abstract it, and create a function with the logger I want to use...

const useLog = (text: string): void => {
  newrelic.log(text) // here sends the log to new relic [newrelic.info(), newrelic.error()]
  console.log(text)  // Here I could use some other log, like Pino or Winston. And It will get rid in production as well
}

in this case, we don't rely on the console.logs only.

Most of the frameworks get rid of the console logs when building the prod (which is correct)

caviyacht commented 6 months ago

Optionally allowing each method in a config would be preferred. Our main focus is to get console.error captured as it would help track down a ton of problems.

The console.log could become a ton of noise and high data ingest, but toggling it on and off at will would be super beneficial.

piyushchauhan2011 commented 6 months ago

Thank you for good work on logs

patrickhousley commented 4 months ago

Hi everyone. With version 1.261.0, we released two new API methods that you can use to send logs to New Relic for your browser apps.

We do not currently support automatically capturing logs or automatically wrapping console. You will have to determine what fits best in your app and call the appropriate API methods. If you have any questions, please let us know. You can also reach out on support.newrelic.com.