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

Improve exception logging #1992

Merged
merged 2 commits into from
May 3, 2022
Merged

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Apr 28, 2022

Ruby exceptions can have really confusing, vague, or even empty messages.

To help us out during debugging, I've added the exception class in exception-related logs to give us more context while debugging issues.

This is quite low-hanging fruit, but I think in general we have a long way to go in improving exception logging in dd-trace-rb.

In particular, we should probably look into centralizing exception logging in a method to solve the following:

  • Eliminate duplication. Can you spot how often I had to copy paste e.class.name in this PR?

  • There's a few cases where we just log the message, without any context. (I did not touch those)

  • The formatting of our error messages is quite inconsistent. Sometimes we include the backtrace, sometimes not. Sometimes we call the backtrace location, sometimes source, etc.

  • Sometimes we call the logger with a block (so that the string does not need to be generated if logging is disabled at that level), sometimes we just pass in a string.

  • There is no way to get the full stack trace, if we need to know more about where an error came from.

But... for now here's a smaller improvement.

This allows us to distinguish which product is originating the failed
requests, e.g.:

```
ERROR -- ddtrace: [ddtrace] (.../client.rb:38:in `rescue in send_request') Internal error during Datadog::Profiling::Transport::HTTP::Client request.
```

for profiling.
Ruby exceptions can have really confusing, vague, or even empty
messages.

To help us out during debugging, I've added the exception class in
exception-related logs to give us more context while debugging issues.

This is quite low-hanging fruit, but I think in general we have a long
way to go in improving exception logging in dd-trace-rb.

In particular, we should probably look into centralizing exception
logging in a method to solve the following:

* Eliminate duplication. Can you spot how often I had to copy paste
  `e.class.name` in this PR?

* There's a few cases where we just log the message, without any
  context. (I did not touch those)

* The formatting of our error messages is quite inconsistent.
  Sometimes we include the backtrace, sometimes not. Sometimes we
  call the backtrace location, sometimes source, etc.

* Sometimes we call the logger with a block (so that the string does
  not need to be generated if logging is disabled at that level),
  sometimes we just pass in a string.

* There is no way to get the full stack trace, if we need to know
  more about where an error came from.

But... for now here's a smaller improvement.
@ivoanjo ivoanjo requested a review from a team April 28, 2022 12:33
Copy link
Contributor

@lloeki lloeki left a comment

Choose a reason for hiding this comment

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

I like this, any improvement, however small, is welcome.

@ivoanjo
Copy link
Member Author

ivoanjo commented Apr 29, 2022

Cool! I'll hold off on pressing the magic button so we can finish putting 1.0.0 out :)

Copy link
Contributor

@delner delner left a comment

Choose a reason for hiding this comment

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

Does it make sense to extract some part of this error message formatting to a Utils function? Not a huge deal, but may be useful to get consistent behavior/formatting in the printed message.

@ivoanjo
Copy link
Member Author

ivoanjo commented May 3, 2022

Does it make sense to extract some part of this error message formatting to a Utils function? Not a huge deal, but may be useful to get consistent behavior/formatting in the printed message.

It does, a lot! But improving this is a bit of a rabbit hole, so I decided to take a small step, and leave further improvements for the future :)

@ivoanjo ivoanjo merged commit 7db4a60 into master May 3, 2022
@ivoanjo ivoanjo deleted the ivoanjo/add-exception-name-to-logs branch May 3, 2022 08:29
@github-actions github-actions bot added this to the 1.1.0 milestone May 3, 2022
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.

None yet

4 participants