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

Using the transport seems to break changing the log level #186

Open
TreeOfLearning opened this issue Sep 7, 2024 · 1 comment
Open

Using the transport seems to break changing the log level #186

TreeOfLearning opened this issue Sep 7, 2024 · 1 comment

Comments

@TreeOfLearning
Copy link

It seems that using this transport prevents me from changing the pino default log level.

For example:


import pino from 'pino';

const logger = pino({
  transport: {
    targets: [
      {
        target: 'pino-pretty',
        options: { colorize: true },
      },
      {
        target: 'pino-opentelemetry-transport',
        options: {
          resourceAttributes: {
            'service.name': 'whatever',
          },
       },
     },
   ]
 }
});
logger.level = "trace";
logger.trace("trace");
logger.debug("debug");
logger.info("info");

Gives the output:
[20:51:12.705] INFO (2543437): info

Whereas this:


import pino from 'pino';

const logger = pino({
  transport: {
    targets: [
      {
        target: 'pino-pretty',
        options: { colorize: true },
      },
    /*  {
        target: 'pino-opentelemetry-transport',
        options: {
          resourceAttributes: {
            'service.name': 'whatever',
          },
       },
     }, */
   ]
 }
});
logger.level = "trace";
logger.trace("trace");
logger.debug("debug");
logger.info("info");

Gives the output:

[20:54:06.302] TRACE (2543472): trace
[20:54:06.303] DEBUG (2543472): debug
[20:54:06.303] INFO (2543472): info

And my otel collector only ever receives the info log when the transport enabled.

Am I missing something obvious?

Perhaps worth mentioning I am writing this in typescript and running via ts-node. Perhaps that's an issue?

@Vunovati
Copy link
Collaborator

Vunovati commented Sep 28, 2024

Hello @TreeOfLearning, sorry for the wait.

I was able to reproduce your issue in plain JS, so ts-node is not the issue here.
The problem is visible only if both pino-pretty and pino-opentelemetry-transport are set as transports. If only one of those is set, all log levels are visible in the logs as expected.

You will have to explicitly set the log level for each transform for this to work the way you expect it to:

const logger = pino({
  transport: {
    targets: [
      {
        target: 'pino-pretty',
        options: { colorize: true },
        level: 'trace'
      },
      {
        target: 'pino-opentelemetry-transport',
        level: 'trace',
        options: {
          resourceAttributes: {
            'service.name': 'whatever'
          }
        }
      }
    ]
  }
})
logger.level = 'trace'
logger.trace('trace')
logger.debug('debug')
logger.info('info')

Or like this:

const logger = pino({
  transport: {
    targets: [
      {
        target: 'pino-pretty',
        options: { colorize: true },
        level: 'trace'
      },
      {
        target: 'pino-opentelemetry-transport',
        level: 'trace',
        options: {
          resourceAttributes: {
            'service.name': 'whatever'
          }
        }
      }
    ]
  },
  level: 'trace'
})
// logger.level = 'trace'
logger.trace('trace')
logger.debug('debug')
logger.info('info')

This is not specific to pino-opentelemetry-transport though,

You will see the same behaviour in similar combinations of different transports ... for example:

run

const pino = require('pino')

const logger = pino({
  transport: {
    targets: [
      {
        target: 'pino-pretty',
        options: { colorize: true },
      },
      {
        target: 'pino/file',
        options: { destination: 1 }, // this writes to STDOUT,
      }
    ]
  }
})
logger.level = 'trace'
logger.trace('trace')
logger.debug('debug')
logger.info('info')

compare it to:

const pino = require('pino')

const logger = pino({
  transport: {
    targets: [
      {
        target: 'pino-pretty',
        options: { colorize: true },
        level: 'trace'
      },
      {
        target: 'pino/file',
        options: { destination: 1 }, // this writes to STDOUT,
        level: 'trace'
      }
    ]
  }
})
logger.level = 'trace'
logger.trace('trace')
logger.debug('debug')
logger.info('info')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants