Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into evan.li/test-multiple
Browse files Browse the repository at this point in the history
lievan authored Jan 17, 2025
2 parents 4ba46a0 + f67a358 commit cad52ed
Showing 39 changed files with 1,011 additions and 549 deletions.
2 changes: 0 additions & 2 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -119,8 +119,6 @@ tests/appsec/ @DataDog/asm-python
tests/contrib/dbapi/test_dbapi_appsec.py @DataDog/asm-python
tests/contrib/subprocess @DataDog/asm-python
tests/contrib/flask/test_flask_appsec.py @DataDog/asm-python
tests/contrib/django/django_app/appsec_urls.py @DataDog/asm-python
tests/contrib/django/test_django_appsec.py @DataDog/asm-python
tests/snapshots/tests*appsec*.json @DataDog/asm-python
tests/contrib/*/test*appsec*.py @DataDog/asm-python
scripts/iast/* @DataDog/asm-python
9 changes: 5 additions & 4 deletions ddtrace/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import os
import warnings


@@ -42,22 +43,22 @@
# initialization, which added this module to sys.modules. We catch deprecation
# warnings as this is only to retain a side effect of the package
# initialization.
# TODO: Remove this in v3.0 when the ddtrace/tracer.py module is removed
with warnings.catch_warnings():
warnings.simplefilter("ignore")
from .tracer import Tracer as _


__version__ = get_version()

# a global tracer instance with integration settings
tracer = Tracer()
# TODO: Deprecate accessing tracer from ddtrace.__init__ module in v4.0
if os.environ.get("_DD_GLOBAL_TRACER_INIT", "true").lower() in ("1", "true"):
from ddtrace.trace import tracer # noqa: F401

__all__ = [
"patch",
"patch_all",
"Pin",
"Span",
"tracer",
"Tracer",
"config",
"DDTraceDeprecationWarning",
34 changes: 27 additions & 7 deletions ddtrace/_trace/pin.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import wrapt

import ddtrace
from ddtrace.vendor.debtcollector import deprecate

from ..internal.logger import get_logger

@@ -41,6 +42,12 @@ def __init__(
_config=None, # type: Optional[Dict[str, Any]]
):
# type: (...) -> None
if tracer is not None and tracer is not ddtrace.tracer:
deprecate(
"Initializing ddtrace.Pin with `tracer` argument is deprecated",
message="All Pin instances should use the global tracer instance",
removal_version="3.0.0",
)
tracer = tracer or ddtrace.tracer
self.tags = tags
self.tracer = tracer
@@ -72,15 +79,15 @@ def __repr__(self):
def _find(*objs):
# type: (Any) -> Optional[Pin]
"""
Return the first :class:`ddtrace.trace.Pin` found on any of the provided objects or `None` if none were found
Return the first :class:`ddtrace.pin.Pin` found on any of the provided objects or `None` if none were found
>>> pin = Pin._find(wrapper, instance, conn)
:param objs: The objects to search for a :class:`ddtrace.trace.Pin` on
:param objs: The objects to search for a :class:`ddtrace.pin.Pin` on
:type objs: List of objects
:rtype: :class:`ddtrace.trace.Pin`, None
:returns: The first found :class:`ddtrace.trace.Pin` or `None` is none was found
:rtype: :class:`ddtrace.pin.Pin`, None
:returns: The first found :class:`ddtrace.pin.Pin` or `None` is none was found
"""
for obj in objs:
pin = Pin.get_from(obj)
@@ -98,10 +105,10 @@ def get_from(obj):
>>> pin = Pin.get_from(conn)
:param obj: The object to look for a :class:`ddtrace.trace.Pin` on
:param obj: The object to look for a :class:`ddtrace.pin.Pin` on
:type obj: object
:rtype: :class:`ddtrace.trace.Pin`, None
:returns: :class:`ddtrace.trace.Pin` associated with the object or None
:rtype: :class:`ddtrace.pin.Pin`, None
:returns: :class:`ddtrace.pin.Pin` associated with the object, or None if none was found
"""
if hasattr(obj, "__getddpin__"):
return obj.__getddpin__()
@@ -132,6 +139,12 @@ def override(
>>> # Override a pin for a specific connection
>>> Pin.override(conn, service='user-db')
"""
if tracer is not None:
deprecate(
"Calling ddtrace.Pin.override(...) with the `tracer` argument is deprecated",
message="All Pin instances should use the global tracer instance",
removal_version="3.0.0",
)
if not obj:
return

@@ -193,6 +206,13 @@ def clone(
if not tags and self.tags:
tags = self.tags.copy()

if tracer is not None:
deprecate(
"Initializing ddtrace.Pin with `tracer` argument is deprecated",
message="All Pin instances should use the global tracer instance",
removal_version="3.0.0",
)

# we use a copy instead of a deepcopy because we expect configurations
# to have only a root level dictionary without nested objects. Using
# deepcopy introduces a big overhead:
2 changes: 1 addition & 1 deletion ddtrace/_trace/tracer.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
from ddtrace import _hooks
from ddtrace import config
from ddtrace._trace.context import Context
from ddtrace._trace.filters import TraceFilter
from ddtrace._trace.processor import SpanAggregator
from ddtrace._trace.processor import SpanProcessor
from ddtrace._trace.processor import TopLevelSpanProcessor
@@ -68,7 +69,6 @@
from ddtrace.settings import Config
from ddtrace.settings.asm import config as asm_config
from ddtrace.settings.peer_service import _ps_config
from ddtrace.trace import TraceFilter
from ddtrace.vendor.debtcollector import deprecate


Loading

0 comments on commit cad52ed

Please sign in to comment.