Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: avoids using deprecated modules in tests and log injection [3.0 prep] #11835

Merged
merged 16 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ddtrace/_trace/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,11 +1168,11 @@ def _on_global_config_update(self, cfg: Config, items: List[str]) -> None:

if "_logs_injection" in items:
if config._logs_injection:
from ddtrace.contrib.logging import patch
from ddtrace.contrib.internal.logging.patch import patch

patch()
else:
from ddtrace.contrib.logging import unpatch
from ddtrace.contrib.internal.logging.patch import unpatch

unpatch()

Expand Down
16 changes: 8 additions & 8 deletions tests/appsec/iast/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from ddtrace.appsec._iast.taint_sinks.weak_cipher import unpatch_iast as weak_cipher_unpatch
from ddtrace.appsec._iast.taint_sinks.weak_hash import patch as weak_hash_patch
from ddtrace.appsec._iast.taint_sinks.weak_hash import unpatch_iast as weak_hash_unpatch
from ddtrace.contrib.sqlite3.patch import patch as sqli_sqlite_patch
from ddtrace.contrib.sqlite3.patch import unpatch as sqli_sqlite_unpatch
from ddtrace.contrib.internal.sqlite3.patch import patch as sqli_sqlite_patch
from ddtrace.contrib.internal.sqlite3.patch import unpatch as sqli_sqlite_unpatch
from tests.utils import override_env
from tests.utils import override_global_config

Expand Down Expand Up @@ -60,20 +60,20 @@ def _end_iast_context_and_oce(span=None):

def iast_context(env, request_sampling=100.0, deduplication=False, asm_enabled=False):
try:
from ddtrace.contrib.langchain.patch import patch as langchain_patch
from ddtrace.contrib.langchain.patch import unpatch as langchain_unpatch
from ddtrace.contrib.internal.langchain.patch import patch as langchain_patch
from ddtrace.contrib.internal.langchain.patch import unpatch as langchain_unpatch
except Exception:
langchain_patch = lambda: True # noqa: E731
langchain_unpatch = lambda: True # noqa: E731
try:
from ddtrace.contrib.sqlalchemy.patch import patch as sqlalchemy_patch
from ddtrace.contrib.sqlalchemy.patch import unpatch as sqlalchemy_unpatch
from ddtrace.contrib.internal.sqlalchemy.patch import patch as sqlalchemy_patch
from ddtrace.contrib.internal.sqlalchemy.patch import unpatch as sqlalchemy_unpatch
except Exception:
sqlalchemy_patch = lambda: True # noqa: E731
sqlalchemy_unpatch = lambda: True # noqa: E731
try:
from ddtrace.contrib.psycopg.patch import patch as psycopg_patch
from ddtrace.contrib.psycopg.patch import unpatch as psycopg_unpatch
from ddtrace.contrib.internal.psycopg.patch import patch as psycopg_patch
from ddtrace.contrib.internal.psycopg.patch import unpatch as psycopg_unpatch
except Exception:
psycopg_patch = lambda: True # noqa: E731
psycopg_unpatch = lambda: True # noqa: E731
Expand Down
20 changes: 10 additions & 10 deletions tests/appsec/iast/taint_sinks/test_ssrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
from ddtrace.appsec._iast._taint_tracking._taint_objects import taint_pyobject
from ddtrace.appsec._iast._taint_tracking.aspects import add_aspect
from ddtrace.appsec._iast.constants import VULN_SSRF
from ddtrace.contrib.httplib.patch import patch as httplib_patch
from ddtrace.contrib.httplib.patch import unpatch as httplib_unpatch
from ddtrace.contrib.requests.patch import patch as requests_patch
from ddtrace.contrib.requests.patch import unpatch as requests_unpatch
from ddtrace.contrib.urllib.patch import patch as urllib_patch
from ddtrace.contrib.urllib.patch import unpatch as urllib_unpatch
from ddtrace.contrib.urllib3.patch import patch as urllib3_patch
from ddtrace.contrib.urllib3.patch import unpatch as urllib3_unpatch
from ddtrace.contrib.webbrowser.patch import patch as webbrowser_patch
from ddtrace.contrib.webbrowser.patch import unpatch as webbrowser_unpatch
from ddtrace.contrib.internal.httplib.patch import patch as httplib_patch
from ddtrace.contrib.internal.httplib.patch import unpatch as httplib_unpatch
from ddtrace.contrib.internal.requests.patch import patch as requests_patch
from ddtrace.contrib.internal.requests.patch import unpatch as requests_unpatch
from ddtrace.contrib.internal.urllib.patch import patch as urllib_patch
from ddtrace.contrib.internal.urllib.patch import unpatch as urllib_unpatch
from ddtrace.contrib.internal.urllib3.patch import patch as urllib3_patch
from ddtrace.contrib.internal.urllib3.patch import unpatch as urllib3_unpatch
from ddtrace.contrib.internal.webbrowser.patch import patch as webbrowser_patch
from ddtrace.contrib.internal.webbrowser.patch import unpatch as webbrowser_unpatch
from tests.appsec.iast.conftest import _end_iast_context_and_oce
from tests.appsec.iast.conftest import _start_iast_context_and_oce
from tests.appsec.iast.iast_utils import get_line_and_hash
Expand Down
4 changes: 2 additions & 2 deletions tests/appsec/iast/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from ddtrace.appsec._iast.taint_sinks.command_injection import patch as cmdi_patch
from ddtrace.appsec._iast.taint_sinks.header_injection import patch as header_injection_patch
from ddtrace.appsec._iast.taint_sinks.header_injection import unpatch as header_injection_unpatch
from ddtrace.contrib.sqlalchemy import patch as sqli_sqlalchemy_patch
from ddtrace.contrib.sqlite3 import patch as sqli_sqlite3_patch
from ddtrace.contrib.internal.sqlalchemy.patch import patch as sqli_sqlalchemy_patch
from ddtrace.contrib.internal.sqlite3.patch import patch as sqli_sqlite3_patch
from ddtrace.ext import SpanTypes
from ddtrace.internal.telemetry.constants import TELEMETRY_NAMESPACE_TAG_IAST
from ddtrace.internal.telemetry.constants import TELEMETRY_TYPE_GENERATE_METRICS
Expand Down
8 changes: 4 additions & 4 deletions tests/contrib/aiobotocore/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import pytest

