Skip to content

change the traceback format to print in one line #362

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

Merged
merged 4 commits into from
Aug 22, 2023

Conversation

joeyzhao2018
Copy link
Contributor

@joeyzhao2018 joeyzhao2018 commented Aug 22, 2023

What does this PR do?

Format the traceback printout to one line

Motivation

Otherwise the printout would be split into multiple lines and would be hard to read and search.

Testing Guidelines

This trick is just to replace \n with \r and the result looks like this:

Before:
Screenshot 2023-08-22 at 10 03 38 AM

After:
Screenshot 2023-08-22 at 10 04 15 AM

If we replace with \n with \\n instead:
Screenshot 2023-08-22 at 10 49 26 AM

Additional Notes

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

@joeyzhao2018 joeyzhao2018 marked this pull request as ready for review August 22, 2023 14:13
@joeyzhao2018 joeyzhao2018 requested a review from a team as a code owner August 22, 2023 14:13
traceback.print_exc()
except Exception as e:
logger.error(
"Error %s. Traceback: %s", e, traceback.format_exc().replace("\n", "\r")
Copy link
Contributor

Choose a reason for hiding this comment

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

oh interesting. This is good, but is there no default method for tracebacks which does this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i don't think so. it seems that python just uses \n. i saw some people replace it with \\n. i added a screen shot in the description to show the difference.

traceback.print_exc()
except Exception as e:
logger.error(
"Error %s. Traceback: %s", e, traceback.format_exc().replace("\n", "\r")
Copy link
Contributor

Choose a reason for hiding this comment

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

One minor nit, we might consider splitting this out into a small util method, as we've got it in a few places and there doesn't seem to be something we'd change depending on input. Maybe the message? Even that can be a param.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

been thinking about this. will do.

@joeyzhao2018 joeyzhao2018 merged commit 75d7858 into main Aug 22, 2023
@joeyzhao2018 joeyzhao2018 deleted the joey/fix_traceback_fmt branch August 22, 2023 15:44
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.

2 participants