예제 #1
0
def detect(module):
    """
    """
    def url_url_open(instance, method, url, *args, **kwargs):
        return url

    def parse_params(method, url, redirect=True, **kw):
        _args = (method, url)
        _kwargs = kw
        protocol = 'http' if 'https' not in url else 'https'

        if not kw:
            _kwargs = {}

        ty_headers, external_id = process_cross_trace(
            _kwargs.get("headers", None), protocol)
        _kwargs["redirect"] = redirect
        _kwargs["headers"] = ty_headers

        return external_id, _args, _kwargs

    wrap_external_trace(module,
                        'PoolManager.urlopen',
                        'urllib3',
                        url_url_open,
                        params=parse_params,
                        exception_wrapper=wrap_exception)
def detect_requests_sessions(module):
    """
    :param module:
    :return:
    """
    def request_url(instance, method, url, *args, **kwargs):
        """
        """
        return url

    def parse_params(method, url, *args, **kwargs):
        _kwargs = kwargs
        _args = (method, url) + args
        protocol = 'http' if 'https' not in url else 'https'

        if 'headers' in _kwargs:
            ty_headers, external_id = process_cross_trace(
                _kwargs['headers'], protocol)
            _kwargs['headers'] = ty_headers
        else:
            ty_headers, external_id = process_cross_trace(None, protocol)
            _kwargs['headers'] = ty_headers

        return external_id, _args, _kwargs

    wrap_external_trace(module,
                        'Session.request',
                        'requests',
                        request_url,
                        params=parse_params,
                        exception_wrapper=wrap_exception)
예제 #3
0
def detect_requests_sessions(module):
    """
    :param module:
    :return:
    """
    def request_url(instance, method, url, *args, **kwargs):
        """
        """
        return url

    def parse_params(method, url, *args, **kwargs):
        _kwargs = kwargs
        _args = (method, url) + args

        if 'headers' in _kwargs:
            _kwargs['headers'] = process_cross_trace(_kwargs['headers'])
        else:
            _kwargs['headers'] = process_cross_trace(None)

        return _args, _kwargs

    wrap_external_trace(module,
                        'Session.request',
                        'requests',
                        request_url,
                        params=parse_params,
                        exception_wrapper=wrap_exception)
def detect(module):
    def urllib_url(instance, fullurl, *args, **kwargs):
        return fullurl

    if hasattr(module, 'URLopener'):
        wrap_external_trace(module,
                            'URLopener.open',
                            'urllib',
                            urllib_url,
                            exception_wrapper=wrap_exception)
예제 #5
0
def detect_curl_httpclient(module):
    """
    :param module:
    :return:
    """
    def parse_url(instance, request, *args, **kwargs):
        return request

    wrap_external_trace(module, 'CurlAsyncHTTPClient.fetch', 'curl_httpclient',
                        parse_url)
예제 #6
0
def detect_tsslsocket(module):
    """
    :param module:
    :return:
    """
    def tsocket_ssl_url(tsocket, *args, **kwargs):
        # _unix_socket is passed in when TSSSocket initialized
        # when wrap the specified func, the TSSSocket is instance.
        url = 'thrift//%s:%s' % (tsocket.host, tsocket.port)

        if tsocket._unix_socket is None:
            url = 'thrift//%s:%s' % (tsocket.host, tsocket.port)

        return url

    wrap_external_trace(module, 'TSSLSocket.open', 'thrift', tsocket_ssl_url, exception_wrapper=wrap_exception)
def detect(module):
    def url_opener_open(instance, fullurl, *args, **kwargs):
        """
        :param instance:
        :param fullurl:
        :param args:
        :param kwargs:
        :return:
        """
        if isinstance(fullurl, six.string_types):
            return fullurl
        else:
            return fullurl.get_full_url()

    wrap_external_trace(module,
                        'OpenerDirector.open',
                        'urllib2',
                        url_opener_open,
                        exception_wrapper=wrap_exception)
예제 #8
0
def detect_https_connect_with_timeout(module):
    """
    :param module:
    :return:
    """
    def https_with_timeout_url(instance, *args, **kwargs):
        """
        :param instance: HTTPSConnectionWithTimeout instance
        :param args:
        :param kwargs:
        :return:
        """
        url = "http://%s" % instance.host
        if instance.port:
            url = 'http://%s:%s' % (instance.host, instance.port)

        return url

    wrap_external_trace(module, "HTTPSConnectionWithTimeout.connect",
                        'httplib2', https_with_timeout_url)
예제 #9
0
def detect(module):
    """
    """
    def url_url_open(instance, method, url, *args, **kwargs):
        return url

    def parse_params(method, url, redirect=True, **kw):
        _args = (method, url)
        _kwargs = kw

        if not kw:
            _kwargs = {}

        _kwargs["redirect"] = redirect
        _kwargs["headers"] = process_cross_trace(_kwargs.get("headers", None))

        return _args, _kwargs

    wrap_external_trace(module,
                        'PoolManager.urlopen',
                        'urllib3',
                        url_url_open,
                        params=parse_params,
                        exception_wrapper=wrap_exception)
def detect_httplib2_http(module):
    """
    :param module:
    :return:
    """
    def http_url(instance, uri, method="GET", *args, **kwargs):
        """
        :param instance:Http() instance
        :param uri:
        :param method:
        :param args:
        :param kwargs:
        :return:
        """
        return uri

    def parse_params(uri, method="GET", body=None, headers=None, **kwargs):
        """
        """
        _args = (uri, )
        _kwarg = kwargs

        if not kwargs:
            _kwarg = {}

        ty_headers, external_id = process_cross_trace(headers)
        _kwarg["method"] = method
        _kwarg["body"] = body
        _kwarg["headers"] = ty_headers

        return external_id, _args, _kwarg

    return wrap_external_trace(module,
                               "Http.request",
                               'httplib2',
                               http_url,
                               params=parse_params,
                               exception_wrapper=wrap_exception)