@loglayer/transport-new-relic
v4.2.0
Published
New Relic transport for the LogLayer logging library.
Downloads
2,527
Maintainers
Readme
New Relic Transport for LogLayer
The New Relic transport for the LogLayer logging library.
Ships logs to New Relic using their Log API. Compatible with Node.js, Bun, and Deno. Features include:
- Automatic gzip compression (configurable)
- Retry mechanism with exponential backoff
- Rate limiting support
- Batch sending with configurable size and timeout
- Validation of New Relic's API constraints
- Error handling and debug callbacks
Installation
npm install loglayer @loglayer/transport-new-relic serialize-errorUsage
import { LogLayer } from 'loglayer'
import { NewRelicTransport } from "@loglayer/transport-new-relic"
import { serializeError } from "serialize-error";
const log = new LogLayer({
errorSerializer: serializeError,
transport: new NewRelicTransport({
apiKey: "YOUR_NEW_RELIC_API_KEY",
endpoint: "https://log-api.newrelic.com/log/v1", // optional, this is the default
compression: true, // optional, defaults to true
maxRetries: 3, // optional, defaults to 3
retryDelay: 1000, // optional, base delay in ms, defaults to 1000
respectRateLimit: true, // optional, defaults to true
onError: (err) => {
console.error('Failed to send logs:', err);
},
onDebug: (entry) => {
console.log('Log entry being sent:', entry);
},
})
})
// Use the logger
log.info("This is a test message");
log.withMetadata({ userId: "123" }).error("User not found");Configuration
interface NewRelicTransportConfig {
/**
* Whether the transport is enabled. Default is true.
*/
enabled?: boolean;
/**
* The New Relic API key
*/
apiKey: string;
/**
* The New Relic Log API endpoint
* @default "https://log-api.newrelic.com/log/v1"
*/
endpoint?: string;
/**
* Optional callback for error handling
*/
onError?: (err: Error) => void;
/**
* Optional callback for debugging log entries
* Called with the entry before it is sent
*/
onDebug?: (entry: Record<string, any>) => void;
/**
* Whether to use gzip compression
* @default true
*/
compression?: boolean;
/**
* Number of retry attempts before giving up
* @default 3
*/
maxRetries?: number;
/**
* Base delay between retries in milliseconds
* @default 1000
*/
retryDelay?: number;
/**
* Whether to respect rate limiting by waiting when a 429 response is received
* @default true
*/
respectRateLimit?: boolean;
}Documentation
For more details, visit https://loglayer.dev/transports/new-relic
