Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Dec 19, 2024
1 parent 6871715 commit 6cd501f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ddtrace/settings/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,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
self._asm_enabled or self._iast_enabled or tracer_config._sca_enabled is True
) and self._appsec_standalone_enabled

@property
Expand Down
2 changes: 0 additions & 2 deletions tests/contrib/flask/test_flask_appsec_iast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
66 changes: 35 additions & 31 deletions tests/contrib/requests/test_requests_distributed.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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

0 comments on commit 6cd501f

Please sign in to comment.