# Path: opentracing_instrumentation/utils.py
# def start_child_span(operation_name, tracer=None, parent=None, tags=None):
# 
# Path: opentracing_instrumentation/request_context.py
# def get_current_span():
#     """
#     Access current request context and extract current Span from it.
#     :return:
#         Return current span associated with the current request context.
#         If no request context is present in thread local, or the context
#         has no span, return None.
#     """
#     # Check against the old, ScopeManager-less implementation,
#     # for backwards compatibility.
#     context = RequestContextManager.current_context()
#     if context is not None:
#         return context.span
# 
#     active = opentracing.tracer.scope_manager.active
#     return active.span if active else None
# 
# def span_in_stack_context(span):
#     """
#     Create Tornado's StackContext that stores the given span in the
#     thread-local request context. This function is intended for use
#     in Tornado applications based on IOLoop, although will work fine
#     in single-threaded apps like Flask, albeit with more overhead.
# 
#     ## Usage example in Tornado application
# 
#     Suppose you have a method `handle_request(request)` in the http server.
#     Instead of calling it directly, use a wrapper:
# 
#     .. code-block:: python
# 
#         from opentracing_instrumentation import request_context
# 
#         @tornado.gen.coroutine
#         def handle_request_wrapper(request, actual_handler, *args, **kwargs)
# 
#             request_wrapper = TornadoRequestWrapper(request=request)
#             span = http_server.before_request(request=request_wrapper)
# 
#             with request_context.span_in_stack_context(span):
#                 return actual_handler(*args, **kwargs)
# 
#     :param span:
#     :return:
#         Return StackContext that wraps the request context.
#     """
# 
#     if not isinstance(opentracing.tracer.scope_manager, TornadoScopeManager):
#         raise RuntimeError('scope_manager is not TornadoScopeManager')
# 
#     # Enter the newly created stack context so we have
#     # storage available for Span activation.
#     context = tracer_stack_context()
#     entered_context = _TracerEnteredStackContext(context)
# 
#     if span is None:
#         return entered_context
# 
#     opentracing.tracer.scope_manager.activate(span, False)
#     assert opentracing.tracer.active_span is not None
#     assert opentracing.tracer.active_span is span
# 
#     return entered_context
# 
# Path: opentracing_instrumentation/client_hooks/_patcher.py
# class Patcher(object):
# 
#     def __init__(self):
#         self.patches_installed = False
# 
#     @property
#     def applicable(self):
#         raise NotImplementedError
# 
#     def install_patches(self):
#         if self.patches_installed:
#             return
# 
#         if self.applicable:
#             self._install_patches()
#         self.patches_installed = True
# 
#     def reset_patches(self):
#         if self.applicable:
#             self._reset_patches()
#         self.patches_installed = False
# 
#     def _install_patches(self):
#         raise NotImplementedError
# 
#     def _reset_patches(self):
#         raise NotImplementedError
# 
#     @classmethod
#     def configure_hook_module(cls, context):
#         def set_patcher(custom_patcher):
#             context['patcher'] = custom_patcher
# 
#         def install_patches():
#             context['patcher'].install_patches()
# 
#         def reset_patches():
#             context['patcher'].reset_patches()
# 
#         context['patcher'] = cls()
#         context['set_patcher'] = set_patcher
#         context['install_patches'] = install_patches
#         context['reset_patches'] = reset_patches


import logging
from opentracing.ext import tags
from tornado.stack_context import wrap as keep_stack_context
from opentracing_instrumentation import utils
from ..request_context import get_current_span, span_in_stack_context
from ._patcher import Patcher
    from boto3.resources.action import ServiceAction
    from boto3.s3 import inject as s3_functions
    from botocore import xform_name
    from botocore.client import BaseClient
    from botocore.exceptions import ClientError
    from s3transfer.futures import BoundedExecutor
                client, operation_name, api_params
            )

        return make_api_call_wrapper

    def _get_s3_call_wrapper(self, original_func):
        operation_name = original_func.__name__

        def s3_call_wrapper(*args, **kwargs):
            """Wraps __call__ of S3 client methods"""

            return self.perform_call(
                original_func, 'client', 's3', operation_name, *args, **kwargs
            )

        return s3_call_wrapper

    def perform_call(self, original_func, kind, service_name, operation_name,
                     *args, **kwargs):
        span = utils.start_child_span(
            operation_name='boto3:{}:{}:{}'.format(
                kind, service_name, operation_name
            ),
            parent=get_current_span()
        )

        span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)
        span.set_tag(tags.COMPONENT, 'boto3')
        span.set_tag('boto3.service_name', service_name)


