def test_registered_disconnect_without_propagate(self): with mock.patch('celery.utils.dispatch.signal.Signal.disconnect') as disconnect: app = CeleryTracing(propagate=False) app.disconnect_traced_handlers() assert disconnect.called call_args = [call.args[0] for call in disconnect.call_args_list] assert app._prepublish not in call_args assert app._start_span in call_args assert app._tag_error in call_args assert app._tag_retry in call_args assert app._finish_span in call_args
def celery_application(self, celery_active_broker, celery_result_backend): tracer = MockTracer() self._tracer['tracer'] = tracer with CeleryTracing(tracer=tracer, broker=celery_active_broker, backend=celery_result_backend) as traced: traced.finalize() with Celery(broker=celery_active_broker, backend=celery_result_backend) as app: @app.task def add(one, two): assert self._tracer['tracer'].active_span is None return one + two self._tasks['add'] = add @app.task def blowup(): return 1 / 0 self._tasks['blowup'] = blowup yield app
def test_registered_connect_with_propagate(self): with mock.patch('celery.utils.dispatch.signal.Signal.connect') as connect: app = CeleryTracing() assert connect.called call_args = [call.args[0] for call in connect.call_args_list] assert app._prepublish in call_args assert app._start_span in call_args assert app._tag_error in call_args assert app._tag_retry in call_args assert app._finish_span in call_args
def celery_application(self, celery_active_broker, celery_result_backend): tracer = MockTracer() self._tracer['tracer'] = tracer with CeleryTracing(tracer=tracer, broker=celery_active_broker, backend=celery_result_backend) as app: @app.task def add(one, two): span = tracer.active_span span.set_tag('one', one) span.set_tag('two', two) return one + two self._tasks['add'] = add @app.task def blowup(): return 1 / 0 self._tasks['blowup'] = blowup @app.task(bind=True) def retry(self, raze=True): if not raze: return 'Success' try: raise Exception('My Exception!') except Exception as exc: self.retry(args=(False, ), exc=exc, countdown=.5) self._tasks['retry'] = retry yield app
def celery_new(_, __, *args, **kwargs): """Monkey patch Celery.__new__() to create a CeleryTracing object""" from celery_opentracing import CeleryTracing return CeleryTracing.__new__(CeleryTracing, *args, **kwargs)