Skip to content

chore: configurable logger levels #13562

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

P403n1x87
Copy link
Contributor

@P403n1x87 P403n1x87 commented Jun 2, 2025

We introduce private enviornment variables that allow configuring the log level of the ddtrace loggers. This allows for fine-grained control over the logger levels, making debugging easier by reducing the noise of logs. For example, setting _DD_DEBUGGING_LOG_LEVEL=DEBUG would enable debug logs for any loggers under ddtrace.debugging only.

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

We introduce private enviornment variables that allow configuring the
log level of the ddtrace loggers. This allows for fine-grained control
over the logger levels, making debugging easier by reducing the noise of
logs.
Copy link
Contributor

github-actions bot commented Jun 2, 2025

CODEOWNERS have been resolved as:

ddtrace/internal/logger.py                                              @DataDog/apm-core-python
tests/tracer/test_logger.py                                             @DataDog/apm-sdk-api-python

@P403n1x87 P403n1x87 added the changelog/no-changelog A changelog entry is not required for this PR. label Jun 2, 2025
Copy link
Contributor

github-actions bot commented Jun 2, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 279 ± 6 ms.

The average import time from base is: 281 ± 7 ms.

The import time difference between this PR and base is: -1.7 ± 0.3 ms.

Import time breakdown

The following import paths have appeared:

ddtrace.auto 7.188 ms (2.57%)
ddtrace 7.188 ms (2.57%)
ddtrace._logger 7.188 ms (2.57%)
ddtrace.internal.telemetry 7.188 ms (2.57%)
ddtrace.internal.logger 7.188 ms (2.57%)
dataclasses 7.188 ms (2.57%)
inspect 6.354 ms (2.27%)
ast 2.317 ms (0.83%)
_ast 1.202 ms (0.43%)
dis 1.469 ms (0.53%)
opcode 0.588 ms (0.21%)
_opcode 0.160 ms (0.06%)
importlib.machinery 0.235 ms (0.08%)
importlib 0.173 ms (0.06%)
copy 0.198 ms (0.07%)

The following import paths have disappeared:

ddtrace.auto 7.706 ms (2.76%)
ddtrace 7.706 ms (2.76%)
ddtrace._logger 7.706 ms (2.76%)
ddtrace.internal.telemetry 7.706 ms (2.76%)
ddtrace.settings._agent 7.706 ms (2.76%)
ddtrace.settings 7.706 ms (2.76%)
ddtrace.settings.http 7.510 ms (2.69%)
ddtrace.internal.utils.cache 6.869 ms (2.46%)
inspect 6.869 ms (2.46%)
ast 2.349 ms (0.84%)
_ast 1.211 ms (0.43%)
dis 1.480 ms (0.53%)
opcode 0.605 ms (0.22%)
_opcode 0.165 ms (0.06%)
importlib.machinery 0.232 ms (0.08%)
importlib 0.170 ms (0.06%)
ddtrace.internal.utils.http 0.641 ms (0.23%)
dataclasses 0.641 ms (0.23%)
ddtrace._hooks 0.196 ms (0.07%)
copy 0.196 ms (0.07%)

The following import paths have grown:

ddtrace.auto 1.581 ms (0.57%)
ddtrace 1.581 ms (0.57%)
ddtrace._logger 1.581 ms (0.57%)
ddtrace.internal.telemetry 1.581 ms (0.57%)
ddtrace.internal.logger 0.909 ms (0.33%)
ddtrace.internal.utils.formats 0.586 ms (0.21%)
ddtrace.internal.compat 0.586 ms (0.21%)
pathlib 0.586 ms (0.21%)
ddtrace.settings._agent 0.086 ms (0.03%)
ddtrace.settings 0.086 ms (0.03%)
ddtrace.settings.http 0.086 ms (0.03%)
ddtrace.internal.utils.http 0.086 ms (0.03%)
email.encoders 0.086 ms (0.03%)
base64 0.086 ms (0.03%)
struct 0.086 ms (0.03%)
_struct 0.086 ms (0.03%)

