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

Fix stacktrace format for rollbar #5

Merged
merged 11 commits into from
Jun 19, 2023
Merged

Conversation

catnstein
Copy link

No description provided.

Copy link

@dominik1001 dominik1001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment

const logMethod = this.rollbar[rollbarLevel] || this.rollbar.log;
return logMethod.apply(this.rollbar, [message, meta, cb]);
return logMethod.apply(this.rollbar, [message, info, new Error(info.stack), cb]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new error here seems wrong to me

#getErrorObject(info) {
if (info.message instanceof Error) {
return info.message;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great function 👏 ! I'd change to put the return in one line, like that:

if (info.message instanceof Error) return info.message;

expect(rollbarMock.error).toHaveBeenCalledWith(new Error(logData.message), logData, expect.any(Function));
})
});
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strong tests 💪

Copy link

@dominik1001 dominik1001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am through. 😮‍💨

  1. The API of winston is not very clear and developer-friendly IMO. There is a lot of discussion about this topic.
    [3.0.0] Error object is not parsed or printed winstonjs/winston#1338

  2. When you use logger.error(err) the err becomes the message, so in general the original implementation is correct.

  3. However, to properly log errors rollbar expects the errors to be passed to rollbar.error(err). This was not happening due to two reasons:

A) We use the colorizer before passing data to rollbar. That is why this this.rollbar[rollbarLevel] is not working because rollbarLevel is not error but somethingerrorsomething. The colorizer should only be used for console and papertrail.

B) We format this error before passing it to rollbar

util.format(info.message, ...(info.splat || []));

We should not do that for errors.

So if we fix A and B everything should work.

I don't really like line 34 because it suggests that we can only log errors to rollbar which is not true. And I think even though the API sucks the caller should always make sure that the error object is properly passed as the message.

@catnstein
Copy link
Author

I am through. 😮‍💨

  1. The API of winston is not very clear and developer-friendly IMO. There is a lot of discussion about this topic.
    [3.0.0] Error object is not parsed or printed winstonjs/winston#1338
  2. When you use logger.error(err) the err becomes the message, so in general the original implementation is correct.
  3. However, to properly log errors rollbar expects the errors to be passed to rollbar.error(err). This was not happening due to two reasons:

A) We use the colorizer before passing data to rollbar. That is why this this.rollbar[rollbarLevel] is not working because rollbarLevel is not error but somethingerrorsomething. The colorizer should only be used for console and papertrail.

B) We format this error before passing it to rollbar

util.format(info.message, ...(info.splat || []));

We should not do that for errors.

So if we fix A and B everything should work.

I don't really like line 34 because it suggests that we can only log errors to rollbar which is not true. And I think even though the API sucks the caller should always make sure that the error object is properly passed as the message.

@dominik1001 I've reimplemented the log function, everything should be logged correctly now. Thanks so much for the help 🙏

Copy link

@dominik1001 dominik1001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks quite good. Two last small things.

@@ -28,24 +28,27 @@ class RollbarTransport extends TransportStream {
}

log(info, callback) {
const {level, message} = info;
process.nextTick(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're changing a lot of code where I guess it's unclear why it was there in the first place. The git history doesn't tell a good story, and without unit tests it's hard to say why that has been there in the first place, so I think it's ok.

delete meta.splat;
delete meta[Symbol.for('level')];

if (level === 'error') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things I'd still add however.

  1. There is no fallback, when the level is something else. I'd leave that to rollbar.log or ino
  2. warning used to work as warn before, we could still keep that

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added fallback to info 👍

@catnstein catnstein merged commit ff7cd44 into main Jun 19, 2023
@catnstein catnstein deleted the fix-stacktrace-format-for-rollbar branch June 19, 2023 09:39
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

Successfully merging this pull request may close these issues.

3 participants