from ddtrace.constants import ERROR_MSG
from ddtrace.contrib.aiobotocore.patch import patch
from ddtrace.contrib.aiobotocore.patch import unpatch
from ddtrace.contrib.internal.aiobotocore.patch import patch
from ddtrace.contrib.internal.aiobotocore.patch import unpatch
from tests.conftest import DEFAULT_DDTRACE_SUBPROCESS_TEST_SERVICE_NAME
from tests.utils import assert_is_measured
from tests.utils import assert_span_http_status_code
Expand Down Expand Up @@ -419,8 +419,8 @@ def test_schematized_env_specified_service(ddtrace_run_python_code_in_subprocess
service_name, schema_version, expected_service_name, expected_operation_name = schema_params
code = """
import asyncio
from ddtrace.contrib.aiobotocore.patch import patch
from ddtrace.contrib.aiobotocore.patch import unpatch
from ddtrace.contrib.internal.aiobotocore.patch import patch
from ddtrace.contrib.internal.aiobotocore.patch import unpatch
from tests.contrib.aiobotocore.utils import *
from tests.conftest import *

Expand Down
6 changes: 3 additions & 3 deletions tests/contrib/aiobotocore/test_aiobotocore_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# removed the ``_generated`` suffix from the file name, to prevent the content
# from being overwritten by future re-generations.

from ddtrace.contrib.aiobotocore import get_version
from ddtrace.contrib.aiobotocore.patch import patch
from ddtrace.contrib.internal.aiobotocore.patch import get_version
from ddtrace.contrib.internal.aiobotocore.patch import patch


try:
from ddtrace.contrib.aiobotocore.patch import unpatch
from ddtrace.contrib.internal.aiobotocore.patch import unpatch
except ImportError:
unpatch = None
from tests.contrib.patch import PatchTestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/contrib/aiohttp/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest

from ddtrace.contrib.aiohttp.middlewares import trace_app
from ddtrace.contrib.aiohttp.patch import unpatch
from ddtrace.contrib.internal.aiohttp.patch import unpatch
from ddtrace.internal.utils import version # noqa:F401

from .app.web import setup_app
Expand Down
6 changes: 3 additions & 3 deletions tests/contrib/aiohttp/test_aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import pytest

from ddtrace import Pin
from ddtrace.contrib.aiohttp import patch
from ddtrace.contrib.aiohttp import unpatch
from ddtrace.contrib.aiohttp.patch import extract_netloc_and_query_info_from_url
from ddtrace.contrib.internal.aiohttp.patch import extract_netloc_and_query_info_from_url
from ddtrace.contrib.internal.aiohttp.patch import patch
from ddtrace.contrib.internal.aiohttp.patch import unpatch
from tests.utils import override_config
from tests.utils import override_http_config

Expand Down
6 changes: 3 additions & 3 deletions tests/contrib/aiohttp/test_aiohttp_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# removed the ``_generated`` suffix from the file name, to prevent the content
# from being overwritten by future re-generations.

from ddtrace.contrib.aiohttp import get_version
from ddtrace.contrib.aiohttp.patch import patch
from ddtrace.contrib.internal.aiohttp.patch import get_version
from ddtrace.contrib.internal.aiohttp.patch import patch


try:
from ddtrace.contrib.aiohttp.patch import unpatch
from ddtrace.contrib.internal.aiohttp.patch import unpatch
except ImportError:
unpatch = None
from tests.contrib.patch import PatchTestCase
Expand Down
4 changes: 2 additions & 2 deletions tests/contrib/aiohttp_jinja2/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import aiohttp_jinja2
import pytest

from ddtrace.contrib.aiohttp_jinja2 import patch
from ddtrace.contrib.aiohttp_jinja2 import unpatch
from ddtrace.contrib.internal.aiohttp_jinja2.patch import patch
from ddtrace.contrib.internal.aiohttp_jinja2.patch import unpatch
from ddtrace.pin import Pin
from tests.contrib.aiohttp.conftest import app_tracer # noqa:F401
from tests.contrib.aiohttp.conftest import patched_app_tracer # noqa:F401
Expand Down
6 changes: 3 additions & 3 deletions tests/contrib/aiohttp_jinja2/test_aiohttp_jinja2_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# removed the ``_generated`` suffix from the file name, to prevent the content
# from being overwritten by future re-generations.

from ddtrace.contrib.aiohttp_jinja2 import get_version
from ddtrace.contrib.aiohttp_jinja2.patch import patch
from ddtrace.contrib.internal.aiohttp_jinja2.patch import get_version
from ddtrace.contrib.internal.aiohttp_jinja2.patch import patch


try:
from ddtrace.contrib.aiohttp_jinja2.patch import unpatch
from ddtrace.contrib.internal.aiohttp_jinja2.patch import unpatch
except ImportError:
unpatch = None
from tests.contrib.patch import PatchTestCase
Expand Down
4 changes: 2 additions & 2 deletions tests/contrib/aiomysql/test_aiomysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from ddtrace import Pin
from ddtrace import Tracer
from ddtrace.contrib.aiomysql import patch
from ddtrace.contrib.aiomysql import unpatch
from ddtrace.contrib.internal.aiomysql.patch import patch
from ddtrace.contrib.internal.aiomysql.patch import unpatch
from ddtrace.internal.schema import DEFAULT_SPAN_SERVICE_NAME
from tests.contrib import shared_tests_async as shared_tests
from tests.contrib.asyncio.utils import AsyncioTestCase
Expand Down
6 changes: 3 additions & 3 deletions tests/contrib/aiomysql/test_aiomysql_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# removed the ``_generated`` suffix from the file name, to prevent the content
# from being overwritten by future re-generations.

from ddtrace.contrib.aiomysql import get_version
from ddtrace.contrib.aiomysql.patch import patch
from ddtrace.contrib.internal.aiomysql.patch import get_version
from ddtrace.contrib.internal.aiomysql.patch import patch


try:
from ddtrace.contrib.aiomysql.patch import unpatch
from ddtrace.contrib.internal.aiomysql.patch import unpatch
except ImportError:
unpatch = None
from tests.contrib.patch import PatchTestCase
Expand Down
4 changes: 2 additions & 2 deletions tests/contrib/aiopg/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

# project
from ddtrace import Pin
from ddtrace.contrib.aiopg.patch import patch
from ddtrace.contrib.aiopg.patch import unpatch
from ddtrace.contrib.internal.aiopg.patch import patch
from ddtrace.contrib.internal.aiopg.patch import unpatch
from ddtrace.internal.schema import DEFAULT_SPAN_SERVICE_NAME
from tests.contrib.asyncio.utils import AsyncioTestCase
from tests.contrib.config import POSTGRES_CONFIG
Expand Down
6 changes: 3 additions & 3 deletions tests/contrib/aiopg/test_aiopg_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# removed the ``_generated`` suffix from the file name, to prevent the content
# from being overwritten by future re-generations.

from ddtrace.contrib.aiopg import get_version
from ddtrace.contrib.aiopg.patch import patch
from ddtrace.contrib.internal.aiopg.patch import get_version
from ddtrace.contrib.internal.aiopg.patch import patch


try:
from ddtrace.contrib.aiopg.patch import unpatch
from ddtrace.contrib.internal.aiopg.patch import unpatch
except ImportError:
unpatch = None
from tests.contrib.patch import PatchTestCase
Expand Down
6 changes: 3 additions & 3 deletions tests/contrib/algoliasearch/test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from ddtrace import config
from ddtrace import patch_all
from ddtrace.contrib.algoliasearch.patch import algoliasearch_version
from ddtrace.contrib.algoliasearch.patch import patch
from ddtrace.contrib.algoliasearch.patch import unpatch
from ddtrace.contrib.internal.algoliasearch.patch import algoliasearch_version
from ddtrace.contrib.internal.algoliasearch.patch import patch
from ddtrace.contrib.internal.algoliasearch.patch import unpatch
from ddtrace.pin import Pin
from ddtrace.vendor.packaging.version import parse as parse_version
from tests.utils import TracerTestCase
Expand Down
6 changes: 3 additions & 3 deletions tests/contrib/algoliasearch/test_algoliasearch_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# removed the ``_generated`` suffix from the file name, to prevent the content
# from being overwritten by future re-generations.

from ddtrace.contrib.algoliasearch import get_version
from ddtrace.contrib.algoliasearch.patch import patch
from ddtrace.contrib.internal.algoliasearch.patch import get_version
from ddtrace.contrib.internal.algoliasearch.patch import patch


try:
from ddtrace.contrib.algoliasearch.patch import unpatch
from ddtrace.contrib.internal.algoliasearch.patch import unpatch
except ImportError:
unpatch = None
from tests.contrib.patch import PatchTestCase
Expand Down
4 changes: 2 additions & 2 deletions tests/contrib/anthropic/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import pytest

from ddtrace import Pin
from ddtrace.contrib.anthropic.patch import patch
from ddtrace.contrib.anthropic.patch import unpatch
from ddtrace.contrib.internal.anthropic.patch import patch
from ddtrace.contrib.internal.anthropic.patch import unpatch
from ddtrace.llmobs import LLMObs
from tests.contrib.anthropic.utils import get_request_vcr
from tests.utils import DummyTracer
Expand Down
6 changes: 3 additions & 3 deletions tests/contrib/anthropic/test_anthropic_patch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ddtrace.contrib.anthropic import get_version
from ddtrace.contrib.anthropic import patch
from ddtrace.contrib.anthropic import unpatch
from ddtrace.contrib.internal.anthropic.patch import get_version
from ddtrace.contrib.internal.anthropic.patch import patch
from ddtrace.contrib.internal.anthropic.patch import unpatch
from tests.contrib.patch import PatchTestCase


Expand Down
4 changes: 2 additions & 2 deletions tests/contrib/aredis/test_aredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from wrapt import ObjectProxy

from ddtrace import Pin
from ddtrace.contrib.aredis.patch import patch
from ddtrace.contrib.aredis.patch import unpatch
from ddtrace.contrib.internal.aredis.patch import patch
from ddtrace.contrib.internal.aredis.patch import unpatch
from tests.conftest import DEFAULT_DDTRACE_SUBPROCESS_TEST_SERVICE_NAME
from tests.opentracer.utils import init_tracer
from tests.utils import override_config
Expand Down
6 changes: 3 additions & 3 deletions tests/contrib/aredis/test_aredis_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# removed the ``_generated`` suffix from the file name, to prevent the content
# from being overwritten by future re-generations.

from ddtrace.contrib.aredis import get_version
from ddtrace.contrib.aredis.patch import patch
from ddtrace.contrib.internal.aredis.patch import get_version
from ddtrace.contrib.internal.aredis.patch import patch


try:
from ddtrace.contrib.aredis.patch import unpatch
from ddtrace.contrib.internal.aredis.patch import unpatch
except ImportError:
unpatch = None
from tests.contrib.patch import PatchTestCase
Expand Down
12 changes: 6 additions & 6 deletions tests/contrib/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import pytest

from ddtrace.constants import ERROR_MSG
from ddtrace.contrib.asgi import TraceMiddleware
from ddtrace.contrib.asgi import span_from_scope
from ddtrace.contrib.internal.asgi.middleware import TraceMiddleware
from ddtrace.contrib.internal.asgi.middleware import _parse_response_cookies
from ddtrace.contrib.internal.asgi.middleware import span_from_scope
from ddtrace.propagation import http as http_propagation
from tests.conftest import DEFAULT_DDTRACE_SUBPROCESS_TEST_SERVICE_NAME
from tests.utils import DummyTracer
Expand Down Expand Up @@ -195,8 +195,8 @@ def test_span_attribute_schema_operation_name(ddtrace_run_python_code_in_subproc
from tests.contrib.asgi.test_asgi import scope
from tests.contrib.asgi.test_asgi import tracer
from asgiref.testing import ApplicationCommunicator
from ddtrace.contrib.asgi import TraceMiddleware
from ddtrace.contrib.asgi import span_from_scope
from ddtrace.contrib.internal.asgi.middleware import TraceMiddleware
from ddtrace.contrib.internal.asgi.middleware import span_from_scope


@pytest.mark.asyncio
Expand Down Expand Up @@ -254,8 +254,8 @@ def test_span_attribute_schema_service_name(ddtrace_run_python_code_in_subproces
from tests.contrib.asgi.test_asgi import scope
from tests.contrib.asgi.test_asgi import tracer
from asgiref.testing import ApplicationCommunicator
from ddtrace.contrib.asgi import TraceMiddleware
from ddtrace.contrib.asgi import span_from_scope
from ddtrace.contrib.internal.asgi.middleware import TraceMiddleware
from ddtrace.contrib.internal.asgi.middleware import span_from_scope

@pytest.mark.asyncio
async def test(scope, tracer, test_spans):
Expand Down
4 changes: 2 additions & 2 deletions tests/contrib/asyncio/test_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from ddtrace._trace.context import Context
from ddtrace._trace.provider import DefaultContextProvider
from ddtrace.contrib.asyncio.patch import patch
from ddtrace.contrib.asyncio.patch import unpatch
from ddtrace.contrib.internal.asyncio.patch import patch
from ddtrace.contrib.internal.asyncio.patch import unpatch
from tests.opentracer.utils import init_tracer


Expand Down
4 changes: 2 additions & 2 deletions tests/contrib/asyncio/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import pytest

from ddtrace.constants import ERROR_MSG
from ddtrace.contrib.asyncio import patch
from ddtrace.contrib.asyncio import unpatch
from ddtrace.contrib.asyncio.compat import asyncio_current_task
from ddtrace.contrib.internal.asyncio.patch import patch
from ddtrace.contrib.internal.asyncio.patch import unpatch


@pytest.fixture(autouse=True)
Expand Down
4 changes: 2 additions & 2 deletions tests/contrib/asyncpg/test_asyncpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from ddtrace import Pin
from ddtrace import tracer
from ddtrace.contrib.asyncpg import patch
from ddtrace.contrib.asyncpg import unpatch
from ddtrace.contrib.internal.asyncpg.patch import patch
from ddtrace.contrib.internal.asyncpg.patch import unpatch
from ddtrace.contrib.trace_utils import iswrapped
from tests.contrib.asyncio.utils import AsyncioTestCase
from tests.contrib.asyncio.utils import mark_asyncio
Expand Down
Loading
Loading