Console auto-logging
The agent watches the browser console. No code changes needed, just turn on Automatically collect console logs in Application settings.
Click around this page to send real log events to a shared New Relic account, then find your own messages with a single query.
console.log.
// 1. Console calls are captured automatically console.error('Payment declined') // 2. Or send a log yourself, with attributes newrelic.log('Cart abandoned', { level: 'warn', customAttributes: { cartValue: 129.99 } }) // 3. Or wrap the logger you already have newrelic.wrapLogger(myLogger, 'warn', { level: 'warn' })
There are three ways to get browser logs into New Relic, plus a few realistic scenarios. Each button shows the log level it creates and whether that level is kept at WARN.
The agent watches the browser console. No code changes needed, just turn on Automatically collect console logs in Application settings.
newrelic.log()Send one log event with a level you choose and your own attributes.
newrelic.wrapLogger()This page has its own little logger, appLogger, which writes to the box below and not to the console. Each method was wrapped once at page load, so every call also becomes a New Relic log event. The first argument becomes the message.
// Run once at page load newrelic.wrapLogger(appLogger, 'info', { level: 'info', customAttributes: { loggerName: 'appLogger' } }) newrelic.wrapLogger(appLogger, 'warn', { level: 'warn', customAttributes: { loggerName: 'appLogger' } }) newrelic.wrapLogger(appLogger, 'error', { level: 'error', customAttributes: { loggerName: 'appLogger' } })
Each scenario plays out a short story using a mix of all three methods, with attributes you could filter or facet on.
Browser logs are sent in batches, so allow up to a minute for new events to show up. Both searches below are already filled in with your code, NR-XXXX.