Skip to content

Commit 00b6b37

Browse files
authored
chore: refactor logs injection configuration (#12921)
We refactor the logic for the enablement of log injection to avoid some potential circular imports. ## Checklist - [x] 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](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## 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](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) 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](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
1 parent e85cb52 commit 00b6b37

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

ddtrace/_logger.py

-12
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,3 @@ def _add_file_handler(
9090
logger.addHandler(ddtrace_file_handler)
9191
logger.debug("ddtrace logs will be routed to %s", log_path)
9292
return ddtrace_file_handler
93-
94-
95-
def _configure_log_injection():
96-
"""
97-
Ensures that logging is patched before we inject trace information into logs.
98-
"""
99-
from ddtrace import patch
100-
101-
patch(logging=True)
102-
ddtrace_logger = logging.getLogger("ddtrace")
103-
for handler in ddtrace_logger.handlers:
104-
handler.setFormatter(logging.Formatter(DD_LOG_FORMAT))

ddtrace/bootstrap/sitecustomize.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,20 @@
2222

2323
from ddtrace.internal.telemetry import telemetry_writer
2424
from ddtrace import config # noqa:F401
25-
from ddtrace._logger import _configure_log_injection
25+
from ddtrace._logger import DD_LOG_FORMAT
2626
from ddtrace.internal.logger import get_logger # noqa:F401
2727
from ddtrace.internal.module import ModuleWatchdog # noqa:F401
2828
from ddtrace.internal.module import is_module_installed
2929
from ddtrace.internal.utils.formats import asbool # noqa:F401
3030

3131
# Debug mode from the tracer will do the same here, so only need to do this otherwise.
3232
if config._logs_injection:
33-
_configure_log_injection()
33+
from ddtrace import patch
34+
35+
patch(logging=True)
36+
ddtrace_logger = logging.getLogger("ddtrace")
37+
for handler in ddtrace_logger.handlers:
38+
handler.setFormatter(logging.Formatter(DD_LOG_FORMAT))
3439

3540

3641
log = get_logger(__name__)

0 commit comments

Comments
 (0)