Skip to content

Commit 24c2632

Browse files
fix(logging): configuration debug call [backport 1.20] (#7566)
Backport 0800d81 from #6252 to 1.20. 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 033e9b3 commit 24c2632

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
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
@@ -540,7 +539,7 @@ def _generate_diagnostic_logs(self):
540539
self._log_compat(logging.WARNING, "- DATADOG TRACER DIAGNOSTIC - %s" % msg)
541540
else:
542541
if log.isEnabledFor(logging.INFO):
543-
msg = "- DATADOG TRACER CONFIGURATION - %s" % json.dumps(info)
542+
msg = "- DATADOG TRACER CONFIGURATION - %s" % info
544543
self._log_compat(logging.INFO, msg)
545544

546545
# 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
@@ -235,6 +235,7 @@ unpatch
235235
unpatched
236236
unobfuscated
237237
unregister
238+
unserializable
238239
unshallow
239240
unvendored
240241
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: 4 additions & 0 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

0 commit comments

Comments
 (0)