Add experimental support for customizing tracer log levels#727
Conversation
|
Looks like |
|
For the API docs, it should be enough to just add an entry in API.md for the new configuration option. |
ericmustin
left a comment
There was a problem hiding this comment.
ergh not sure why this started a review for me but, updated PR from feedback, thanks again for taking a look!
|
@rochdev updated with feedback again, i think i've covered everything and appreciate the patience with all the back and forth here, feels like we're close. also my |
rochdev
left a comment
There was a problem hiding this comment.
A few small things but then it's good to go.
ericmustin
left a comment
There was a problem hiding this comment.
updated with feedback, still unclear why browser tests are failing though
|
@ericmustin Can you try to rebase? Hopefully this will fix the browser tests since I don't see why they would fail. |
…mental options, add tests
…mental options, add tests
8db71ba to
9c8e444
Compare
|
It looks like the build issue is because of BrowserStack credentials in CircleCI from a fork. I'll go ahead and merge it and if my theory is correct I'll contact CircleCI. |
#16174) ## Description <!-- Provide an overview of the change and motivation for the change --> Today, the ddtrace logger follows the root logger. If the root logger is in DEBUG mode, then ddtrace will also emit logs and the only way to override that is to set something like this: https://docs.datadoghq.com/tracing/troubleshooting/tracer_debug_logs/?tab=python#review-debug-logs ``` import logging # root logger configuration root_logger = logging.getLogger() root_logger.setLevel(logging.DEBUG) # override the ddtrace configuration to WARNING log level logging.getLogger("ddtrace").setLevel(logging.WARNING) ``` This change introduces a DD_TRACE_LOG_LEVEL setting that follows the logging levels in the logging module: https://docs.python.org/3/library/logging.html#levels . `DD_TRACE_DEBUG` will take precedence if set and set the tracer to debug. However, if DD_TRACE_LOG_LEVEL is used as a standalone, it can control the ddtrace logger setting. Example `DD_TRACE_LOG_LEVEL=CRITICAL` to only get critical logs instead of everything. In startup logs, I have the setting report as `log_level_override` to avoid confusion with the debug mode option someone may be trying to set: ``` - DATADOG TRACER CONFIGURATION - {... 'debug': True, ..... 'log_level_override': None} ``` Addresses APMS-18427 ## Testing <!-- Describe your testing strategy or note what tests are included --> Added tests that assert on the order of DD_TRACE_DEBUG and DD_TRACE_LOG_LEVEL . ## Risks <!-- Note any risks associated with this change, or "None" if no risks --> There really isn't a true "NO LOGS" setting if we follow these [logging levels](https://docs.python.org/3/library/logging.html#levels), so if we accept this PR, we need to avoid setting any critical logs unless it's an exceptional use case. ## Additional Notes <!-- Any other information that would be helpful for reviewers --> There have been various changes to how debug mode can be set over the years. Some questions I think will be asked of the reviewers and here's my answer: 1. Do other tracers have this setting? Yes. Java has DD_LOG_LEVEL: DataDog/dd-trace-java#7159 Node.js has DD_TRACE_LOG_LEVEL: DataDog/dd-trace-js#727 2. If DD_TRACE_DEBUG=debug, how is it different than setting DD_TRACE_LOG_LEVEL=debug? Won't they have the same problems? All DD_TRACE_DEBUG does today is enables debug mode if the user sets it to TRUE: https://github.com/DataDog/dd-trace-py/blob/c173a8a084b0f7f2a8cd081dbf9611208faa48e0/ddtrace/_logger.py#L53-L54. Setting it to "FALSE" has no effect if the root logger has already been configured. **DD_TRACE_LOG_LEVEL** is different in the sense that it allows us to override the log level setting beyond accepting DEBUG mode or accepting whatever the root logger's level was. --------- Co-authored-by: Munir Abdinur <[email protected]> Co-authored-by: Quinna Halim <[email protected]>
What does this PR do?
Following up on Feedback from PR-718 This PR addresses the use case introduced in Issue 599 for when a user wants to forward tracer errors to their logger but ignore debug messages.
This PR adds experimental support for an
experimental.ddTraceLogLevelsexperimental.logLevelconfiguration option as well asDD_TRACE_LOG_LEVELenvironment variable, which allow a user to specify thespecificminimum log levelsthat they'd like to permit from the tracer's logger. It accepts the format ofan array of strings such asa string such as['error','debug','info']as well as a comma separated value string such as'error,info''error'or'debug'.Motivation
Implementing feedback discussed from PR-718
Additional Notes
I tried to incorporate the feedback from PR-718 in this pull request. A few notes.
Some of the implementation is a bit clunky given that I am trying to target a future logger that hasn't been written or spec'd out, so I tried to leave things flexible enough that they can adjusted if there is a larger refactor of the default logger in the future. At a high level my approach was to give the user a few ways to set the tracer log levels they'd want logged, and then ideally not have to worry about changing that format if there's a larger refactor in the future / new log levels are added.
There's some helper methods for determining if the specific log level is enabled or not (
_isLogLevelEnabled) that I'd be open to feedback on if there's a better way to approach this. I tried to write a method that would automagically determine the log level's function name that was invoking it and check if that name had been whitelisted, however the approach to doing so seemed to rely on either outdated js concepts (using something likearguments.callee) or methods that might not play nicely when minified (specificallymyFunction.namehad some scary language around it in this S/O Note ). So the current approach is a bit clunky.Unclear how i ought to document this but happy to add docs/usage example to
api/docs.mdin this PR (i made the option experimental for now and it doesn't look like we really update that api/docs.md file until an option is "non-experimental").It's entirely possible i botched the typescript part of this, apologies if so, still need to level up with my TS.
Any and all feedback is welcome, and generally if it's better to shelve this until there's more clarity on what logging might look like after additional log lvls have been added, thats ok too. Just trying to unblock the folks who'd been asking for it.