pinojs / pino-http

🌲 high-speed HTTP logger for Node.js
MIT License
539 stars 116 forks source link

pino-http not working correctly with GraphQL requests #273

Closed mh377 closed 1 year ago

mh377 commented 1 year ago

What is the current behavior?

I am able to append a custom header: x-request-id to each log message for REST requests but not for GraphQL requests.

What is the expected behavior?

I should be able to append a custom header x-request-id to each log message for BOTH REST and GraphQL requests.

Sample Code Repo

Instructions are in the README.md of the following repo:

https://github.com/mh377/nestjs-graphql-sample

Additional Information

Logger Configuration:

@Module({
  imports: [
    PinoLoggerModule.forRootAsync({
      imports: [ConfigModule.forRoot({ isGlobal: true })],
      useFactory: async (configService: ConfigService) => ({
        isGlobal: true,
        pinoHttp: {
          level: 'trace',
          redact: configService.get<string[]>('logger.redact.fields'),
          transport: {
            target: 'pino-pretty',
            options: {
              colorize: false,
              singleLine: true,
              levelFirst: false,
              translateTime: "yyyy-mm-dd'T'HH:MM:ss.l'Z'",
              messageFormat: '{req.headers.x-request-id} [{context}] {msg}',
              ignore: 'pid,hostname,context,req,res.headers',
              errorLikeObjectKeys: ['err', 'error'],
            },
          },
        },
      }),
      inject: [ConfigService],
    }),
  ],
  controllers: [],
  providers: [],
})
export class LoggerModule {}
mcollina commented 1 year ago

Thanks for reporting. We do not have the resources to support Nest.js users. Please refer to the Nest Discord channel (support) for such questions.