diff --git a/ddtrace/_trace/pin.py b/ddtrace/_trace/pin.py index d12303a57ea..7dd83474749 100644 --- a/ddtrace/_trace/pin.py +++ b/ddtrace/_trace/pin.py @@ -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: diff --git a/ddtrace/contrib/grpc/__init__.py b/ddtrace/contrib/grpc/__init__.py index c95633b4024..8ad2a705233 100644 --- a/ddtrace/contrib/grpc/__init__.py +++ b/ddtrace/contrib/grpc/__init__.py @@ -48,6 +48,7 @@ from ddtrace import patch from ddtrace.trace import Pin + patch(grpc=True) # override the pin on the client @@ -62,7 +63,7 @@ from grpc.framework.foundation import logging_pool from ddtrace import patch - from ddtrace.trace import Pin, Tracer + from ddtrace.trace import Pin patch(grpc=True) diff --git a/ddtrace/contrib/internal/django/patch.py b/ddtrace/contrib/internal/django/patch.py index 98a6163a6e5..8bc523dd1c1 100644 --- a/ddtrace/contrib/internal/django/patch.py +++ b/ddtrace/contrib/internal/django/patch.py @@ -17,6 +17,7 @@ import wrapt from wrapt.importer import when_imported +import ddtrace from ddtrace import config from ddtrace.appsec._utils import _UserInfoRetriever from ddtrace.constants import SPAN_KIND @@ -147,7 +148,12 @@ def cursor(django, pin, func, instance, args, kwargs): tags = {"django.db.vendor": vendor, "django.db.alias": alias} tags.update(getattr(conn, "_datadog_tags", {})) - pin = Pin(service, tags=tags, tracer=pin.tracer) + # Calling ddtrace.pin.Pin(...) with the `tracer` argument generates a deprecation warning. + # Remove this if statement when the `tracer` argument is removed + if pin.tracer is ddtrace.tracer: + pin = Pin(service, tags=tags) + else: + pin = Pin(service, tags=tags, tracer=pin.tracer) cursor = func(*args, **kwargs) diff --git a/ddtrace/contrib/internal/mongoengine/trace.py b/ddtrace/contrib/internal/mongoengine/trace.py index b13ef567037..93868e096ce 100644 --- a/ddtrace/contrib/internal/mongoengine/trace.py +++ b/ddtrace/contrib/internal/mongoengine/trace.py @@ -23,12 +23,17 @@ class WrappedConnect(wrapt.ObjectProxy): def __init__(self, connect): super(WrappedConnect, self).__init__(connect) - ddtrace.trace.Pin(_SERVICE, tracer=ddtrace.tracer).onto(self) + ddtrace.trace.Pin(_SERVICE).onto(self) def __call__(self, *args, **kwargs): client = self.__wrapped__(*args, **kwargs) pin = ddtrace.trace.Pin.get_from(self) if pin: - ddtrace.trace.Pin(service=pin.service, tracer=pin.tracer).onto(client) + # Calling ddtrace.pin.Pin(...) with the `tracer` argument generates a deprecation warning. + # Remove this if statement when the `tracer` argument is removed + if pin.tracer is ddtrace.tracer: + ddtrace.trace.Pin(service=pin.service).onto(client) + else: + ddtrace.trace.Pin(service=pin.service, tracer=pin.tracer).onto(client) return client diff --git a/ddtrace/contrib/internal/pylibmc/client.py b/ddtrace/contrib/internal/pylibmc/client.py index af15925f327..3ea6f09c62c 100644 --- a/ddtrace/contrib/internal/pylibmc/client.py +++ b/ddtrace/contrib/internal/pylibmc/client.py @@ -51,7 +51,12 @@ def __init__(self, client=None, service=memcached.SERVICE, tracer=None, *args, * super(TracedClient, self).__init__(client) schematized_service = schematize_service_name(service) - pin = ddtrace.trace.Pin(service=schematized_service, tracer=tracer) + # Calling ddtrace.pin.Pin(...) with the `tracer` argument generates a deprecation warning. + # Remove this if statement when the `tracer` argument is removed + if tracer is ddtrace.tracer: + pin = ddtrace.trace.Pin(service=schematized_service) + else: + pin = ddtrace.trace.Pin(service=schematized_service, tracer=tracer) pin.onto(self) # attempt to collect the pool of urls this client talks to diff --git a/ddtrace/contrib/internal/sqlalchemy/engine.py b/ddtrace/contrib/internal/sqlalchemy/engine.py index 57b6db4e9fc..3b5f96be9e7 100644 --- a/ddtrace/contrib/internal/sqlalchemy/engine.py +++ b/ddtrace/contrib/internal/sqlalchemy/engine.py @@ -67,7 +67,12 @@ def __init__(self, tracer, service, engine): self.name = schematize_database_operation("%s.query" % self.vendor, database_provider=self.vendor) # attach the PIN - Pin(tracer=tracer, service=self.service).onto(engine) + # Calling ddtrace.pin.Pin(...) with the `tracer` argument generates a deprecation warning. + # Remove this if statement when the `tracer` argument is removed + if self.tracer is ddtrace.tracer: + Pin(service=self.service).onto(engine) + else: + Pin(tracer=tracer, service=self.service).onto(engine) listen(engine, "before_cursor_execute", self._before_cur_exec) listen(engine, "after_cursor_execute", self._after_cur_exec) diff --git a/ddtrace/contrib/internal/tornado/application.py b/ddtrace/contrib/internal/tornado/application.py index 227c74f3359..86794689835 100644 --- a/ddtrace/contrib/internal/tornado/application.py +++ b/ddtrace/contrib/internal/tornado/application.py @@ -55,4 +55,9 @@ def tracer_config(__init__, app, args, kwargs): tracer.set_tags(tags) # configure the PIN object for template rendering - ddtrace.trace.Pin(service=service, tracer=tracer).onto(template) + # Required for backwards compatibility. Remove the else clause when + # the `ddtrace.Pin` object no longer accepts the Pin argument. + if tracer is ddtrace.tracer: + ddtrace.trace.Pin(service=service).onto(template) + else: + ddtrace.trace.Pin(service=service, tracer=tracer).onto(template) diff --git a/ddtrace/contrib/vertica/__init__.py b/ddtrace/contrib/vertica/__init__.py index 4da8a844e83..7271c1c92ad 100644 --- a/ddtrace/contrib/vertica/__init__.py +++ b/ddtrace/contrib/vertica/__init__.py @@ -28,14 +28,14 @@ ``Pin`` API:: from ddtrace import patch - from ddtrace.trace import Pin, Tracer + from ddtrace.trace import Pin patch(vertica=True) import vertica_python conn = vertica_python.connect(**YOUR_VERTICA_CONFIG) - # override the service and tracer to be used + # override the service Pin.override(conn, service='myverticaservice') """ diff --git a/releasenotes/notes/remove-multi-tracer-support-from-pin-f2f20ca3fa731929.yaml b/releasenotes/notes/remove-multi-tracer-support-from-pin-f2f20ca3fa731929.yaml new file mode 100644 index 00000000000..18c70a15b04 --- /dev/null +++ b/releasenotes/notes/remove-multi-tracer-support-from-pin-f2f20ca3fa731929.yaml @@ -0,0 +1,4 @@ +--- +deprecations: + - | + tracer: Deprecates the ability to use multiple tracer instances with ddtrace.Pin. In v3.0.0 pin objects will only use the global tracer.