Skip to content

Commit 7a0db4e

Browse files
fix(logging): configuration debug call [backport 2.1] (#7568)
Backport 0800d81 from #6252 to 2.1. Trying to run with DD_TRACE_DEBUG set and the agent writer fails with `TypeError: Object of type AgentWriter is not JSON serializable`. This fixes it. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] 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) Co-authored-by: Thomas Hervé <[email protected]>
1 parent 65c7a16 commit 7a0db4e

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

ddtrace/tracer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import functools
22
from itertools import chain
3-
import json
43
import logging
54
import os
65
from os import environ
@@ -519,7 +518,7 @@ def _generate_diagnostic_logs(self):
519518
self._log_compat(logging.WARNING, "- DATADOG TRACER DIAGNOSTIC - %s" % msg)
520519
else:
521520
if log.isEnabledFor(logging.INFO):
522-
msg = "- DATADOG TRACER CONFIGURATION - %s" % json.dumps(info)
521+
msg = "- DATADOG TRACER CONFIGURATION - %s" % info
523522
self._log_compat(logging.INFO, msg)
524523

525524
# Always log errors since we're either in debug_mode or start up logs

docs/spelling_wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ unpatch
240240
unpatched
241241
unobfuscated
242242
unregister
243+
unserializable
243244
unshallow
244245
unvendored
245246
uri
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
tracing: This fix resolves an issue where unserializable tracer attributes caused crashes when
5+
``DD_TRACE_DEBUG`` was set.

tests/integration/test_debug.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ddtrace.internal import debug
1717
from ddtrace.internal.compat import PY2
1818
from ddtrace.internal.compat import PY3
19+
from ddtrace.internal.writer import AgentWriter
1920
from ddtrace.internal.writer import TraceWriter
2021
import ddtrace.sampler
2122
from tests.subprocesstest import SubprocessTestCase
@@ -197,6 +198,9 @@ def test_tracer_loglevel_info_connection(self):
197198
tracer = ddtrace.Tracer()
198199
logging.basicConfig(level=logging.INFO)
199200
with mock.patch.object(logging.Logger, "log") as mock_logger:
201+
# shove an unserializable object into the config log output
202+
# regression: this used to cause an exception to be raised
203+
ddtrace.config.version = AgentWriter(agent_url="foobar")
200204
tracer.configure()
201205
assert mock.call(logging.INFO, re_matcher("- DATADOG TRACER CONFIGURATION - ")) in mock_logger.mock_calls
202206

@@ -316,20 +320,16 @@ def test_custom_writer():
316320
tracer = ddtrace.Tracer()
317321

318322
class CustomWriter(TraceWriter):
319-
def recreate(self):
320-
# type: () -> TraceWriter
323+
def recreate(self) -> TraceWriter:
321324
return self
322325

323-
def stop(self, timeout=None):
324-
# type: (Optional[float]) -> None
326+
def stop(self, timeout: Optional[float] = None) -> None:
325327
pass
326328

327-
def write(self, spans=None):
328-
# type: (Optional[List[Span]]) -> None
329+
def write(self, spans: Optional[List[Span]] = None) -> None:
329330
pass
330331

331-
def flush_queue(self):
332-
# type: () -> None
332+
def flush_queue(self) -> None:
333333
pass
334334

335335
tracer._writer = CustomWriter()

0 commit comments

Comments
 (0)