diff --git a/ddtrace/settings/asm.py b/ddtrace/settings/asm.py index 95bafabd042..f2a56b51e8b 100644 --- a/ddtrace/settings/asm.py +++ b/ddtrace/settings/asm.py @@ -271,9 +271,7 @@ def _api_security_feature_active(self) -> bool: @property def _apm_opt_out(self) -> bool: - return ( - self._asm_enabled or self._iast_enabled or tracer_config._sca_enabled - ) and self._appsec_standalone_enabled + return (self._asm_enabled or self._iast_enabled or tracer_config._sca_enabled is True) and self._appsec_standalone_enabled @property def _user_event_mode(self) -> str: diff --git a/tests/contrib/flask/test_flask_appsec_iast.py b/tests/contrib/flask/test_flask_appsec_iast.py index 8d2f11d88d1..ca727d93acc 100644 --- a/tests/contrib/flask/test_flask_appsec_iast.py +++ b/tests/contrib/flask/test_flask_appsec_iast.py @@ -1379,8 +1379,6 @@ def setUp(self): ) ): super(FlaskAppSecIASTDisabledTestCase, self).setUp() - self.tracer._iast_enabled = False - self.tracer._asm_enabled = False self.tracer.configure(api_version="v0.4") @pytest.mark.skipif(not python_supported_by_iast(), reason="Python version not supported by IAST") diff --git a/tests/contrib/requests/test_requests_distributed.py b/tests/contrib/requests/test_requests_distributed.py index 8718eae5c96..9ca01372772 100644 --- a/tests/contrib/requests/test_requests_distributed.py +++ b/tests/contrib/requests/test_requests_distributed.py @@ -1,6 +1,7 @@ from requests_mock import Adapter from ddtrace import config +from ddtrace.settings.asm import config as asm_config from tests.utils import TracerTestCase from tests.utils import get_128_bit_trace_id_from_headers @@ -117,45 +118,48 @@ def matcher(request): def test_propagation_apm_opt_out_true(self): # ensure distributed tracing works when APM is opted out - self.tracer.enabled = False + with self.override_global_config(dict(_appsec_standalone_enabled=True, _asm_enabled=True)): + assert asm_config._apm_opt_out + self.tracer.enabled = False + cfg = config.get_from(self.session) + cfg["distributed_tracing"] = True + adapter = Adapter() + self.session.mount("mock", adapter) - cfg = config.get_from(self.session) - cfg["distributed_tracing"] = True - adapter = Adapter() - self.session.mount("mock", adapter) + with self.tracer.trace("root") as root: - with self.tracer.trace("root") as root: + def matcher(request): + return self.headers_here(self.tracer, request, root) - def matcher(request): - return self.headers_here(self.tracer, request, root) + adapter.register_uri("GET", "mock://datadog/foo", additional_matcher=matcher, text="bar") + resp = self.session.get("mock://datadog/foo") + assert 200 == resp.status_code + assert "bar" == resp.text - adapter.register_uri("GET", "mock://datadog/foo", additional_matcher=matcher, text="bar") - resp = self.session.get("mock://datadog/foo") - assert 200 == resp.status_code - assert "bar" == resp.text - - spans = self.pop_spans() - root, req = spans - assert "root" == root.name - assert "requests.request" == req.name - assert root.trace_id == req.trace_id - assert root.span_id == req.parent_id + spans = self.pop_spans() + root, req = spans + assert "root" == root.name + assert "requests.request" == req.name + assert root.trace_id == req.trace_id + assert root.span_id == req.parent_id def test_propagation_apm_opt_out_false(self): # ensure distributed tracing doesn't works when APM is disabled but not opted out - self.tracer.enabled = False + with self.override_global_config(dict(_appsec_standalone_enabled=False, _asm_enabled=True)): + assert not asm_config._apm_opt_out + self.tracer.enabled = False - cfg = config.get_from(self.session) - cfg["distributed_tracing"] = True - adapter = Adapter() - self.session.mount("mock", adapter) + cfg = config.get_from(self.session) + cfg["distributed_tracing"] = True + adapter = Adapter() + self.session.mount("mock", adapter) - with self.tracer.trace("root"): + with self.tracer.trace("root"): - def matcher(request): - return self.headers_not_here(self.tracer, request) + def matcher(request): + return self.headers_not_here(self.tracer, request) - adapter.register_uri("GET", "mock://datadog/foo", additional_matcher=matcher, text="bar") - resp = self.session.get("mock://datadog/foo") - assert 200 == resp.status_code - assert "bar" == resp.text + adapter.register_uri("GET", "mock://datadog/foo", additional_matcher=matcher, text="bar") + resp = self.session.get("mock://datadog/foo") + assert 200 == resp.status_code + assert "bar" == resp.text