def setUp(self): # keep track of original config self._config = dict(config.celery) # instrument Celery and create an app with Broker and Result backends patch() self.tracer = get_dummy_tracer() self.pin = Pin(service='celery-unittest', tracer=self.tracer) self.app = Celery('celery.test_app', broker=BROKER_URL, backend=BACKEND_URL) # override pins to use our Dummy Tracer Pin.override(self.app, tracer=self.tracer)
def setUp(self): super(CeleryBaseTestCase, self).setUp() # instrument Celery and create an app with Broker and Result backends patch() self.pin = Pin(service="celery-unittest", tracer=self.tracer) self.app = Celery("celery.test_app", broker=BROKER_URL, backend=BACKEND_URL) # override pins to use our Dummy Tracer Pin.override(self.app, tracer=self.tracer)
def patch_all(**patch_modules): """Automatically patches all available modules. :param dict \**patch_modules: Override whether particular modules are patched or not. >>> patch_all(redis=False, cassandra=False) """ modules = PATCH_MODULES.copy() modules.update(patch_modules) patch(raise_errors=False, **modules)
def instrument_celery(self): # Register our context-ruining signal before the normal ones so that # the "real" task_prerun signal starts with the new context celery.signals.task_prerun.connect(self.inject_new_context) # instrument Celery and create an app with Broker and Result backends patch() yield # remove instrumentation from Celery unpatch() celery.signals.task_prerun.disconnect(self.inject_new_context)
def test_idempotent_patch(self): # calling patch() twice doesn't have side effects patch() @self.app.task def fn_task(): return 42 t = fn_task.apply() assert t.successful() assert 42 == t.result traces = self.pop_traces() assert 1 == len(traces) assert 1 == len(traces[0])
def test_idempotent_patch(self): # calling patch() twice doesn't have side effects patch() @self.app.task def fn_task(): return 42 t = fn_task.apply() ok_(t.successful()) eq_(42, t.result) traces = self.tracer.writer.pop_traces() eq_(1, len(traces)) eq_(1, len(traces[0]))
def instrument_celery(self): # instrument Celery and create an app with Broker and Result backends patch() yield # remove instrumentation from Celery unpatch()
def patch_celery(hook): from ddtrace.contrib.celery import patch patch()