pino-newrelic-log-api-transport
A Pino v7+ transport to send log to newrelic with Logs API.
Caution
newrelic has an automatic log forwarding feature.
Consider using the official nodejs agent.
https://docs.newrelic.com/jp/docs/apm/agents/nodejs-agent/installation-configuration/install-nodejs-agent
If for some reason you cannot use the automatic log forwarding feature with nodejs agent, please use it.
Installation
pnpm @harusame0616/pino-newrelic-log-api-transport
Usage
import pino from 'pino';
import {
NewrelicLogAPITransportOption,
endpointEnum,
} from '@harusame0616/pino-newrelic-log-api-transport';
const options: NewrelicLogAPITransportOption = {
endpoint: endpointEnum.us,
};
const logger = pino({
messageKey: 'message',
errorKey: 'error',
level: 'info',
base: {
entity: {
name: process.env.NEWRELIC_APP_NAME,
},
},
formatters: {
level: (label) => ({ level: label }),
},
transport: {
target: '@harusame0616/pino-newrelic-log-api-transport',
options: options,
},
});
logger.info('info level log');
※ If you are using the nextjs app router you may need to add "pino" to serverComponentsExternalPackages in next.config.
https://github.com/vercel/next.js/discussions/46987#discussioncomment-6986115
and run bellow
NEWRELIC_LICENSE_KEY=YOUR_LICENSE NEWRELIC_APP_NAME=YOUR_APP_NAME node YOUR_APP