From fefa3620cf9ddde165afe0d29090d34e0d5e9b06 Mon Sep 17 00:00:00 2001 From: Munir Abdinur Date: Mon, 23 Dec 2024 20:09:38 -0500 Subject: [PATCH] fix failing tracer, profiling, stats, and integration tests --- tests/integration/test_debug.py | 5 ++-- tests/integration/test_trace_stats.py | 16 ++++++----- tests/profiling/test_profiler.py | 38 ++++++++++++++++++++++----- tests/tracer/test_tracer.py | 5 +++- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/tests/integration/test_debug.py b/tests/integration/test_debug.py index e699db36d6b..9b04d861589 100644 --- a/tests/integration/test_debug.py +++ b/tests/integration/test_debug.py @@ -19,6 +19,7 @@ import ddtrace.sampler from tests.subprocesstest import SubprocessTestCase from tests.subprocesstest import run_in_subprocess +from tests.utils import DummyTracer from .test_integration import AGENT_VERSION @@ -111,7 +112,7 @@ def test_standard_tags(): def test_debug_post_configure(): - tracer = ddtrace.Tracer() + tracer = DummyTracer() tracer.configure( hostname="0.0.0.0", port=1234, @@ -131,7 +132,7 @@ def test_debug_post_configure(): # Tracer doesn't support re-configure()-ing with a UDS after an initial # configure with normal http settings. So we need a new tracer instance. - tracer = ddtrace.Tracer() + tracer = DummyTracer() tracer.configure(uds_path="/file.sock") f = debug.collect(tracer) diff --git a/tests/integration/test_trace_stats.py b/tests/integration/test_trace_stats.py index 0fd7695fc23..e4ffde3d81b 100644 --- a/tests/integration/test_trace_stats.py +++ b/tests/integration/test_trace_stats.py @@ -5,12 +5,12 @@ import mock import pytest -from ddtrace import Tracer from ddtrace.constants import SPAN_MEASURED_KEY from ddtrace.ext import http from ddtrace.internal.processor.stats import SpanStatsProcessorV06 from ddtrace.sampler import DatadogSampler from ddtrace.sampler import SamplingRule +from tests.utils import DummyTracer from tests.utils import override_global_config from .test_integration import AGENT_VERSION @@ -21,9 +21,8 @@ @pytest.fixture def stats_tracer(): - # type: (float) -> Generator[Tracer, None, None] with override_global_config(dict(_trace_compute_stats=True)): - tracer = Tracer() + tracer = DummyTracer() yield tracer tracer.shutdown() @@ -70,7 +69,7 @@ def test_compute_stats_default_and_configure(run_python_code_in_subprocess, envv """Ensure stats computation can be enabled.""" # Test enabling via `configure` - t = Tracer() + t = DummyTracer() assert not t._compute_stats assert not any(isinstance(p, SpanStatsProcessorV06) for p in t._span_processors) t.configure(compute_stats_enabled=True) @@ -100,14 +99,16 @@ def test_compute_stats_default_and_configure(run_python_code_in_subprocess, envv assert status == 0, out + err -def test_apm_opt_out_compute_stats_and_configure(run_python_code_in_subprocess): +@pytest.mark.subprocess(err=b"WARNING:root:IAST not enabled but native module is being loaded\n") +def test_apm_opt_out_compute_stats_and_configure(): """ Ensure stats computation is disabled, but reported as enabled, if APM is opt-out. """ + from ddtrace import tracer as t + from ddtrace.internal.processor.stats import SpanStatsProcessorV06 # Test via `configure` - t = Tracer() assert not t._compute_stats assert not any(isinstance(p, SpanStatsProcessorV06) for p in t._span_processors) t.configure(appsec_enabled=True, appsec_standalone_enabled=True) @@ -116,8 +117,9 @@ def test_apm_opt_out_compute_stats_and_configure(run_python_code_in_subprocess): assert not t._compute_stats # but it's reported as enabled assert t._writer._headers.get("Datadog-Client-Computed-Stats") == "yes" - t.configure(appsec_enabled=False, appsec_standalone_enabled=False) + +def test_apm_opt_out_compute_stats_and_configure_env(run_python_code_in_subprocess): # Test via environment variable env = os.environ.copy() env.update({"DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED": "true", "DD_APPSEC_ENABLED": "true"}) diff --git a/tests/profiling/test_profiler.py b/tests/profiling/test_profiler.py index 7f98bbf6aa8..de321e73833 100644 --- a/tests/profiling/test_profiler.py +++ b/tests/profiling/test_profiler.py @@ -232,36 +232,61 @@ def _check_url(prof, url, api_key, endpoint_path="profiling/v1/input"): pytest.fail("Unable to find HTTP exporter") +@pytest.mark.subprocess() def test_tracer_url(): - t = ddtrace.Tracer() + import os + + from ddtrace import tracer as t + from ddtrace.profiling import profiler + t.configure(hostname="foobar") prof = profiler.Profiler(tracer=t) _check_url(prof, "http://foobar:8126", os.environ.get("DD_API_KEY")) +@pytest.mark.subprocess() def test_tracer_url_https(): - t = ddtrace.Tracer() + import os + + from ddtrace import tracer as t + from ddtrace.profiling import profiler + t.configure(hostname="foobar", https=True) prof = profiler.Profiler(tracer=t) _check_url(prof, "https://foobar:8126", os.environ.get("DD_API_KEY")) +@pytest.mark.subprocess() def test_tracer_url_uds_hostname(): - t = ddtrace.Tracer() + import os + + from ddtrace import tracer as t + from ddtrace.profiling import profiler + t.configure(hostname="foobar", uds_path="/foobar") prof = profiler.Profiler(tracer=t) _check_url(prof, "unix://foobar/foobar", os.environ.get("DD_API_KEY")) +@pytest.mark.subprocess() def test_tracer_url_uds(): - t = ddtrace.Tracer() + import os + + from ddtrace import tracer as t + from ddtrace.profiling import profiler + t.configure(uds_path="/foobar") prof = profiler.Profiler(tracer=t) _check_url(prof, "unix:///foobar", os.environ.get("DD_API_KEY")) +@pytest.mark.subprocess() def test_tracer_url_configure_after(): - t = ddtrace.Tracer() + import os + + from ddtrace import tracer as t + from ddtrace.profiling import profiler + prof = profiler.Profiler(tracer=t) t.configure(hostname="foobar") _check_url(prof, "http://foobar:8126", os.environ.get("DD_API_KEY")) @@ -276,11 +301,10 @@ def test_env_no_api_key(): def test_env_endpoint_url(): import os - import ddtrace + from ddtrace import tracer as t from ddtrace.profiling import profiler from tests.profiling.test_profiler import _check_url - t = ddtrace.Tracer() prof = profiler.Profiler(tracer=t) _check_url(prof, "http://foobar:123", os.environ.get("DD_API_KEY")) diff --git a/tests/tracer/test_tracer.py b/tests/tracer/test_tracer.py index 0978e3ae92b..21972d44492 100644 --- a/tests/tracer/test_tracer.py +++ b/tests/tracer/test_tracer.py @@ -2106,8 +2106,11 @@ def test_multiple_tracer_instances(): import ddtrace assert ddtrace.tracer is not None - assert len(warns) == 0 + for w in warns: + # Ensure the warning is not about multiple tracer instances is not logged when importing ddtrace + assert "Support for multiple Tracer instances is deprecated" not in str(w.message) + warns.clear() t = ddtrace.Tracer() assert t is ddtrace.tracer assert len(warns) == 1