# Path: opentracing_instrumentation/client_hooks/celery.py
# def task_apply_async_wrapper(task, args=None, kwargs=None, **other_kwargs):
# def set_common_tags(span, task, span_kind):
# def before_task_publish_handler(headers, **kwargs):
# def task_prerun_handler(task, task_id, **kwargs):
# def finish_current_span(task, exc_type=None, exc_val=None, exc_tb=None):
# def task_success_handler(sender, **kwargs):
# def task_failure_handler(sender, exception, traceback, **kwargs):
#     def _install_patches(self):
#     def _reset_patches(self):
# class CeleryPatcher(Patcher):


import celery as celery_module
import mock
import pytest
from celery import Celery
from celery.signals import (
    before_task_publish, after_task_publish, task_postrun
)
from celery.states import SUCCESS, FAILURE
from celery.worker import state as celery_worker_state
from kombu import Connection
from opentracing.ext import tags
from opentracing_instrumentation.client_hooks import celery as celery_hooks
    foo.called = False

    result = foo.delay()
    assert foo.called
    if task_error:
        assert result.status == FAILURE
        if not (
            CELERY_3 and celery.conf.defaults[0].get('CELERY_ALWAYS_EAGER')
        ):
            celery_logger.log.assert_called_once()
    else:
        assert result.status == SUCCESS
        celery_logger.log.assert_not_called()

    return result


def _test_with_instrumented_client(celery, tracer, task_error):
    result = _test_foo_task(celery, task_error)

    span_server, span_client = tracer.recorder.get_spans()
    assert span_client.parent_id is None
    assert span_client.context.trace_id == span_server.context.trace_id
    assert span_client.context.span_id == span_server.parent_id

    assert_span(span_client, result, 'apply_async', tags.SPAN_KIND_RPC_CLIENT)
    assert_span(span_server, result, 'run', tags.SPAN_KIND_RPC_SERVER)


@mock.patch(

# Path: opentracing_instrumentation/client_hooks/celery.py
# def task_apply_async_wrapper(task, args=None, kwargs=None, **other_kwargs):
# def set_common_tags(span, task, span_kind):
# def before_task_publish_handler(headers, **kwargs):
# def task_prerun_handler(task, task_id, **kwargs):
# def finish_current_span(task, exc_type=None, exc_val=None, exc_tb=None):
# def task_success_handler(sender, **kwargs):
# def task_failure_handler(sender, exception, traceback, **kwargs):
#     def _install_patches(self):
#     def _reset_patches(self):
# class CeleryPatcher(Patcher):


# Path: tests/opentracing_instrumentation/test_celery.py
import celery as celery_module
import mock
import pytest
from celery import Celery
from celery.signals import (
    before_task_publish, after_task_publish, task_postrun
)
from celery.states import SUCCESS, FAILURE
from celery.worker import state as celery_worker_state
from kombu import Connection
from opentracing.ext import tags
from opentracing_instrumentation.client_hooks import celery as celery_hooks

    foo.called = False

    result = foo.delay()
    assert foo.called
    if task_error:
        assert result.status == FAILURE
        if not (
            CELERY_3 and celery.conf.defaults[0].get('CELERY_ALWAYS_EAGER')
        ):
            celery_logger.log.assert_called_once()
    else:
        assert result.status == SUCCESS
        celery_logger.log.assert_not_called()

    return result


def _test_with_instrumented_client(celery, tracer, task_error):
    result = _test_foo_task(celery, task_error)

    span_server, span_client = tracer.recorder.get_spans()
    assert span_client.parent_id is None
    assert span_client.context.trace_id == span_server.context.trace_id
    assert span_client.context.span_id == span_server.parent_id

    assert_span(span_client, result, 'apply_async', tags.SPAN_KIND_RPC_CLIENT)
    assert_span(span_server, result, 'run', tags.SPAN_KIND_RPC_SERVER)


@mock.patch(

    'celery.app.task.Task.apply_async', new=celery_hooks._task_apply_async