0

I have this logger model:

  LoggerModule.forRootAsync({
  imports: [ConfigModule],
  useFactory: (configService: ConfigService<AppConfig, true>) => ({
    pinoHttp: {
      level: configService.get('logger.level', { infer: true }),
      autoLogging: false,
      name: 'someName',
      messageKey: 'message', // take advantage Datadog's default facet
      mixin(): Record<string, unknown> {
        return {
          dd: { ...getDatadogMixin(tracer) },
        };
      },
      nestedKey: 'metadata',
      reqCustomProps(req) {
        return {
          executionId: req.headers[EXECUTION_ID],
        };
      },
    },
  }),
  inject: [ConfigService],
}),

I know that as of pino 7.x, when the mixin is used with the nestedKey option, the object returned from the mixin method will also be nested.

I'm trying to revert that, which means that I want the object that returning from the mixin method would still be at the root.

{"level":30,"time":1591195061437,"pid":16012,"hostname":"x", dd: {<dd-tracing-object>}, "metadata": 
{"executionId":"12345"},"msg":"Message 1"}

tnx.

yairabr
  • 101
  • 1
  • 1
  • 6

1 Answers1

0

The only option I found with pino was to remove the option nestedKey and use the optional function formatters.log to wrap the log object into your nestedKey and provide the details under getDatadogMixin(). But beware this method would require you to review other pino config you could have set (e.g. serializers or redact).

vhtc
  • 790
  • 6
  • 12