Skip to content

Commit 8fe0cfa

Browse files
authored
chore(stable_config): collect debug logs when DD_TRACE_DEBUG is True (#13247)
## 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 - [x] 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 a5802e6 commit 8fe0cfa

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

ddtrace/internal/native/__init__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
from ._native import store_metadata # noqa: F401
1010

1111

12-
def get_configuration_from_disk(
13-
debug_logs: bool = False,
14-
) -> Tuple[Dict[str, str], Dict[str, str], Dict[str, Optional[str]]]:
12+
def get_configuration_from_disk() -> Tuple[Dict[str, str], Dict[str, str], Dict[str, Optional[str]]]:
1513
"""
1614
Retrieves the tracer configuration from disk. Calls the PyConfigurator object
1715
to read the configuration from the disk using the libdatadog shared library
1816
and returns the corresponding configuration
1917
See https://github.com/DataDog/libdatadog/blob/06d2b6a19d7ec9f41b3bfd4ddf521585c55298f6/library-config/src/lib.rs
2018
for more information on how the configuration is read from disk
2119
"""
20+
debug_logs = os.getenv("DD_TRACE_DEBUG", "false").lower().strip() in ("true", "1")
2221
configurator = PyConfigurator(debug_logs)
2322

2423
# Check if the file override is provided via environment variables

tests/internal/test_native.py

+32
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,38 @@ def test_get_configuration_from_disk_managed_stable_config_priority():
4040
assert config.version == "c", f"Expected DD_VERSION to be 'c' but got {config.version}"
4141

4242

43+
@pytest.mark.subprocess(parametrize={"DD_TRACE_DEBUG": ["TRUE", "1"]}, err=None)
44+
def test_get_configuration_debug_logs():
45+
"""
46+
Verify stable config debug log enablement
47+
"""
48+
import os
49+
import sys
50+
import tempfile
51+
52+
from tests.utils import call_program
53+
54+
# Create managed config
55+
with tempfile.NamedTemporaryFile(suffix=".yaml", prefix="managed_config") as managed_config:
56+
managed_config.write(
57+
b"""
58+
apm_configuration_default:
59+
DD_VERSION: "c"
60+
"""
61+
)
62+
managed_config.flush()
63+
64+
env = os.environ.copy()
65+
env["DD_TRACE_DEBUG"] = "true"
66+
env["_DD_SC_MANAGED_FILE_OVERRIDE"] = managed_config.name
67+
68+
_, err, status, _ = call_program(sys.executable, "-c", "import ddtrace", env=env)
69+
assert status == 0, err
70+
assert b"Read the following static config: StableConfig" in err
71+
assert b'ConfigMap([(DdVersion, "c")]), tags: {}, rules: [] }' in err
72+
assert b"configurator: Configurator { debug_logs: true }" in err
73+
74+
4375
@pytest.mark.subprocess(parametrize={"DD_VERSION": ["b", None]})
4476
def test_get_configuration_from_disk_local_config_priority(tmp_path):
4577
"""

0 commit comments

Comments
 (0)