@@ -77,16 +77,28 @@ def patch(raise_errors=True, **patch_modules):
7777 >>> patch(psycopg=True, elasticsearch=True)
7878 """
7979 modules = [m for (m , should_patch ) in patch_modules .items () if should_patch ]
80- count = 0
8180 for module in modules :
82- patched = patch_module (module , raise_errors = raise_errors )
83- if patched :
84- count += 1
85-
81+ # TODO: this is a temporary hack until we shift to using
82+ # post-import hooks for everything.
83+ if module == 'celery' :
84+ # if patch celery via post-import hooks
85+ from wrapt .importer import when_imported
86+
87+ @when_imported ('celery' )
88+ def patch_celery (hook ):
89+ from ddtrace .contrib .celery import patch
90+ patch ()
91+
92+ # manually add celery to patched modules
93+ _PATCHED_MODULES .add (module )
94+ else :
95+ patch_module (module , raise_errors = raise_errors )
96+
97+ patched_modules = get_patched_modules ()
8698 log .info ("patched %s/%s modules (%s)" ,
87- count ,
99+ len ( patched_modules ) ,
88100 len (modules ),
89- "," .join (get_patched_modules () ))
101+ "," .join (patched_modules ))
90102
91103
92104def patch_module (module , raise_errors = True ):
@@ -115,7 +127,7 @@ def _patch_module(module):
115127 """
116128 path = 'ddtrace.contrib.%s' % module
117129 with _LOCK :
118- if module in _PATCHED_MODULES :
130+ if module in _PATCHED_MODULES and module != 'celery' :
119131 log .debug ("already patched: %s" , path )
120132 return False
121133
0 commit comments