Introduction
In modern application development, monitoring application behavior and identifying errors quickly are essential for maintaining reliable software. New Relic is an observability platform that helps developers monitor application performance, collect logs, investigate errors, and troubleshoot issues across different environments.
New Relic Logs allows developers to search, filter, and analyze log data from applications, servers, containers, and cloud infrastructure. By bringing logs and performance data together, developers can identify the root cause of problems more efficiently.
In this article, we will explore New Relic Logs, how to configure logging, how to send application logs to New Relic, and how to troubleshoot common issues.
What Are New Relic Logs?
New Relic Logs is a log management solution that collects and analyzes log data generated by applications and infrastructure.
Logs provide information about what is happening inside an application, including:
- Application errors and exceptions.
- API requests and responses.
- Authentication and authorization failures.
- Performance-related events.
- Background jobs and service activity.
- Debugging information generated by developers.
For example, when an API request fails, application logs can help you determine whether the issue originated from the application, an external service, or a configuration problem.
Key Features of New Relic Logs
1. Centralized log management
New Relic allows you to collect logs from multiple services and environments in one place. Instead of connecting to individual servers or Kubernetes pods, developers can investigate logs through a centralized interface.
2. Real-time log monitoring
Developers can inspect incoming logs to identify errors and unusual application behavior without manually checking every server.
3. Log filtering and searching
You can search logs using attributes such as:
- Application name.
- Environment.
- Kubernetes namespace.
- Log severity.
- Timestamp.
- Error message.
- Trace or request identifier.
4. Correlation with application performance
When configured appropriately, logs can be correlated with distributed traces, transactions, and errors. This helps developers understand not just what failed, but also where and why it failed.
5. Alerts and dashboards
New Relic can help teams create alerts and dashboards based on log events and related telemetry, making it easier to detect recurring problems.
How to Send Application Logs to New Relic
There are multiple ways to send logs to New Relic. The correct approach depends on your application architecture and the type of logs you want to collect.
1. Infrastructure agent or log forwarding
Common for backend applications, virtual machines, and containerized workloads. An infrastructure agent or supported forwarding solution collects logs and sends them to New Relic.
2. Browser monitoring
Useful for frontend applications built with React or Next.js. The New Relic browser agent collects browser telemetry and can be configured to capture supported browser logs.
3. Application logging APIs
Applications can send supported log events through New Relic APIs or compatible logging integrations. This approach is useful when you need explicit control over what gets sent.
Important: Browser logs and server logs are different. Capturing console.log() in a browser does not automatically collect backend logs or Kubernetes container output.
Integrating New Relic Logs with a React or Next.js Application
For frontend applications, New Relic Browser monitoring can provide visibility into errors and user-side application behavior.
Step 1: Configure the New Relic Browser agent
Install or configure a supported New Relic Browser agent integration for your application. Ensure that the browser agent receives the correct configuration for the target environment, including the required application and license identifiers.
For deployments using Kubernetes, configuration may be provided through a ConfigMap and mounted configuration file.
Avoid hardcoding secrets or environment-specific identifiers in source code.
Step 2: Initialize the browser agent
The agent must be initialized before you expect it to collect telemetry.
A simplified example of the initialization pattern is shown below. The exact configuration depends on your installed agent version and integration.
import { BrowserAgent } from '@newrelic/browser-agent/loaders/browser-agent';export function initializeNewRelic(config) { if (!config?.licenseKey || !config?.applicationID) { console.error( 'New Relic browser configuration is missing' ); return; } new BrowserAgent({ init: { distributed_tracing: { enabled: true, }, }, loader_config: { accountID: config.accountID, trustKey: config.trustKey, agentID: config.agentID, licenseKey: config.licenseKey, applicationID: config.applicationID, }, info: { beacon: 'bam.nr-data.net', applicationID: config.applicationID, }, });}
This is an illustrative initialization example, not a complete logging configuration. Check the API and required fields for your installed Browser agent version before using it in production.
Step 3: Capture browser console logs
If your requirement is to send application console.log(), console.warn(), and console.error() messages to New Relic, verify that your browser agent version supports the required logging capability and that it is enabled.
A logging wrapper can intercept console calls and forward selected messages through a supported New Relic logging API.
For example, the browser agent may expose a logging method such as newrelic.log() when the relevant functionality is available.
function logToNewRelic(message, level = 'info') { if (typeof window === 'undefined') { return; } const newRelic = window.newrelic; if (typeof newRelic?.log === 'function') { newRelic.log(message, { level }); }}
Usage:
logToNewRelic('Application initialized', 'info');logToNewRelic('API request failed', 'error');
The exact API signature and available logging methods depend on the browser agent version and enabled features. Confirm these against the official documentation before implementation.
Important considerations:
- Do not log passwords, access tokens, personal information, or other sensitive data.
- Avoid sending the same event through multiple logging integrations.
- Ensure that the browser agent has initialized before attempting to send logs.
- Do not assume that every browser console message is automatically forwarded to New Relic.
Step 4: Verify that logs are reaching New Relic
Open the New Relic platform and navigate to the Logs interface. Search for the expected application, environment, or log message.
You can also use NRQL to investigate logs.
Example query:
SELECT *FROM LogSINCE 30 minutes agoLIMIT 100
To count logs by severity:
SELECT count(*)FROM LogFACET levelSINCE 1 hour ago
To search for a particular application error:
SELECT *FROM LogWHERE message LIKE '%API request failed%'SINCE 1 hour agoLIMIT 100
These queries assume that logs are ingested into the Log event type and that the relevant attributes are available.
Troubleshooting New Relic Logs
Sometimes New Relic monitoring appears to work in one environment but not another. The following checks can help identify the issue.
| Problem | What to check |
|---|---|
| Logs do not appear in New Relic | Confirm that the logging integration is enabled and events are actually being sent. |
| Browser monitoring works but logs are missing | Verify browser logging support, configuration, and agent initialization. |
| Logs work in development but not in staging | Compare environment-specific ConfigMaps, mounted files, and application identifiers. |
| Browser logs appear in the console but not in New Relic | Check whether console forwarding is configured and whether the supported logging API is available. |
| Kubernetes logs are missing | Check pod output, container logging, collection agents, and forwarding configuration. |
| Duplicate logs appear | Check for overlapping logging integrations or multiple console wrappers. |
| Configuration values are incorrect | Verify the mounted configuration file and ensure the application reads the intended key. |