# Path: opentracing_instrumentation/utils.py
# def start_child_span(operation_name, tracer=None, parent=None, tags=None):
# 
# Path: opentracing_instrumentation/request_context.py
# def get_current_span():
#     """
#     Access current request context and extract current Span from it.
#     :return:
#         Return current span associated with the current request context.
#         If no request context is present in thread local, or the context
#         has no span, return None.
#     """
#     # Check against the old, ScopeManager-less implementation,
#     # for backwards compatibility.
#     context = RequestContextManager.current_context()
#     if context is not None:
#         return context.span
# 
#     active = opentracing.tracer.scope_manager.active
#     return active.span if active else None
# 
# def span_in_stack_context(span):
#     """
#     Create Tornado's StackContext that stores the given span in the
#     thread-local request context. This function is intended for use
#     in Tornado applications based on IOLoop, although will work fine
#     in single-threaded apps like Flask, albeit with more overhead.
# 
#     ## Usage example in Tornado application
# 
#     Suppose you have a method `handle_request(request)` in the http server.
#     Instead of calling it directly, use a wrapper:
# 
#     .. code-block:: python
# 
#         from opentracing_instrumentation import request_context
# 
#         @tornado.gen.coroutine
#         def handle_request_wrapper(request, actual_handler, *args, **kwargs)
# 
#             request_wrapper = TornadoRequestWrapper(request=request)
#             span = http_server.before_request(request=request_wrapper)
# 
#             with request_context.span_in_stack_context(span):
#                 return actual_handler(*args, **kwargs)
# 
#     :param span:
#     :return:
#         Return StackContext that wraps the request context.
#     """
# 
#     if not isinstance(opentracing.tracer.scope_manager, TornadoScopeManager):
#         raise RuntimeError('scope_manager is not TornadoScopeManager')
# 
#     # Enter the newly created stack context so we have
#     # storage available for Span activation.
#     context = tracer_stack_context()
#     entered_context = _TracerEnteredStackContext(context)
# 
#     if span is None:
#         return entered_context
# 
#     opentracing.tracer.scope_manager.activate(span, False)
#     assert opentracing.tracer.active_span is not None
#     assert opentracing.tracer.active_span is span
# 
#     return entered_context
# 
# Path: opentracing_instrumentation/client_hooks/_patcher.py
# class Patcher(object):
# 
#     def __init__(self):
#         self.patches_installed = False
# 
#     @property
#     def applicable(self):
#         raise NotImplementedError
# 
#     def install_patches(self):
#         if self.patches_installed:
#             return
# 
#         if self.applicable:
#             self._install_patches()
#         self.patches_installed = True
# 
#     def reset_patches(self):
#         if self.applicable:
#             self._reset_patches()
#         self.patches_installed = False
# 
#     def _install_patches(self):
#         raise NotImplementedError
# 
#     def _reset_patches(self):
#         raise NotImplementedError
# 
#     @classmethod
#     def configure_hook_module(cls, context):
#         def set_patcher(custom_patcher):
#             context['patcher'] = custom_patcher
# 
#         def install_patches():
#             context['patcher'].install_patches()
# 
#         def reset_patches():
#             context['patcher'].reset_patches()
# 
#         context['patcher'] = cls()
#         context['set_patcher'] = set_patcher
#         context['install_patches'] = install_patches
#         context['reset_patches'] = reset_patches


# Path: opentracing_instrumentation/client_hooks/boto3.py
import logging
from opentracing.ext import tags
from tornado.stack_context import wrap as keep_stack_context
from opentracing_instrumentation import utils
from ..request_context import get_current_span, span_in_stack_context
from ._patcher import Patcher
    from boto3.resources.action import ServiceAction
    from boto3.s3 import inject as s3_functions
    from botocore import xform_name
    from botocore.client import BaseClient
    from botocore.exceptions import ClientError
    from s3transfer.futures import BoundedExecutor

                client, operation_name, api_params
            )

        return make_api_call_wrapper

    def _get_s3_call_wrapper(self, original_func):
        operation_name = original_func.__name__

        def s3_call_wrapper(*args, **kwargs):
            """Wraps __call__ of S3 client methods"""

            return self.perform_call(
                original_func, 'client', 's3', operation_name, *args, **kwargs
            )

        return s3_call_wrapper

    def perform_call(self, original_func, kind, service_name, operation_name,
                     *args, **kwargs):
        span = utils.start_child_span(
            operation_name='boto3:{}:{}:{}'.format(
                kind, service_name, operation_name
            ),
            parent=get_current_span()
        )

        span.set_tag(tags.SPAN_KIND, tags.SPAN_KIND_RPC_CLIENT)
        span.set_tag(tags.COMPONENT, 'boto3')
        span.set_tag('boto3.service_name', service_name)


        with span, span_in_stack_context(span):