File tree Expand file tree Collapse file tree 8 files changed +75
-5
lines changed Expand file tree Collapse file tree 8 files changed +75
-5
lines changed Original file line number Diff line number Diff line change 2424
2525with require_modules (required_modules ) as missing_modules :
2626 if not missing_modules :
27- from .patch import patch
27+ from .patch import patch , trace_mongoengine
28+
29+ __all__ = ['patch' , 'trace_mongoengine' ]
30+
2831
29- __all__ = ['patch' ]
Original file line number Diff line number Diff line change 11import mongoengine
22
33from .trace import WrappedConnect
4+ from ddtrace .util import deprecated
45
56# Original connect function
67_connect = mongoengine .connect
@@ -12,3 +13,7 @@ def patch():
1213def unpatch ():
1314 setattr (mongoengine , 'connect' , _connect )
1415
16+ @deprecated (message = 'Use patching instead (see the docs).' , version = '0.6.0' )
17+ def trace_mongoengine (* args , ** kwargs ):
18+ return _connect
19+
Original file line number Diff line number Diff line change @@ -10,5 +10,5 @@ def patch():
1010 setattr (pylibmc , 'Client' , TracedClient )
1111
1212def unpatch ():
13- setattr (pylibmc , 'Elasticsearch ' , _Client )
13+ setattr (pylibmc , 'Client ' , _Client )
1414
Original file line number Diff line number Diff line change 1+ """
2+ ensure old interfaces exist and won't break things.
3+ """
4+
5+
6+ import mongoengine
7+
8+ from tests .test_tracer import get_dummy_tracer
9+ from tests .contrib import config
10+
11+ class Singer (mongoengine .Document ):
12+ first_name = mongoengine .StringField (max_length = 50 )
13+ last_name = mongoengine .StringField (max_length = 50 )
14+
15+
16+ def test_less_than_v04 ():
17+ # interface from < v0.4
18+ from ddtrace .contrib .mongoengine import trace_mongoengine
19+ tracer = get_dummy_tracer ()
20+
21+ connect = trace_mongoengine (tracer , service = "my-mongo-db" , patch = False )
22+ connect (port = config .MONGO_CONFIG ['port' ])
23+
24+ lc = Singer ()
25+ lc .first_name = 'leonard'
26+ lc .last_name = 'cohen'
27+ lc .save ()
Original file line number Diff line number Diff line change 1+
2+ from ddtrace .contrib .mysql import get_traced_mysql_connection
3+ from tests .test_tracer import get_dummy_tracer
4+ from tests .contrib import config
5+
6+
7+ def test_pre_v4 ():
8+ tracer = get_dummy_tracer ()
9+ MySQL = get_traced_mysql_connection (tracer , service = "my-mysql-server" )
10+ conn = MySQL (** config .MYSQL_CONFIG )
11+ cursor = conn .cursor ()
12+ cursor .execute ("SELECT 1" )
13+ assert cursor .fetchone ()[0 ] == 1
Original file line number Diff line number Diff line change @@ -169,3 +169,10 @@ def test_patch_unpatch(self):
169169 spans = writer .pop ()
170170 assert spans , spans
171171 eq_ (len (spans ), 1 )
172+
173+ def test_backwards_compatibilty_v3 ():
174+ tracer = get_dummy_tracer ()
175+ factory = connection_factory (tracer , service = "my-postgres-db" )
176+ conn = psycopg2 .connect (connection_factory = factory , ** POSTGRES_CONFIG )
177+ conn .cursor ().execute ("select 'blah'" )
178+
Original file line number Diff line number Diff line change 66from nose .tools import eq_ , ok_
77
88from ddtrace import Pin , compat
9- from ddtrace .contrib .redis import get_traced_redis
9+ from ddtrace .contrib .redis import get_traced_redis , get_traced_redis_from
1010from ddtrace .contrib .redis .patch import patch , unpatch
1111from ..config import REDIS_CONFIG
1212from ...test_tracer import get_dummy_tracer
Original file line number Diff line number Diff line change 1111import sys
1212
1313# 3p
14+ import pylibmc
1415import pympler .tracker
1516import psycopg2
1617import redis
1718
19+
1820# project
1921import ddtrace
2022from tests .contrib import config
2123
2224
23- ddtrace .patch (redis = True )
25+ # verbosity
26+ logging .basicConfig (stream = sys .stderr , level = logging .INFO )
27+ ddtrace .tracer .debug_logging = False
28+
29+ ddtrace .patch_all ()
2430ddtrace .tracer .writer = None
2531
2632
@@ -30,9 +36,15 @@ def __init__(self):
3036 self ._redis = redis .Redis (** config .REDIS_CONFIG )
3137 self ._pg = psycopg2 .connect (** config .POSTGRES_CONFIG )
3238
39+ url = "%s:%s" % (
40+ config .MEMCACHED_CONFIG ["host" ],
41+ config .MEMCACHED_CONFIG ["port" ])
42+ self ._pylibmc = pylibmc .Client ([url ])
43+
3344 def ping (self , i ):
3445 self ._ping_redis (i )
3546 self ._ping_pg (i )
47+ self ._ping_pylibmc (i )
3648
3749 def _ping_redis (self , i ):
3850 with self ._redis .pipeline () as p :
@@ -48,6 +60,10 @@ def _ping_pg(self, i):
4860 finally :
4961 cur .close ()
5062
63+ def _ping_pylibmc (self , i ):
64+ self ._pylibmc .set ("a" , 1 )
65+ self ._pylibmc .incr ("a" , 2 )
66+ self ._pylibmc .decr ("a" , 1 )
5167
5268if __name__ == '__main__' :
5369 k = KitchenSink ()
You can’t perform that action at this time.
0 commit comments