winston-transport-sentry-node icon indicating copy to clipboard operation
winston-transport-sentry-node copied to clipboard

Errors are not grouped correctly

Open mlarcher opened this issue 3 years ago • 8 comments
trafficstars

Hi,

We have trouble on Sentry's side because errors alerting is not working as expected. As it turns out, Sentry is grouping errors according to stack trace, and the stack trace is always the same regardless of where the error originated in our code.

For example, if we call logger.error('Some message', { error: err, requestId }); in line 12 of codefile.js, we want errors to be location according to that location, and instead we currently have /app/node_modules/winston-transport-sentry-node/dist/transport.js in SentryTransport.log at line 72:64 for all errors

Is there a way to preserve the stack trace from the location logger.error was called instead of overriding it ?

mlarcher avatar Mar 03 '22 13:03 mlarcher

After some digging in the code, I understand that there is no stack trace at first as we provide a message and not an error object. I would expect the lib to just forward the message though, instead of trying to generate a real error object with a useless stack trace...

mlarcher avatar Mar 10 '22 09:03 mlarcher

Resolved in #40

orengor avatar Aug 04 '22 13:08 orengor

thanks! merged in #40

aandrewww avatar Aug 04 '22 14:08 aandrewww

It's was solved? I still getting useless node_modules traces when I use logger.error

guilhermeprokisch avatar Aug 26 '22 02:08 guilhermeprokisch

It's was solved? I still getting useless node_modules traces when I use logger.error

Should work if you're on the current version and pass an Error object in the info param.

orengor avatar Aug 28 '22 08:08 orengor

@orengor can you give an example how it should be passed correcly?

bodva avatar Mar 20 '24 17:03 bodva

Running log.error('Testing 12345') results in Sentry grouping an Error under SentryTransport._SentryTransport.log:

Screenshot 2024-04-05 at 22 44 30

Which makes the stack trace pretty useless:

Screenshot 2024-04-05 at 22 44 20

Is this really how people are using this transport, or am I missing something? I would've assumed the trace would be tied to the log.error() call itself, not the underlying SentryTransport._SentryTransport.log method.

trymbill avatar Apr 06 '24 05:04 trymbill

@trymbill , @jadesym and everyone who comes here with a question about how to log errors properly using this transport and Winston with node (nests) in general: the easy way to do this it is log just error, without adding a message, something like this:

try {
  return await this.userService.profileUpdate(
    authPayload._id,
    updateProfileDto,
  );
} catch (e) {
  this.logger.error(e);
}

If you want to show and log with more details you should pass your own object into the logger, instead of splitting the error into parameters, so yor detailed error will looks like:

this.logger.debug({
  message: 'Object stored successfully',
  context: this.constructor.name,
  object,
});

Using this style of logging, you will receive properly handled errors on sentry, and properly handled errors in your other transport. Example of properly logger error here:

CleanShot 2024-04-08 at 12 01 20

bodva avatar Apr 08 '24 09:04 bodva