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

Errors are not grouped correctly #31

Open
mlarcher opened this issue Mar 3, 2022 · 8 comments
Open

Errors are not grouped correctly #31

mlarcher opened this issue Mar 3, 2022 · 8 comments

Comments

@mlarcher
Copy link

mlarcher commented Mar 3, 2022

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
Copy link
Author

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...

@orengor
Copy link
Contributor

orengor commented Aug 4, 2022

Resolved in #40

@aandrewww
Copy link
Owner

thanks!
merged in #40

@guilhermeprokisch
Copy link

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

@orengor
Copy link
Contributor

orengor commented Aug 28, 2022

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.

@bodva
Copy link

bodva commented Mar 20, 2024

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

@trymbill
Copy link

trymbill commented Apr 6, 2024

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.

@bodva
Copy link

bodva commented Apr 8, 2024

@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

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

6 participants