Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions ddtrace/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ def _add_file_handler(
return ddtrace_file_handler


def set_log_formatting():
# type: () -> None
"""Sets the log format for the ddtrace logger."""
ddtrace_logger = logging.getLogger("ddtrace")
for handler in ddtrace_logger.handlers:
handler.setFormatter(logging.Formatter(DD_LOG_FORMAT))


def get_log_injection_state(raw_config: Optional[str]) -> bool:
"""Returns the current log injection state."""
if raw_config:
Expand Down
8 changes: 0 additions & 8 deletions ddtrace/contrib/internal/logging/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import ddtrace
from ddtrace import config
from ddtrace._logger import set_log_formatting
from ddtrace.contrib.internal.trace_utils import unwrap as _u
from ddtrace.internal.constants import LOG_ATTR_ENV
from ddtrace.internal.constants import LOG_ATTR_SERVICE
Expand Down Expand Up @@ -100,13 +99,6 @@ def patch():
_w(logging.Logger, "makeRecord", _w_makeRecord)
_w(logging.StrFormatStyle, "_format", _w_StrFormatStyle_format)

if config._logs_injection:
# Only set the formatter is DD_LOGS_INJECTION is set to True. We do not want to modify
# unstructured logs if a user has not enabled logs injection.
# Also, the Datadog log format must be set after the logging module has been patched,
# otherwise the formatter will raise an exception.
set_log_formatting()


def unpatch():
if getattr(logging, "_datadog_patch", False):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
logging: Fixed ddtrace internal logging when trace-log correlation is disabled.
Prevents ``ValueError: Formatting field not found in record: 'dd.service'``.
2 changes: 1 addition & 1 deletion tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def test_logging_during_tracer_init_succeeds_when_debug_logging_and_logs_injecti
assert out == b"", "an empty program should generate no logs under ddtrace-run"

assert (
b"[dd.service=ddtrace_subprocess_dir dd.env= dd.version= dd.trace_id=0 dd.span_id=0]" in err
b"[dd.service=ddtrace_subprocess_dir dd.env= dd.version= dd.trace_id=0 dd.span_id=0]" not in err
), "stderr should contain debug output when DD_TRACE_DEBUG is set"

assert b"KeyError: 'dd.service'" not in err, "stderr should not contain any exception logs"
Expand Down
Loading