Пример #1
0
    def wrapper(wrapped, instance, args, kwargs):
        tracker = current_tracker()
        if not tracker:
            return wrapped(*args, **kwargs)

        tracker.set_tracker_name(callable_name(wrapped), priority=3)
        with FunctionTracker(tracker, callable_name(wrapped)):
            try:
                return wrapped(*args, **kwargs)
            except Exception as _:
                tracker.record_exception()
                raise
Пример #2
0
    def _wrapper(wrapped, instance, args, kwargs):
        """
        :param wrapped:
        :param instance:
        :param args:
        :param kwargs:
        :return:
        """
        tracker = current_tracker()
        if not tracker:
            return wrapped(*args, **kwargs)

        tracker.set_tracker_name(callable_name(wrapped), priority=priority)
        with FunctionTracker(tracker, callable_name(wrapped)):
            return wrapped(*args, **kwargs)
Пример #3
0
    def dynamic_wrapper(wrapped, instance, args, kwargs):
        tracker = current_tracker()

        if tracker is None:
            return wrapped(*args, **kwargs)

        _name = name
        _params = params
        _label = label
        _group = group

        if callable(name):
            if instance is not None:
                _name = name(instance, *args, **kwargs)
            else:
                _name = name(*args, **kwargs)
        elif name is None:
            _name = callable_name(wrapped)

        if callable(group):
            if instance is not None:
                _group = group(instance, *args, **kwargs)
            else:
                _group = group(*args, **kwargs)

        with FunctionTracker(tracker, _name, _group, _label, _params):
            return wrapped(*args, **kwargs)
Пример #4
0
    def literal_wrapper(wrapped, instance, args, kwargs):
        tracker = current_tracker()

        if tracker is None:
            return wrapped(*args, **kwargs)

        _name = name or callable_name(wrapped)

        with FunctionTracker(tracker, _name, group, label, params):
            return wrapped(*args, **kwargs)
Пример #5
0
def pika_channel_publish_wrapper(wrapped, instance, args, kwargs):
    try:
        console.info('pika_channel_publish_wrapper before')

        console.info(args)
        console.info(kwargs)

        tracker = current_tracker()
        if not tracker:
            return wrapped(*args, **kwargs)

        tracker.set_tracker_name(callable_name(wrapped), priority=4)
        with FunctionTracker(tracker, callable_name(wrapped), params=kwargs):
            kwargs['body'] = json.dumps({
                'pika_trace_id': tracker._trace_id,
                'body': kwargs['body']
            })
            console.info('pika_channel_publish_wrapper after')
            console.info(args)
            console.info(kwargs)
            return wrapped(*args, **kwargs)
    except Exception as e:
        console.exception("pika_channel_publish_wrapper error")
Пример #6
0
    def wrapper(wrapped, instance, args, kwargs):
        console.info("args===>")
        console.info(args)
        console.info("args<===")
        tracker = current_tracker()
        console.info("wsgi_wrapper_inline>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
        console.info("current_tracker:1: %s" % tracker)
        if tracker:
            console.info("current_tracker:2: None")
            console.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
            return wrapped(*args, **kwargs)

        environ, start_response = parse_wsgi_protocol(target, *args, **kwargs)
        disable_agent = environ.get(AGENT_REQUEST_SWITCH, None)
        if disable_agent:
            console.debug("Current trace is disabled with http request environment. %s", environ)
            return wrapped(*args, **kwargs)

        tracker = Tracer(proxy_instance(), environ, framework)
        tracker.generate_trace_id()
        tracker.start_work()

        def _start_response(status, response_headers, *args):
            # deal the response header/data
            process_header(tracker, response_headers)
            tracker.deal_response(status, response_headers, *args)
            _write = start_response(status, response_headers, *args)

            return _write

        result = []
        try:
            tracker.set_tracker_name(callable_name(wrapped), priority=1)
            application = function_trace_wrapper(wrapped)
            console.info("current_tracker:2: %s" % tracker)
            with FunctionTracker(tracker, name='Application', group='Python.WSGI'):
                result = TingYunWSGIBrowserRumMiddleware(tracker, application, _start_response, environ)()  # sunyan: 1
                # result = application(environ, start_response)
            console.info("wsgi_wrapper_inline<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
        except:
            console.exception("wsgi_entrance")
            tracker.finish_work(*sys.exc_info())
            raise

        return WSGIApplicationResponse(tracker, result)
    def wrapper(wrapped, instance, args, kwargs):

        incoming_message = args[0][0]
        msg = incoming_message.message
        console.info("msg:")
        console.info(msg)
        ctxt = incoming_message.ctxt
        console.info("ctxt:")
        console.info(ctxt)

        oslo_messaging_trace_id = ctxt['oslo_messaging_trace_id'] if 'oslo_messaging_trace_id' in ctxt else None

        tracker = current_tracker()
        console.info("oslo_messaging_wrapper_inline>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
        console.info("current_tracker:1: %s" % tracker)
        if tracker:
            console.info("current_tracker:2: None")
            console.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
            return wrapped(*args, **kwargs)

        environ = {
            'k1': 'v1'
        }

        tracker = Tracer(proxy_instance(), environ, framework)
        if oslo_messaging_trace_id is not None:
            tracker._trace_id = oslo_messaging_trace_id
        tracker.generate_trace_id()
        tracker.start_work()

        result = None
        try:
            tracker.set_tracker_name(callable_name(wrapped), priority=1)
            with FunctionTracker(tracker, name='Application', group='Python.oslo_messaging', params=msg['args']):
                result = wrapped(*args, **kwargs)
            console.info("oslo_messaging_wrapper_inline<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
        except:
            console.exception("oslo_messaging_entrance")
            tracker.finish_work(*sys.exc_info())
            raise
        else:
            tracker.finish_work(None, None, None)

        return result
Пример #8
0
    def wrapper(wrapped, instance, args, kwargs):

        console.info('args:')
        console.info(args)
        console.info('kwargs:')
        console.info(kwargs)

        method = args[0]
        header = args[1]
        body = None
        pika_trace_id = None
        try:
            wrapped_message = json.loads(args[2])
            if 'pika_trace_id' in wrapped_message:
                pika_trace_id = wrapped_message['pika_trace_id']
                body = wrapped_message['body']
            else:
                body = args[2]
        except Exception:
            body = args[2]
        args = (method, header, body)
        params = {
            #'method': str(method),
            #'header': str(header),
            'body': body
        }

        tracker = current_tracker()
        console.info(
            "pika_wrapper_inline>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
        console.info("current_tracker:1: %s" % tracker)
        if tracker:
            console.info("current_tracker:2: None")
            console.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
            return wrapped(*args, **kwargs)

        environ = {'k1': 'v1'}

        tracker = Tracer(proxy_instance(), environ, framework)

        if pika_trace_id is not None:
            tracker._trace_id = pika_trace_id
        tracker.generate_trace_id()
        tracker.start_work()

        result = None
        try:
            tracker.set_tracker_name(callable_name(wrapped), priority=1)
            with FunctionTracker(tracker,
                                 name='Application',
                                 group='Python.pika',
                                 params=params):
                result = wrapped(*args, **kwargs)
            console.info(
                "pika_wrapper_inline<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
        except:
            console.exception("pika_wrapper_inline")
            tracker.finish_work(*sys.exc_info())
            raise
        else:
            tracker.finish_work(None, None, None)

        return result