Skip to content

Commit

Permalink
Merge branch 'munir/remove-patch-unpatch-get-version-from-public-api'…
Browse files Browse the repository at this point in the history
… into munir/refactor-trace-utils
  • Loading branch information
mabdinur authored Jan 20, 2025
2 parents faa0d5f + c170b14 commit 5929451
Show file tree
Hide file tree
Showing 86 changed files with 1,192 additions and 418 deletions.
11 changes: 8 additions & 3 deletions ddtrace/_monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,13 @@ def _on_import_factory(module, prefix="ddtrace.contrib", raise_errors=True, patc

def on_import(hook):
# Import and patch module
path = "%s.%s" % (prefix, module)
try:
imported_module = importlib.import_module(path)
try:
imported_module = importlib.import_module("%s.internal.%s.patch" % (prefix, module))
except ImportError:
# Some integrations do not have an internal patch module, so we use the public one
# FIXME: This is a temporary solution until we refactor the patching logic.
imported_module = importlib.import_module("%s.%s" % (prefix, module))
imported_module.patch()
if hasattr(imported_module, "patch_submodules"):
imported_module.patch_submodules(patch_indicator)
Expand All @@ -204,7 +208,8 @@ def on_import(hook):
telemetry.telemetry_writer.add_integration(
name, True, PATCH_MODULES.get(module) is True, "", version=v
)
else:
elif hasattr(imported_module, "get_version"):
# TODO: Ensure every integration defines either get_version or get_versions in their patch.py module
version = imported_module.get_version()
telemetry.telemetry_writer.add_integration(
module, True, PATCH_MODULES.get(module) is True, "", version=version
Expand Down
17 changes: 13 additions & 4 deletions ddtrace/contrib/aiobotocore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@
_w.simplefilter("ignore", DeprecationWarning)
from . import patch as _ # noqa: F401, I001

# Expose public methods
from ddtrace.contrib.internal.aiobotocore.patch import get_version
from ddtrace.contrib.internal.aiobotocore.patch import patch

from ddtrace.contrib.internal.aiobotocore.patch import get_version # noqa: F401
from ddtrace.contrib.internal.aiobotocore.patch import patch # noqa: F401
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate

__all__ = ["patch", "get_version"]

deprecate(
("%s is deprecated" % (__name__)),
message="Avoid using this package directly. "
"Set DD_TRACE_AIOBOTOCORE_ENABLED=true and use ``import ddtrace.auto`` or the "
"``ddtrace-run`` command to enable and configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)
24 changes: 19 additions & 5 deletions ddtrace/contrib/aiohttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,25 @@ async def home_handler(request):
_w.simplefilter("ignore", DeprecationWarning)
from . import patch as _ # noqa: F401, I001
from ddtrace.contrib.internal.aiohttp.middlewares import trace_app
from ddtrace.contrib.internal.aiohttp.patch import get_version
from ddtrace.contrib.internal.aiohttp.patch import get_version # noqa: F401
from ddtrace.contrib.internal.aiohttp.patch import patch # noqa: F401
from ddtrace.contrib.internal.aiohttp.patch import unpatch # noqa: F401
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate

# Expose public methods
from ddtrace.contrib.internal.aiohttp.patch import patch
from ddtrace.contrib.internal.aiohttp.patch import unpatch

def __getattr__(name):
if name in ("patch", "get_version", "unpatch"):
deprecate(
("%s.%s is deprecated" % (__name__, name)),
message="Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)

__all__ = ["patch", "unpatch", "trace_app", "get_version"]
if name in globals():
return globals()[name]
raise AttributeError("%s has no attribute %s", __name__, name)


__all__ = ["trace_app"]
20 changes: 14 additions & 6 deletions ddtrace/contrib/aiohttp_jinja2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@
_w.simplefilter("ignore", DeprecationWarning)
from . import patch as _ # noqa: F401, I001

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


__all__ = ["patch", "unpatch", "get_version"]
from ddtrace.contrib.internal.aiohttp_jinja2.patch import get_version # noqa: F401
from ddtrace.contrib.internal.aiohttp_jinja2.patch import patch # noqa: F401
from ddtrace.contrib.internal.aiohttp_jinja2.patch import unpatch # noqa: F401
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate


deprecate(
("%s is deprecated" % (__name__)),
message="Avoid using this package directly. "
"Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to enable and configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)
20 changes: 14 additions & 6 deletions ddtrace/contrib/aiomysql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@
_w.simplefilter("ignore", DeprecationWarning)
from . import patch as _ # noqa: F401, I001

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


__all__ = ["patch", "unpatch", "get_version"]
from ddtrace.contrib.internal.aiomysql.patch import get_version # noqa: F401
from ddtrace.contrib.internal.aiomysql.patch import patch # noqa: F401
from ddtrace.contrib.internal.aiomysql.patch import unpatch # noqa: F401
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate


deprecate(
("%s is deprecated" % (__name__)),
message="Avoid using this package directly. "
"Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to enable and configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)
18 changes: 13 additions & 5 deletions ddtrace/contrib/aiopg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@
_w.simplefilter("ignore", DeprecationWarning)
from . import patch as _ # noqa: F401, I001

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


__all__ = ["patch", "get_version"]
from ddtrace.contrib.internal.aiopg.patch import get_version # noqa: F401
from ddtrace.contrib.internal.aiopg.patch import patch # noqa: F401
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate


deprecate(
("%s is deprecated" % (__name__)),
message="Avoid using this package directly. "
"Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to enable and configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)
24 changes: 11 additions & 13 deletions ddtrace/contrib/aioredis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate


deprecate(
"The aioredis integration is deprecated.",
message="Please use the redis integration with redis>=4.2.0 instead.",
category=DDTraceDeprecationWarning,
)
"""
The aioredis integration instruments aioredis requests. Version 1.3 and above are fully
supported.
Expand Down Expand Up @@ -77,9 +68,16 @@
# Required to allow users to import from `ddtrace.contrib.aioredis.patch` directly
from . import patch as _ # noqa: F401, I001

from ddtrace.contrib.internal.aioredis.patch import get_version # noqa: E402
from ddtrace.contrib.internal.aioredis.patch import patch # noqa: E402
from ddtrace.contrib.internal.aioredis.patch import unpatch # noqa: E402
from ddtrace.contrib.internal.aioredis.patch import get_version # noqa: F401
from ddtrace.contrib.internal.aioredis.patch import patch # noqa: F401
from ddtrace.contrib.internal.aioredis.patch import unpatch # noqa: F401
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate


__all__ = ["patch", "unpatch", "get_version"]
deprecate(
"The aioredis integration is deprecated",
message="Please use the redis integration with redis>=4.2.0 instead.",
removal_version="3.0.0",
category=DDTraceDeprecationWarning,
)
20 changes: 14 additions & 6 deletions ddtrace/contrib/algoliasearch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@
_w.simplefilter("ignore", DeprecationWarning)
from . import patch as _ # noqa: F401, I001

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


__all__ = ["patch", "unpatch", "get_version"]
from ddtrace.contrib.internal.algoliasearch.patch import get_version # noqa: F401
from ddtrace.contrib.internal.algoliasearch.patch import patch # noqa: F401
from ddtrace.contrib.internal.algoliasearch.patch import unpatch # noqa: F401
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate


deprecate(
("%s is deprecated" % (__name__)),
message="Avoid using this package directly. "
"Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to enable and configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)
20 changes: 14 additions & 6 deletions ddtrace/contrib/anthropic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,17 @@
_w.simplefilter("ignore", DeprecationWarning)
from . import patch as _ # noqa: F401, I001

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


__all__ = ["patch", "unpatch", "get_version"]
from ddtrace.contrib.internal.anthropic.patch import get_version # noqa: F401
from ddtrace.contrib.internal.anthropic.patch import patch # noqa: F401
from ddtrace.contrib.internal.anthropic.patch import unpatch # noqa: F401
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate


deprecate(
("%s is deprecated" % (__name__)),
message="Avoid using this package directly. "
"Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to enable and configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)
18 changes: 13 additions & 5 deletions ddtrace/contrib/aredis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,16 @@ async def example():
_w.simplefilter("ignore", DeprecationWarning)
from . import patch as _ # noqa: F401, I001

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


__all__ = ["patch", "get_version"]
from ddtrace.contrib.internal.aredis.patch import get_version # noqa: F401
from ddtrace.contrib.internal.aredis.patch import patch # noqa: F401
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate


deprecate(
("%s is deprecated" % (__name__)),
message="Avoid using this package directly. "
"Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to enable and configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)
20 changes: 18 additions & 2 deletions ddtrace/contrib/asgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,24 @@ def handle_request(scope, send):


from ddtrace.contrib.internal.asgi.middleware import TraceMiddleware
from ddtrace.contrib.internal.asgi.middleware import get_version
from ddtrace.contrib.internal.asgi.middleware import get_version # noqa: F401
from ddtrace.contrib.internal.asgi.middleware import span_from_scope
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate


__all__ = ["TraceMiddleware", "span_from_scope", "get_version"]
def __getattr__(name):
if name in ("get_version",):
deprecate(
("%s.%s is deprecated" % (__name__, name)),
message="Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)

if name in globals():
return globals()[name]
raise AttributeError("%s has no attribute %s", __name__, name)


__all__ = ["TraceMiddleware", "span_from_scope"]
22 changes: 15 additions & 7 deletions ddtrace/contrib/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@
of concurrent execution of ``asyncio.Task``.
"""
# Required to allow users to import from `ddtrace.contrib.asyncio.patch` directly
# Expose public methods

import warnings as _w # noqa:E402


with _w.catch_warnings():
_w.simplefilter("ignore", DeprecationWarning)
from . import patch as _ # noqa: F401, I001
from ddtrace._trace.provider import DefaultContextProvider
from ddtrace.contrib.internal.asyncio.helpers import ensure_future
from ddtrace.contrib.internal.asyncio.helpers import run_in_executor
from ddtrace.contrib.internal.asyncio.helpers import set_call_context
from ddtrace.contrib.internal.asyncio.patch import get_version
from ddtrace.contrib.internal.asyncio.patch import patch
from ddtrace.contrib.internal.asyncio.helpers import ensure_future # noqa: F401
from ddtrace.contrib.internal.asyncio.helpers import run_in_executor # noqa: F401
from ddtrace.contrib.internal.asyncio.helpers import set_call_context # noqa: F401
from ddtrace.contrib.internal.asyncio.patch import get_version # noqa: F401
from ddtrace.contrib.internal.asyncio.patch import patch # noqa: F401
from ddtrace.contrib.internal.asyncio.patch import unpatch # noqa: F401
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate


context_provider = DefaultContextProvider()


__all__ = ["context_provider", "set_call_context", "ensure_future", "run_in_executor", "patch", "get_version"]
deprecate(
("%s is deprecated" % (__name__)),
message="Avoid using this package directly. "
"Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to enable and configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)
20 changes: 14 additions & 6 deletions ddtrace/contrib/asyncpg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,17 @@
_w.simplefilter("ignore", DeprecationWarning)
from . import patch as _ # noqa: F401, I001

from ddtrace.contrib.internal.asyncpg.patch import get_version
from ddtrace.contrib.internal.asyncpg.patch import patch
from ddtrace.contrib.internal.asyncpg.patch import unpatch


__all__ = ["patch", "unpatch", "get_version"]
from ddtrace.contrib.internal.asyncpg.patch import get_version # noqa: F401
from ddtrace.contrib.internal.asyncpg.patch import patch # noqa: F401
from ddtrace.contrib.internal.asyncpg.patch import unpatch # noqa: F401
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate


deprecate(
("%s is deprecated" % (__name__)),
message="Avoid using this package directly. "
"Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to enable and configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)
17 changes: 13 additions & 4 deletions ddtrace/contrib/avro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@
~~~~~~~~~~~~~
"""
# Expose public methods
from ..internal.avro.patch import get_version
from ..internal.avro.patch import patch

from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate

__all__ = ["patch", "get_version"]
from ..internal.avro.patch import get_version # noqa: F401
from ..internal.avro.patch import patch # noqa: F401


deprecate(
("%s is deprecated" % (__name__)),
message="Avoid using this package directly. "
"Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to enable and configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)
20 changes: 14 additions & 6 deletions ddtrace/contrib/aws_lambda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@
`Instrumenting Python Serverless Applications by Datadog <https://docs.datadoghq.com/serverless/installation/python>`_.
"""

from ddtrace.contrib.internal.aws_lambda.patch import get_version
from ddtrace.contrib.internal.aws_lambda.patch import patch
from ddtrace.contrib.internal.aws_lambda.patch import unpatch


__all__ = ["patch", "unpatch", "get_version"]
from ddtrace.contrib.internal.aws_lambda.patch import get_version # noqa: F401
from ddtrace.contrib.internal.aws_lambda.patch import patch # noqa: F401
from ddtrace.contrib.internal.aws_lambda.patch import unpatch # noqa: F401
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.vendor.debtcollector import deprecate


deprecate(
("%s is deprecated" % (__name__)),
message="Avoid using this package directly. "
"Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to enable and configure this integration.",
category=DDTraceDeprecationWarning,
removal_version="3.0.0",
)
Loading

0 comments on commit 5929451

Please sign in to comment.