Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PinoHttp automatic http logs with default successful log message not being forwarded to NewRelic #2718

Closed
danimagb-moonfare opened this issue Nov 11, 2024 · 8 comments
Assignees

Comments

@danimagb-moonfare
Copy link

danimagb-moonfare commented Nov 11, 2024

Description

I'm using nestjs-pino which uses pino-http and allows me to log http requests automatically.
The pino-http package automatically logs http requests with a default message based on the result of the request (e.g: 'request completed', 'request errored', 'request aborted', etc...)

I noticed that when the log message is 'request completed', I see the log in my console locally but it seems that for some reason the log never reaches newrelic. If I customize the log message to something else like 'http request completed', then I'm able to see it in my console and it is automatically forward to newrelic by the agent.

I was able to find a similar bug related to pino-http here
I tried to update my newrelic node agent to the version where the bug was fixed but it didn't help, so I guess this may be something else.
https://github.com/newrelic/node-newrelic/releases/tag/v12.5.1

Expected Behavior

The log should reach newrelic regardless of the message being logged. The log should be forwarded to newrelic when the log message is 'request completed'.

Troubleshooting or NR Diag results

When configuring the module without customizing the default success message defined in pino-http for successful http requests I can see the logs in my console, but the automatic http log never reaches newrelic.

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { LoggerModule } from 'nestjs-pino';

@Module({
  imports: [LoggerModule.forRoot({
    pinoHttp:{
      autoLogging: true,
      level: 'debug',
      useLevel: 'debug',
    }
  })],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Console Logs
default_logs

Default PinoHttp success log message request completed isn't forwarded to NewRelic

NewRelic logs
default_nr_logs

When I change the log message to a custom one like Http Request Completed, it starts working

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { LoggerModule } from 'nestjs-pino';

@Module({
  imports: [LoggerModule.forRoot({
    pinoHttp:{
      autoLogging: true,
      level: 'debug',
      useLevel: 'debug',
      customSuccessMessage: (req, res) : string => (!req.readableAborted && res.writableEnded ?
        'Http Request Completed' :
        'Http Request Aborted'),
      customErrorMessage: () : string => 'Http Request Errored',
    }
  })],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Console Logs
custom_logs

NewRelic logs
custom_nr_logs

Steps to Reproduce

Link to the repo here

Your Environment

  • NestJs version: 10.0.0
  • Node version: 20.16.0
  • nestjs-pino version: 4.1.0
  • pino-http version: 10.3.0
  • newrelic node agent version: 12.6.1

Additional context

@workato-integration
Copy link

@jsumners-nr
Copy link
Contributor

Are you able to provide a minimal reproduction with plain JavaScript?

@danimagb-moonfare
Copy link
Author

Are you able to provide a minimal reproduction with plain JavaScript?

Hi @jsumners-nr ,
You can find it here

@jsumners-nr
Copy link
Contributor

Are you able to provide a minimal reproduction with plain JavaScript?

Hi @jsumners-nr , You can find it here

I am getting a 404 when I visit that link. Can you make it public?

@danimagb-moonfare
Copy link
Author

Are you able to provide a minimal reproduction with plain JavaScript?

Hi @jsumners-nr , You can find it here

I am getting a 404 when I visit that link. Can you make it public?

My bad! it should be public now.

@bizob2828 bizob2828 self-assigned this Nov 12, 2024
@bizob2828 bizob2828 moved this from Triage Needed: Unprioritized Features to In progress: Issues being worked on in Node.js Engineering Board Nov 12, 2024
@bizob2828
Copy link
Member

@danimagb-moonfare I ran your repro and I see the request completed log messages. When I uncomment out the code I see the Http Request Completed messages as well

screenshot 2024-11-12 at 12 47 29 PM

@danimagb-moonfare
Copy link
Author

@danimagb-moonfare I ran your repro and I see the request completed log messages. When I uncomment out the code I see the Http Request Completed messages as well

screenshot 2024-11-12 at 12 47 29 PM

Hey @bizob2828,

Thanks for your response.
I will try to understand if we are dropping some logs intentionally, it will probably be that. I will give feedback

@bizob2828
Copy link
Member

@danimagb-moonfare I'm going to close this bug for now. If you can figure out a way to reproduce, please update your github repo and reopen this issue.

@github-project-automation github-project-automation bot moved this from Triage Needed: Unprioritized Features to Done: Issues recently completed in Node.js Engineering Board Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants