Skip to content

Commit

Permalink
fix failing tracer, profiling, stats, and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Dec 24, 2024
1 parent 2325f7a commit fefa362
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
5 changes: 3 additions & 2 deletions tests/integration/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions tests/integration/test_trace_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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"})
Expand Down
38 changes: 31 additions & 7 deletions tests/profiling/test_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"))

Expand Down
5 changes: 4 additions & 1 deletion tests/tracer/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fefa362

Please sign in to comment.