The following import paths have shrunk:

ddtrace.auto 2.445 ms (0.87%)
ddtrace.bootstrap.sitecustomize 1.373 ms (0.49%)
ddtrace.bootstrap.preload 1.373 ms (0.49%)
ddtrace.internal.remoteconfig.client 0.649 ms (0.23%)
ddtrace 1.072 ms (0.38%)
ddtrace._logger 0.387 ms (0.14%)
ddtrace.internal.telemetry 0.387 ms (0.14%)
ddtrace.settings._agent 0.248 ms (0.09%)
ddtrace.settings 0.248 ms (0.09%)
ddtrace.settings.http 0.248 ms (0.09%)
ddtrace.internal.utils.http 0.248 ms (0.09%)
email.encoders 0.088 ms (0.03%)
base64 0.072 ms (0.03%)
email 0.016 ms (0.01%)
ddtrace.internal.utils.formats 0.139 ms (0.05%)
ddtrace.internal.compat 0.139 ms (0.05%)
ddtrace.internal._unpatched 0.034 ms (0.01%)
json 0.034 ms (0.01%)
json.decoder 0.034 ms (0.01%)
re 0.034 ms (0.01%)
enum 0.034 ms (0.01%)
types 0.034 ms (0.01%)

@pr-commenter
Copy link

pr-commenter bot commented Jun 2, 2025

Benchmarks

Benchmark execution time: 2025-06-12 17:01:51

Comparing candidate commit e9ae14d in PR branch chore/ddtrace-logger-level with baseline commit 140c2b9 in branch main.

Found 0 performance improvements and 1 performance regressions! Performance is the same for 555 metrics, 6 unstable metrics.

scenario:iastaspectsospath-ospathsplitdrive_aspect

  • 🟥 execution_time [+356.703ns; +424.484ns] or [+9.750%; +11.603%]

@P403n1x87 P403n1x87 marked this pull request as ready for review June 10, 2025 10:01
@P403n1x87 P403n1x87 requested a review from a team as a code owner June 10, 2025 10:01
@P403n1x87 P403n1x87 requested a review from brettlangdon June 10, 2025 10:01
@P403n1x87 P403n1x87 enabled auto-merge (squash) June 10, 2025 10:02
Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

tests?

@P403n1x87
Copy link
Contributor Author

tests?

I can add them if we're all onboard with merging this change 🙂

@emmettbutler emmettbutler self-requested a review June 12, 2025 14:30
@P403n1x87 P403n1x87 requested a review from a team as a code owner June 12, 2025 15:14
@P403n1x87 P403n1x87 requested a review from ZStriker19 June 12, 2025 15:14
print(dd_logger.LOG_LEVEL_TRIE)

try:
assert get_logger("ddtrace.testing.debug.foo.bar").level == logging.DEBUG
Copy link
Member

Choose a reason for hiding this comment

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

we shouldn't have to manually set the level for all children.... right?

meaning _DD_TESTING_DEBUG_LOG_LEVEL=DEBUG should only set the level on testing.debug only, and not on .foo or .foo.bar.

You should evaluate via .isEnabledFor(logging.DEBUG) instead of .level == logging.DEBUG, since that takes into account it's parents settings as well:

>>> a = logging.getLogger("a")
>>> b = logging.getLogger("a.b")
>>> a.setLevel(logging.DEBUG)
>>> b.isEnabledFor(logging.DEBUG)
True
>>> a.setLevel(logging.ERROR)
>>> b.isEnabledFor(logging.DEBUG)
False

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah that's a good point, but what if the logger for a is never created? 🤔

Copy link
Collaborator

@emmettbutler emmettbutler left a comment

Choose a reason for hiding this comment

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

This makes sense to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog A changelog entry is not required for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants