def _test_api_flow(self):
        self.assertTrue(pinpointPy.set_agent(collector_host='unix:/tmp/unexist.sock'))
        # self.assertTrue(pinpointPy.enable_debug(None))

        while True:
            id = str(random.randint(1,10000000))
            pinpointPy.set_special_key('sid',id)
            self.assertEqual(pinpointPy.start_trace(),1)
            pinpointPy.add_clue("key","value3")
            pinpointPy.add_clues("key","value3")
            value = pinpointPy.get_special_key('sid')
            self.assertEqual(value,id)
            self.assertEqual(pinpointPy.end_trace(),0)
            pinpointPy.mark_as_error("fghjk","fghjkl",234234)
示例#2
0
    def _test_api_flow(self):
        self.assertTrue(pinpointPy.set_agent(collector_host='unix:/tmp/unexist.sock'))
        # self.assertTrue(pinpointPy.enable_debug(None))

        while self.thread_running:
            pinpointPy.start_trace()
            pinpointPy.set_special_key('sid','12345678')
            pinpointPy.add_clue("key","value3")
            pinpointPy.add_clues("key","value3")
            value = pinpointPy.get_special_key('sid')
            self.assertEqual(value,'12345678')
            pinpointPy.mark_as_error("fghjk","fghjkl",234234)
            pinpointPy.end_trace()
            value = pinpointPy.get_special_key('sid')
            self.assertFalse(value)
示例#3
0
    def onBefore(self, *args, **kwargs):
        args, kwargs = super().onBefore(*args, **kwargs)
        request = Request(args[1])
        pinpointPy.add_clue('appname', APP_NAME)
        pinpointPy.add_clue('appid', APP_ID)
        ###############################################################
        # print(threading.currentThread().ident)
        print("------------------- call before -----------------------")
        pinpointPy.add_clue('name', 'BaseFlaskrequest')
        pinpointPy.add_clue('uri', request.path)
        pinpointPy.add_clue('client', request.remote_addr)
        pinpointPy.add_clue('server', request.host)
        pinpointPy.add_clue('stp', PYTHON)

        # nginx add http
        if HTTP_PINPOINT_PSPANID in request.headers:
            pinpointPy.add_clue('psid', request.headers[HTTP_PINPOINT_PSPANID])
            print("PINPOINT_PSPANID:", request.headers[HTTP_PINPOINT_PSPANID])

        if HTTP_PINPOINT_SPANID in request.headers:
            self.sid = request.headers[HTTP_PINPOINT_SPANID]
        elif PINPOINT_SPANID in request.headers:
            self.sid = request.headers[PINPOINT_SPANID]
        else:
            self.sid = self.generateSid()
        pinpointPy.set_special_key('sid', self.sid)

        if HTTP_PINPOINT_TRACEID in request.headers:
            self.tid = request.headers[HTTP_PINPOINT_TRACEID]
        elif PINPOINT_TRACEID in request.headers:
            self.tid = request.headers[PINPOINT_TRACEID]
        else:
            self.tid = self.generateTid()
        pinpointPy.set_special_key('tid', self.tid)

        if HTTP_PINPOINT_PAPPNAME in request.headers:
            self.pname = request.headers[HTTP_PINPOINT_PAPPNAME]
            pinpointPy.set_special_key('pname', self.pname)
            pinpointPy.add_clue('pname', self.pname)

        if HTTP_PINPOINT_PAPPTYPE in request.headers:
            self.ptype = request.headers[HTTP_PINPOINT_PAPPTYPE]
            pinpointPy.set_special_key('ptype', self.ptype)
            pinpointPy.add_clue('ptype', self.ptype)

        if HTTP_PINPOINT_HOST in request.headers:
            self.Ah = request.headers[HTTP_PINPOINT_HOST]
            pinpointPy.set_special_key('Ah', self.Ah)
            pinpointPy.add_clue('Ah', self.Ah)

        # Not nginx, no http
        if PINPOINT_PSPANID in request.headers:
            pinpointPy.add_clue('psid', request.headers[PINPOINT_PSPANID])
            print("PINPOINT_PSPANID:", request.headers[PINPOINT_PSPANID])

        if PINPOINT_PAPPNAME in request.headers:
            self.pname = request.headers[PINPOINT_PAPPNAME]
            pinpointPy.set_special_key('pname', self.pname)
            pinpointPy.add_clue('pname', self.pname)

        if PINPOINT_PAPPTYPE in request.headers:
            self.ptype = request.headers[PINPOINT_PAPPTYPE]
            pinpointPy.set_special_key('ptype', self.ptype)
            pinpointPy.add_clue('ptype', self.ptype)

        if PINPOINT_HOST in request.headers:
            self.Ah = request.headers[PINPOINT_HOST]
            pinpointPy.set_special_key('Ah', self.Ah)
            pinpointPy.add_clue('Ah', self.Ah)

        if NGINX_PROXY in request.headers:
            pinpointPy.add_clue('NP', request.headers[NGINX_PROXY])

        if APACHE_PROXY in request.headers:
            pinpointPy.add_clue('AP', request.headers[APACHE_PROXY])

        if SAMPLED in request.headers:
            if request.headers[SAMPLED] == 's0':
                self.isLimit = True
                pinpointPy.drop_trace()
        else:
            pinpointPy.check_tracelimit()
            # print(self.isLimit)
        pinpointPy.add_clue('tid', self.tid)
        pinpointPy.add_clue('sid', self.sid)
        ###############################################################
        return args, kwargs
    def onBefore(self, *args, **kwargs):
        args, kwargs = super(BaseHTTPRequestPlugins,
                             self).onBefore(*args, **kwargs)
        pinpointPy.add_clue('appname', APP_NAME)
        pinpointPy.add_clue('appid', APP_ID)
        ###############################################################
        print("------------------- call before -----------------------")
        insBaseHttp = args[0]
        pinpointPy.add_clue('name', 'BaseHTTPRequest request')
        pinpointPy.add_clue('uri', insBaseHttp.path)
        pinpointPy.add_clue('client', insBaseHttp.client_address[0])

        pinpointPy.add_clue('server', insBaseHttp.headers.get('Host'))
        pinpointPy.add_clue('stp', PYTHON)

        # nginx add http
        if HTTP_PINPOINT_PSPANID in insBaseHttp.headers:
            pinpointPy.add_clue('psid',
                                insBaseHttp.headers[HTTP_PINPOINT_PSPANID])
            print("PINPOINT_PSPANID:",
                  insBaseHttp.headers[HTTP_PINPOINT_PSPANID])

        if HTTP_PINPOINT_SPANID in insBaseHttp.headers:
            self.sid = insBaseHttp.headers[HTTP_PINPOINT_SPANID]
        elif PINPOINT_SPANID in insBaseHttp.headers:
            self.sid = insBaseHttp.headers[PINPOINT_SPANID]
        else:
            self.sid = self.generateSid()
        pinpointPy.set_special_key('sid', self.sid)

        if HTTP_PINPOINT_TRACEID in insBaseHttp.headers:
            self.tid = insBaseHttp.headers[HTTP_PINPOINT_TRACEID]
        elif PINPOINT_TRACEID in insBaseHttp.headers:
            self.tid = insBaseHttp.headers[PINPOINT_TRACEID]
        else:
            self.tid = self.generateTid()
        pinpointPy.set_special_key('tid', self.tid)

        if HTTP_PINPOINT_PAPPNAME in insBaseHttp.headers:
            self.pname = insBaseHttp.headers[HTTP_PINPOINT_PAPPNAME]
            pinpointPy.set_special_key('pname', self.pname)
            pinpointPy.add_clue('pname', self.pname)

        if HTTP_PINPOINT_PAPPTYPE in insBaseHttp.headers:
            self.ptype = insBaseHttp.headers[HTTP_PINPOINT_PAPPTYPE]
            pinpointPy.set_special_key('ptype', self.ptype)
            pinpointPy.add_clue('ptype', self.ptype)

        if HTTP_PINPOINT_HOST in insBaseHttp.headers:
            self.Ah = insBaseHttp.headers[HTTP_PINPOINT_HOST]
            pinpointPy.set_special_key('Ah', self.Ah)
            pinpointPy.add_clue('Ah', self.Ah)

        # Not nginx, no http
        if PINPOINT_PSPANID in insBaseHttp.headers:
            pinpointPy.add_clue('psid', insBaseHttp.headers[PINPOINT_PSPANID])
            print("PINPOINT_PSPANID:", insBaseHttp.headers[PINPOINT_PSPANID])

        if PINPOINT_PAPPNAME in insBaseHttp.headers:
            self.pname = insBaseHttp.headers[PINPOINT_PAPPNAME]
            pinpointPy.set_special_key('pname', self.pname)
            pinpointPy.add_clue('pname', self.pname)

        if PINPOINT_PAPPTYPE in insBaseHttp.headers:
            self.ptype = insBaseHttp.headers[PINPOINT_PAPPTYPE]
            pinpointPy.set_special_key('ptype', self.ptype)
            pinpointPy.add_clue('ptype', self.ptype)

        if PINPOINT_HOST in insBaseHttp.headers:
            self.Ah = insBaseHttp.headers[PINPOINT_HOST]
            pinpointPy.set_special_key('Ah', self.Ah)
            pinpointPy.add_clue('Ah', self.Ah)

        if NGINX_PROXY in insBaseHttp.headers:
            pinpointPy.add_clue('NP', insBaseHttp.headers[NGINX_PROXY])

        if APACHE_PROXY in insBaseHttp.headers:
            pinpointPy.add_clue('AP', insBaseHttp.headers[APACHE_PROXY])

        if SAMPLED in insBaseHttp.headers:
            if insBaseHttp.headers[SAMPLED] == 's0':
                self.isLimit = True
                pinpointPy.drop_trace()
                pinpointPy.set_special_key(SAMPLED, 's0')
        else:
            if pinpointPy.check_tracelimit():
                self.isLimit = True
                pinpointPy.set_special_key(SAMPLED, 's0')
            else:
                self.isLimit = False
                pinpointPy.set_special_key(SAMPLED, 's1')

        pinpointPy.add_clue('tid', self.tid)
        pinpointPy.add_clue('sid', self.sid)
        ###############################################################
        return args, kwargs
示例#5
0
    def onBefore(self,*args, **kwargs):
        super().onBefore(*args, **kwargs)
        pinpointPy.add_clue(PP_APP_NAME,APP_NAME)
        pinpointPy.add_clue(PP_APP_ID, APP_ID)
        ###############################################################
        request = args[1]
        # assert isinstance(request,BaseHTTPRequestHandler)
        pinpointPy.add_clue(PP_INTERCEPTOR_NAME, 'BaseDjangoRequest request')
        pinpointPy.add_clue(PP_REQ_URI,request.path)
        # print(request.META)
        pinpointPy.add_clue(PP_REQ_CLIENT,request.META['REMOTE_ADDR'])
        pinpointPy.add_clue(PP_REQ_SERVER,request.get_host())
        pinpointPy.add_clue(PP_SERVER_TYPE,PYTHON)

        # nginx add http
        if HTTP_PINPOINT_PSPANID in request.META:
            pinpointPy.add_clue(PP_PARENT_SPAN_ID, request.META[HTTP_PINPOINT_PSPANID])
            print("PINPOINT_PSPANID:", request.META[HTTP_PINPOINT_PSPANID])

        if HTTP_PINPOINT_SPANID in request.META:
            self.sid = request.META[HTTP_PINPOINT_SPANID]
        elif PINPOINT_SPANID in request.META:
            self.sid = request.META[PINPOINT_SPANID]
        else:
            self.sid = generateSid()
        pinpointPy.set_special_key(PP_SPAN_ID,self.sid)


        if HTTP_PINPOINT_TRACEID in request.META:
            self.tid = request.META[HTTP_PINPOINT_TRACEID]
        elif PINPOINT_TRACEID in request.META:
            self.tid = request.META[PINPOINT_TRACEID]
        else:
            self.tid = generateTid()
        pinpointPy.set_special_key(PP_TRANSCATION_ID,self.tid)

        if HTTP_PINPOINT_PAPPNAME in request.META:
            self.pname = request.META[HTTP_PINPOINT_PAPPNAME]
            pinpointPy.set_special_key(PP_PARENT_NAME,self.pname)
            pinpointPy.add_clue(PP_PARENT_NAME,self.pname)

        if HTTP_PINPOINT_PAPPTYPE in request.META:
            self.ptype = request.META[HTTP_PINPOINT_PAPPTYPE]
            pinpointPy.set_special_key(PP_PARENT_TYPE,self.ptype)
            pinpointPy.add_clue(PP_PARENT_TYPE,self.ptype)

        if HTTP_PINPOINT_HOST in request.META:
            self.Ah = request.META[HTTP_PINPOINT_HOST]
            pinpointPy.set_special_key(PP_PARENT_HOST,self.Ah)
            pinpointPy.add_clue(PP_PARENT_HOST,self.Ah)

        # Not nginx, no http
        if PINPOINT_PSPANID in request.META:
            pinpointPy.add_clue(PP_PARENT_SPAN_ID, request.META[PINPOINT_PSPANID])
            print("PINPOINT_PSPANID:", request.META[PINPOINT_PSPANID])

        if PINPOINT_PAPPNAME in request.META:
            self.pname = request.META[PINPOINT_PAPPNAME]
            pinpointPy.set_special_key(PP_PARENT_NAME, self.pname)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname)

        if PINPOINT_PAPPTYPE in request.META:
            self.ptype = request.META[PINPOINT_PAPPTYPE]
            pinpointPy.set_special_key(PP_PARENT_TYPE, self.ptype)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype)

        if PINPOINT_HOST in request.META:
            self.Ah = request.META[PINPOINT_HOST]
            pinpointPy.set_special_key(PP_PARENT_HOST, self.Ah)
            pinpointPy.add_clue(PP_PARENT_HOST, self.Ah)

        if NGINX_PROXY in request.META:
            pinpointPy.add_clue(PP_NGINX_PROXY,request.META[NGINX_PROXY])
        elif HTTP_NGINX_PROXY in request.META:
            pinpointPy.add_clue(PP_NGINX_PROXY,request.META[HTTP_NGINX_PROXY])
        
        if APACHE_PROXY in request.META:
            pinpointPy.add_clue(PP_APACHE_PROXY,request.META[APACHE_PROXY])
        elif HTTP_APACHE_PROXY in request.META:
            pinpointPy.add_clue(PP_APACHE_PROXY,request.META[HTTP_APACHE_PROXY])

        if PP_HTTP_SAMPLED in request.META :
            sampled = request.META[PP_HTTP_SAMPLED]
        elif HTTPD_SAMPLED in request.META :
            sampled = request.META[HTTPD_SAMPLED]
        else:
            sampled = PP_NOT_SAMPLED if pinpointPy.check_tracelimit() else PP_SAMPLED

        # sampled = PP_NOT_SAMPLED if pinpointPy.check_tracelimit() else PP_SAMPLED

        if sampled == PP_NOT_SAMPLED:
            self.isLimit = True
            pinpointPy.drop_trace()
            pinpointPy.set_special_key(PP_HTTP_SAMPLED,PP_NOT_SAMPLED)
        else:
            self.isLimit = False
            pinpointPy.set_special_key(PP_HTTP_SAMPLED, PP_SAMPLED)


        # if (PP_HTTP_SAMPLED in request.META and request.META[PP_HTTP_SAMPLED] == PP_NOT_SAMPLED) or \
        #         (HTTPD_SAMPLED in request.META and request.META[HTTPD_SAMPLED] == PP_NOT_SAMPLED):
        #     self.isLimit = True
        #     pinpointPy.drop_trace()
        #     pinpointPy.set_special_key(PP_HTTP_SAMPLED,PP_NOT_SAMPLED)
        # else:
        #     if pinpointPy.check_tracelimit():
        #         self.isLimit = True
        #         pinpointPy.drop_trace()
        #         pinpointPy.set_special_key(PP_HTTP_SAMPLED, PP_NOT_SAMPLED)
        #     else:
        #         self.isLimit = False
        #         pinpointPy.set_special_key(PP_HTTP_SAMPLED, PP_SAMPLED)

        pinpointPy.add_clue(PP_TRANSCATION_ID,self.tid)
        pinpointPy.add_clue(PP_SPAN_ID,self.sid)
        ###############################################################
        return args, kwargs
示例#6
0
    def onBefore(self,*args, **kwargs):
        args, kwargs = super().onBefore(*args, **kwargs)
        pinpointPy.add_clue('appname',APP_NAME)
        pinpointPy.add_clue('appid', APP_ID)
        ###############################################################
        print("------------------- call before -----------------------")
        request = args[1]
        # assert isinstance(request,BaseHTTPRequestHandler)
        pinpointPy.add_clue('name', 'BaseDjangoRequest request')
        pinpointPy.add_clue('uri',request.path)
        # print(request.META)
        pinpointPy.add_clue('client',request.META['REMOTE_ADDR'])
        pinpointPy.add_clue('server',request.get_host())
        pinpointPy.add_clue('stp',PYTHON)

        # nginx add http
        if HTTP_PINPOINT_PSPANID in request.META:
            pinpointPy.add_clue('psid', request.META[HTTP_PINPOINT_PSPANID])
            print("PINPOINT_PSPANID:", request.META[HTTP_PINPOINT_PSPANID])

        if HTTP_PINPOINT_SPANID in request.META:
            self.sid = request.META[HTTP_PINPOINT_SPANID]
        elif PINPOINT_SPANID in request.META:
            self.sid = request.META[PINPOINT_SPANID]
        else:
            self.sid = self.generateSid()
        pinpointPy.set_special_key('sid',self.sid)


        if HTTP_PINPOINT_TRACEID in request.META:
            self.tid = request.META[HTTP_PINPOINT_TRACEID]
        elif PINPOINT_TRACEID in request.META:
            self.tid = request.META[PINPOINT_TRACEID]
        else:
            self.tid = self.generateTid()
        pinpointPy.set_special_key('tid',self.tid)

        if HTTP_PINPOINT_PAPPNAME in request.META:
            self.pname = request.META[HTTP_PINPOINT_PAPPNAME]
            pinpointPy.set_special_key('pname',self.pname)
            pinpointPy.add_clue('pname',self.pname)

        if HTTP_PINPOINT_PAPPTYPE in request.META:
            self.ptype = request.META[HTTP_PINPOINT_PAPPTYPE]
            pinpointPy.set_special_key('ptype',self.ptype)
            pinpointPy.add_clue('ptype',self.ptype)

        if HTTP_PINPOINT_HOST in request.META:
            self.Ah = request.META[HTTP_PINPOINT_HOST]
            pinpointPy.set_special_key('Ah',self.Ah)
            pinpointPy.add_clue('Ah',self.Ah)

        # Not nginx, no http
        if PINPOINT_PSPANID in request.META:
            pinpointPy.add_clue('psid', request.META[PINPOINT_PSPANID])
            print("PINPOINT_PSPANID:", request.META[PINPOINT_PSPANID])

        if PINPOINT_PAPPNAME in request.META:
            self.pname = request.META[PINPOINT_PAPPNAME]
            pinpointPy.set_special_key('pname', self.pname)
            pinpointPy.add_clue('pname', self.pname)

        if PINPOINT_PAPPTYPE in request.META:
            self.ptype = request.META[PINPOINT_PAPPTYPE]
            pinpointPy.set_special_key('ptype', self.ptype)
            pinpointPy.add_clue('ptype', self.ptype)

        if PINPOINT_HOST in request.META:
            self.Ah = request.META[PINPOINT_HOST]
            pinpointPy.set_special_key('Ah', self.Ah)
            pinpointPy.add_clue('Ah', self.Ah)

        if NGINX_PROXY in request.META:
            pinpointPy.add_clue('NP',request.META[NGINX_PROXY])
        elif HTTP_NGINX_PROXY in request.META:
            pinpointPy.add_clue('NP',request.META[HTTP_NGINX_PROXY])
        
        if APACHE_PROXY in request.META:
            pinpointPy.add_clue('AP',request.META[APACHE_PROXY])
        elif HTTP_APACHE_PROXY in request.META:
            pinpointPy.add_clue('AP',request.META[HTTP_APACHE_PROXY])

        if SAMPLED in request.META :
            sampled = request.META[SAMPLED]
        elif HTTPD_SAMPLED in request.META :
            sampled = request.META[HTTPD_SAMPLED]
        else:
            sampled = 's0' if pinpointPy.check_tracelimit() else 's1'

        # sampled = 's0' if pinpointPy.check_tracelimit() else 's1'

        if sampled == 's0':
            self.isLimit = True
            pinpointPy.drop_trace()
            pinpointPy.set_special_key(SAMPLED,'s0')
        else:
            self.isLimit = False
            pinpointPy.set_special_key(SAMPLED, 's1')


        # if (SAMPLED in request.META and request.META[SAMPLED] == 's0') or \
        #         (HTTPD_SAMPLED in request.META and request.META[HTTPD_SAMPLED] == 's0'):
        #     self.isLimit = True
        #     pinpointPy.drop_trace()
        #     pinpointPy.set_special_key(SAMPLED,'s0')
        # else:
        #     if pinpointPy.check_tracelimit():
        #         self.isLimit = True
        #         pinpointPy.drop_trace()
        #         pinpointPy.set_special_key(SAMPLED, 's0')
        #     else:
        #         self.isLimit = False
        #         pinpointPy.set_special_key(SAMPLED, 's1')

        pinpointPy.add_clue('tid',self.tid)
        pinpointPy.add_clue('sid',self.sid)
        ###############################################################
        return args, kwargs