Skip to content

Commit 619c4bf

Browse files
github-actions[bot]P403n1x87mabdinur
authored
fix(debugging): ensure dynamic instrumentation enabled [backport 1.18] (#6763)
Backport c98875a from #6618 to 1.18. With the introduction of exception debugging, the new enablement logic caused the dynamic instrumentation to not register with the remoteconfig client when the programmatic API was used, unless `DD_DYNAMIC_INSTRUMENTATION_ENABLED` is also set. Since this is not the documented behaviour, we make this fix to align with the expected behaviour of the programmatic API. ## 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: Gabriele N. Tornetta <[email protected]> Co-authored-by: Munir Abdinur <[email protected]>
1 parent fd669cf commit 619c4bf

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

ddtrace/debugging/_debugger.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ def enable(cls, run_module=False):
186186

187187
log.debug("Enabling %s", cls.__name__)
188188

189+
di_config.enabled = True
190+
189191
cls.__watchdog__.install()
190192

191193
if di_config.metrics:
@@ -215,6 +217,8 @@ def disable(cls, join=True):
215217

216218
log.debug("Disabling %s", cls.__name__)
217219

220+
remoteconfig_poller.unregister("LIVE_DEBUGGING")
221+
218222
forksafe.unregister(cls._restart)
219223
atexit.unregister(cls.disable)
220224
unregister_post_run_module_hook(cls._on_run_module)
@@ -229,6 +233,8 @@ def disable(cls, join=True):
229233
if di_config.metrics:
230234
metrics.disable()
231235

236+
di_config.enabled = False
237+
232238
log.debug("%s disabled", cls.__name__)
233239

234240
def __init__(self, tracer=None):
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
dynamic instrumentation: Fixed the programmatic API to ensure that the
5+
dynamic instrumentation service is fully enabled when
6+
``Dynamic Instrumentation.enable()`` is called.

tests/debugging/test_api.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import pytest
22

3-
from ddtrace.debugging import DynamicInstrumentation
4-
53

64
@pytest.mark.subprocess(ddtrace_run=True, env=dict(DD_DYNAMIC_INSTRUMENTATION_ENABLED="true"), err=None)
75
def test_debugger_enabled_ddtrace_run():
@@ -17,12 +15,20 @@ def test_debugger_disabled_ddtrace_run():
1715
assert DynamicInstrumentation._instance is None
1816

1917

18+
@pytest.mark.subprocess
2019
def test_debugger_enabled_programmatically():
20+
from ddtrace.internal.remoteconfig.worker import remoteconfig_poller
21+
22+
assert "LIVE_DEBUGGING" not in remoteconfig_poller._client._products
23+
from ddtrace.debugging import DynamicInstrumentation
24+
2125
DynamicInstrumentation.enable()
2226
assert DynamicInstrumentation._instance is not None
27+
assert "LIVE_DEBUGGING" in remoteconfig_poller._client._products
2328

2429
DynamicInstrumentation.disable()
2530
assert DynamicInstrumentation._instance is None
31+
assert "LIVE_DEBUGGING" not in remoteconfig_poller._client._products
2632

2733

2834
@pytest.mark.subprocess(err=None)

0 commit comments

Comments
 (0)