feat: add an option to log ddtrace logs to a file#3214
Merged
Conversation
brettlangdon
reviewed
Feb 1, 2022
… what to do with log levels when not specified.
brettlangdon
reviewed
Feb 2, 2022
Co-authored-by: Brett Langdon <[email protected]>
update changes from latest
Contributor
|
@wantsui this pull request is now in conflict 😩 |
brettlangdon
left a comment
Member
There was a problem hiding this comment.
nice. mostly minor nits, this is looking good!
Co-authored-by: Brett Langdon <[email protected]>
Co-authored-by: Brett Langdon <[email protected]>
…e file bytes in a variable.
Co-authored-by: Brett Langdon <[email protected]>
…. Use asbool in configuration.
Co-authored-by: Brett Langdon <[email protected]>
Co-authored-by: Brett Langdon <[email protected]>
…te asserts on log content
mabdinur
reviewed
Jun 10, 2022
mabdinur
reviewed
Jun 10, 2022
mabdinur
left a comment
Contributor
There was a problem hiding this comment.
some nits about tests and doc strings. We should revisit some of the parameterized tests and see if some parameters can be removed
Co-authored-by: Brett Langdon <[email protected]>
…light renaming of code in _logger.
Co-authored-by: Brett Langdon <[email protected]>
ZStriker19
reviewed
Jun 16, 2022
update with 1.x changes.
update with 1.x changes
brettlangdon
approved these changes
Jun 16, 2022
ZStriker19
approved these changes
Jun 16, 2022
ZStriker19
left a comment
Collaborator
There was a problem hiding this comment.
Super excited for this one! Awesome work!
4 tasks
14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR follows up on the discussion in #2603 to add options for
ddtracelogs to be written to a file. This is useful when troubleshooting.Environment Variables
This PR introduces three new environment variables:
DD_TRACE_LOG_FILE- when used with debug mode, this forwardsddtracelogs to a specific file.DD_TRACE_LOG_FILE_SIZE_BYTES- when used, sets the max file size. The default is 15 mb.DD_TRACE_LOG_FILE_LEVELused to control the log level defined for theRotatingFileHandler. It will accept values such as DEBUG, WARNING, ERROR, etc based on the logging library.How it works
DD_TRACE_DEBUGcontrols the log level of theddtracelogger, whileDD_TRACE_LOG_FILE_LEVELcontrols the log level of theRotatingFileHandlerused with file creation.DD_TRACE_LOG_FILE_LEVELdefaults to debug mode, but logs aren't written unlessDD_TRACE_LOG_FILEis configured.ddtracefollow the configured used byddtrace.* Exception: The ddtrace-run logs under commands/ddtrace-run do not use
DD_TRACE_LOG_FILEifDD_TRACE_DEBUGis enabled.* Example: Logs that start with
program executableddtraceis imported relative tologgingwhen usingpatch_all/patch.loggingmodule from the standard Python library.DD_TRACE_DEBUG=true, a basic logging handler will need to be configured,ie:
logging.basicConfig(). Otherwise, console logs will not be emitted due toNo handlers could be found for logger "ddtrace". This logging behavior does not occur in Python 3.Example usage
To get debug level logs written to a file:
DD_TRACE_DEBUG=trueDD_TRACE_LOG_FILE=/path/to/my/debuglogsDD_TRACE_LOG_FILE_LEVEL=DEBUGDD_TRACE_LOG_FILE=/path/to/my/debuglogsSummary of Options
Further customization of the logging configuration is possible:
ddtraceare emitted to the stderr equivalent. / RotatingFileHandler: Not configured.ddtraceare emitted to a file path, depending onDD_TRACE_LOG_FILE_LEVEL. When the file has reachedDD_TRACE_FILE_SIZE_BYTESbytes, it will create 1 backup log file.ddtraceare emitted to the stderr equivalent. / RotatingFileHandler: Not configured.ddtraceare emitted to a file path. When the file has reachedDD_TRACE_FILE_SIZE_BYTESbytes, it will create 1 backup log file.ddtraceare set to emit up to DEBUG logs. Up to WARNING/CRITICAL/ERROR/INFO based onDD_TRACE_LOG_FILE_LEVELget written to the logs. When the file has reachedDD_TRACE_FILE_SIZE_BYTES bytes, it will create 1 backup log file.Checklist