Skip to content

Commit c98c31d

Browse files
authored
Merge pull request #119 from DataDog/benjamin/pin
Document `Pin.override()` as the only way to customize a client
2 parents 37d47cf + 2d07820 commit c98c31d

File tree

26 files changed

+69
-72
lines changed

26 files changed

+69
-72
lines changed

ddtrace/contrib/cassandra/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
# Use a pin to specify metadata related to this cluster
1919
cluster = Cluster(contact_points=['10.1.1.3', '10.1.1.4', '10.1.1.5'], port=9042)
20-
Pin.new(service='cassandra-backend').onto(cluster)
20+
Pin.override(cluster, service='cassandra-backend')
2121
session = cluster.connect("my_keyspace")
2222
session.execute("select id from my_table limit 10;")
2323
"""

ddtrace/contrib/cassandra/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def patch():
2323
""" patch will add tracing to the cassandra library. """
2424
setattr(cassandra.cluster.Cluster, 'connect',
2525
wrapt.FunctionWrapper(_connect, traced_connect))
26-
Pin.new(service=SERVICE, app=SERVICE, app_type="db").onto(cassandra.cluster.Cluster)
26+
Pin(service=SERVICE, app=SERVICE, app_type="db").onto(cassandra.cluster.Cluster)
2727

2828
def unpatch():
2929
cassandra.cluster.Cluster.connect = _connect

ddtrace/contrib/dbapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class TracedConnection(wrapt.ObjectProxy):
8484
def __init__(self, conn):
8585
super(TracedConnection, self).__init__(conn)
8686
name = _get_vendor(conn)
87-
Pin.new(service=name, app=name).onto(self)
87+
Pin(service=name, app=name).onto(self)
8888

8989
def cursor(self, *args, **kwargs):
9090
cursor = self.__wrapped__.cursor(*args, **kwargs)

ddtrace/contrib/elasticsearch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
# Use a pin to specify metadata related to this client
1818
es = elasticsearch.Elasticsearch(port=ELASTICSEARCH_CONFIG['port'])
19-
Pin(service='elasticsearch-videos').onto(es)
19+
Pin.override(es, service='elasticsearch-videos')
2020
es.indices.create(index='videos', ignore=400)
2121
"""
2222
from ..util import require_modules

ddtrace/contrib/elasticsearch/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, *args, **kwargs):
3333
es = _Elasticsearch(*args, **kwargs)
3434
super(TracedElasticsearch, self).__init__(es)
3535

36-
pin = Pin.new(service=DEFAULT_SERVICE, app="elasticsearch", app_type="db")
36+
pin = Pin(service=DEFAULT_SERVICE, app="elasticsearch", app_type="db")
3737
pin.onto(self)
3838

3939
wrapt.wrap_function_wrapper(es.transport, 'perform_request', _perform_request)

ddtrace/contrib/mongoengine/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
1515
# Use a pin to specify metadata related to this client
1616
client = mongoengine.connect('db', alias='master')
17-
pin = Pin.get_from(client)
18-
if pin:
19-
pin.clone(service="mongo-master").onto(client)
17+
Pin.override(client, service="mongo-master")
2018
"""
2119

2220
from ..util import require_modules

ddtrace/contrib/mongoengine/trace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class WrappedConnect(wrapt.ObjectProxy):
1717

1818
def __init__(self, connect):
1919
super(WrappedConnect, self).__init__(connect)
20-
ddtrace.Pin.new(service=mongox.TYPE, tracer=ddtrace.tracer).onto(self)
20+
ddtrace.Pin(service=mongox.TYPE, tracer=ddtrace.tracer).onto(self)
2121

2222
def __call__(self, *args, **kwargs):
2323
client = self.__wrapped__(*args, **kwargs)
@@ -33,6 +33,6 @@ def __call__(self, *args, **kwargs):
3333
app_type=AppTypes.db,
3434
)
3535
client = TracedMongoClient(client)
36-
ddtrace.Pin.new(pin.service, tracer=pin.tracer).onto(client)
36+
ddtrace.Pin(service=pin.service, tracer=pin.tracer).onto(client)
3737

3838
return client

ddtrace/contrib/mysql/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
cursor.execute("SELECT 6*7 AS the_answer;")
1616
1717
# Use a pin to specify metadata related to this connection
18-
Pin.get_from(conn).service = 'mysql-users'
18+
Pin.override(conn, service='mysql-users')
1919
2020
This package works for mysql.connector version 2.1.x.
2121
Only the default full-Python integration works. The binary C connector,

ddtrace/contrib/mysql/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _connect(func, instance, args, kwargs):
3434
def patch_conn(conn):
3535

3636
tags = {t: getattr(conn, a, '') for t, a in CONN_ATTR_BY_TAG.items()}
37-
pin = Pin.new(service="mysql", app="mysql", app_type="db", tags=tags)
37+
pin = Pin(service="mysql", app="mysql", app_type="db", tags=tags)
3838

3939
# grab the metadata from the conn
4040
wrapped = TracedConnection(conn)

ddtrace/contrib/psycopg/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
cursor.execute("select * from users where id = 1")
1616
1717
# Use a pin to specify metadata related to this connection
18-
Pin.get_from(db).service = 'postgres-users'
18+
Pin.override(db, service='postgres-users')
1919
"""
2020
from ..util import require_modules
2121

0 commit comments

Comments
 (0)