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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error without property type=Error are not logged as exception #79

Open
magnusottosson opened this issue Apr 14, 2023 · 0 comments
Open

Comments

@magnusottosson
Copy link

magnusottosson commented Apr 14, 2023

馃悰 Bug Report

We are using this library with nestjs-pino and a graphql api. We have registered a global exception filter that catches all errors in the GQL application and we are logging them usin the pino logger.

None of these exceptions are logged as exceptions (but are logged as traces) because they are missing a property type with the value error. When our errors are sent to pino-applicationinsights its an object that looks like this:

{
  level: 50,
  time: '2023-04-14T05:40:19.573Z',
  pid: 123456,
  hostname: '<hostname>',
  serviceInstance: 'abc',
  req: {
    ...
  },
  context: 'SomeClassThatLoggedTheError',
  err: {
    type: 'UnauthorizedException',
    message: 'Unauthorized',
    stack: 'UnauthorizedException: Unauthorized\n' +
      ...
    response: {
      type: 'Object',
      message: 'Unauthorized',
      stack: '',
      statusCode: 401
    },
    status: 401,
    options: {},
    name: 'UnauthorizedException'
  },
  msg: 'Unauthorized'
}

I have found this line to be the reason why our logs are not logged as exceptions:

if (item.level !== 50 || item.type !== 'Error') { return }

Our logs are missing the item.type property all together. I guess this is because the apollo framework catches the error first and transformans them before we log them. So we dont log actual errors we log object containing the error info.

On the err property I do have the type of the original error but its not Error since we use custom errors.

So my question is. Do the really need the type check to see if we want to treat the item as an exception? Isnt it enough to just check the level and if its level === 50 we log it as an exception to application insights?

Your Environment

pino: 8.10.0
nestjs-pino: 3.1.2
pino-applicationinsights: 2.1.0
pino-http: 8.3.3

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

1 participant