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(pin): deprecate multi tracer support #11884

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
10 changes: 4 additions & 6 deletions ddtrace/contrib/grpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@
``Pin`` API::

import grpc
from ddtrace import Pin, patch, Tracer
from ddtrace import Pin, patch

patch(grpc=True)
custom_tracer = Tracer()

# override the pin on the client
Pin.override(grpc.Channel, service='mygrpc', tracer=custom_tracer)
Pin.override(grpc.Channel, service='mygrpc')
with grpc.insecure_channel('localhost:50051') as channel:
# create stubs and send requests
pass
Expand All @@ -61,13 +60,12 @@
import grpc
from grpc.framework.foundation import logging_pool

from ddtrace import Pin, patch, Tracer
from ddtrace import Pin, patch

patch(grpc=True)
custom_tracer = Tracer()

# override the pin on the server
Pin.override(grpc.Server, service='mygrpc', tracer=custom_tracer)
Pin.override(grpc.Server, service='mygrpc')
server = grpc.server(logging_pool.pool(2))
server.add_insecure_port('localhost:50051')
add_MyServicer_to_server(MyServicer(), server)
Expand Down
8 changes: 7 additions & 1 deletion ddtrace/contrib/internal/django/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import wrapt
from wrapt.importer import when_imported

import ddtrace
from ddtrace import Pin
from ddtrace import config
from ddtrace.appsec._utils import _UserInfoRetriever
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With multiple tracers gone, is there a chance that we can perhaps drop the concept of Pins entirely?

else:
pin = Pin(service, tags=tags, tracer=pin.tracer)

cursor = func(*args, **kwargs)

Expand Down
9 changes: 7 additions & 2 deletions ddtrace/contrib/internal/mongoengine/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ class WrappedConnect(wrapt.ObjectProxy):

def __init__(self, connect):
super(WrappedConnect, self).__init__(connect)
ddtrace.Pin(_SERVICE, tracer=ddtrace.tracer).onto(self)
ddtrace.Pin(_SERVICE).onto(self)

def __call__(self, *args, **kwargs):
client = self.__wrapped__(*args, **kwargs)
pin = ddtrace.Pin.get_from(self)
if pin:
ddtrace.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.Pin(service=pin.service).onto(client)
else:
ddtrace.Pin(service=pin.service, tracer=pin.tracer).onto(client)

return client
7 changes: 6 additions & 1 deletion ddtrace/contrib/internal/pylibmc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.Pin(service=schematized_service)
else:
pin = ddtrace.Pin(service=schematized_service, tracer=tracer)
pin.onto(self)

# attempt to collect the pool of urls this client talks to
Expand Down
7 changes: 6 additions & 1 deletion ddtrace/contrib/internal/sqlalchemy/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/tornado/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ def tracer_config(__init__, app, args, kwargs):
tracer.set_tags(tags)

# configure the PIN object for template rendering
ddtrace.Pin(service=service, tracer=tracer).onto(template)
ddtrace.Pin(service=service).onto(template)
4 changes: 2 additions & 2 deletions ddtrace/contrib/vertica/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
custom_tracer = Tracer()
conn = vertica_python.connect(**YOUR_VERTICA_CONFIG)

# override the service and tracer to be used
Pin.override(conn, service='myverticaservice', tracer=custom_tracer)
# override the service
Pin.override(conn, service='myverticaservice')
"""


Expand Down
20 changes: 20 additions & 0 deletions ddtrace/pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import wrapt

import ddtrace
from ddtrace.vendor.debtcollector import deprecate

from .internal.logger import get_logger

Expand Down Expand Up @@ -41,6 +42,12 @@ def __init__(
_config=None, # type: Optional[Dict[str, Any]]
):
# type: (...) -> None
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",
)
tracer = tracer or ddtrace.tracer
self.tags = tags
self.tracer = tracer
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Loading