def onEnd(self, ret):
     ###############################################################
     if self.isLimit:
         pinpointPy.drop_trace(self.node_id)
     ###############################################################
     super().onEnd(ret)
     self.isLimit = False
     return ret
Example #2
0
 def onEnd(self,ret):
     ###############################################################
     if self.isLimit:
         pinpointPy.drop_trace()
     print("------------------- call end -----------------------")
     ###############################################################
     super().onEnd(ret)
     self.isLimit = False
     return ret
 def onEnd(self, ret):
     ###############################################################
     if self.isLimit:
         pinpointPy.drop_trace()
     print("------------------- call end -----------------------")
     ###############################################################
     super(BaseHTTPRequestPlugins, self).onEnd(ret)
     self.isLimit = False
     return ret
Example #4
0
    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.start_trace()
            pinpointPy.set_context_key('sid', id)
            pinpointPy.add_clue("key", "value3")
            pinpointPy.add_clues("key", "value3")
            value = pinpointPy.get_context_key('sid')
            self.assertEqual(value, id)
            pinpointPy.mark_as_error("fghjk", "fghjkl", 234234)
            pinpointPy.end_trace()
            pinpointPy.force_flush_trace()
            pinpointPy.drop_trace()
    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_context_key('sid', '12345678')
            pinpointPy.add_clue("key", "value3")
            pinpointPy.add_clues("key", "value3")
            value = pinpointPy.get_context_key('sid')
            self.assertEqual(value, '12345678')
            pinpointPy.mark_as_error("fghjk", "fghjkl", 234234)
            pinpointPy.end_trace()
            pinpointPy.force_flush_trace()
            pinpointPy.drop_trace()
            value = pinpointPy.get_context_key('sid')
            self.assertFalse(value)
Example #6
0
    def onBefore(self, *args, **kwargs):
        super().onBefore(*args, **kwargs)
        ###############################################################
        pinpointPy.add_clue(PP_INTERCEPTOR_NAME, self.getFuncUniqueName())
        pinpointPy.add_clue(PP_SERVER_TYPE, PP_RABBITMQ_CLIENT)
        if 'exchange' in kwargs and not kwargs['exchange']:
            pinpointPy.add_clues(PP_RABBITMQ_EXCHANGEKEY, kwargs['exchange'])

        if 'routing_key' in kwargs and not kwargs['routing_key']:
            if kwargs['routing_key'] == 'worker.heartbeat':
                pinpointPy.drop_trace()
            pinpointPy.add_clues(PP_RABBITMQ_ROUTINGKEY, kwargs['routing_key'])
        target = kwargs['headers']['task']
        generatePPRabbitMqHeader(target, kwargs['headers'])

        uri = args[0].connection.as_uri()
        pinpointPy.add_clue(PP_DESTINATION, str(uri))
        ###############################################################
        return args, kwargs
Example #7
0
    def onBefore(self, *args, **kwargs):
        super().onBefore(*args, **kwargs)
        APP_NAME = 'celery-task-queue'
        APP_ID = args[0].name[0:24]
        pinpointPy.add_clue(PP_APP_NAME, APP_NAME)
        pinpointPy.add_clue(PP_APP_ID, APP_ID)
        pinpointPy.set_context_key(PP_APP_NAME, APP_NAME)
        ###############################################################
        headers = args[4]

        pinpointPy.add_clue(PP_INTERCEPTOR_NAME, 'worker')
        pinpointPy.add_clue(PP_REQ_URI, APP_ID)
        pinpointPy.add_clue(PP_REQ_SERVER, APP_ID)
        pinpointPy.add_clue(PP_SERVER_TYPE, PP_CELERY_WORKER)
        pinpointPy.add_clue('FT', PP_CELERY_WORKER)
        pinpointPy.set_context_key(PP_SERVER_TYPE, PP_CELERY_WORKER)

        if PP_HEADER_PINPOINT_CLIENT in headers:
            pinpointPy.add_clue(PP_REQ_CLIENT,
                                headers[PP_HEADER_PINPOINT_CLIENT])
        # nginx add http
        if PP_HTTP_PINPOINT_PSPANID in headers:
            pinpointPy.add_clue(PP_PARENT_SPAN_ID,
                                headers[PP_HTTP_PINPOINT_PSPANID])
        elif PP_HEADER_PINPOINT_PSPANID in headers:
            pinpointPy.add_clue(PP_PARENT_SPAN_ID,
                                headers[PP_HEADER_PINPOINT_PSPANID])

        if PP_HTTP_PINPOINT_SPANID in headers:
            self.sid = headers[PP_HTTP_PINPOINT_SPANID]
        elif PP_HEADER_PINPOINT_SPANID in headers:
            self.sid = headers[PP_HEADER_PINPOINT_SPANID]
        else:
            self.sid = generateSid()
        pinpointPy.set_context_key(PP_SPAN_ID, self.sid)

        if PP_HTTP_PINPOINT_TRACEID in headers:
            self.tid = headers[PP_HTTP_PINPOINT_TRACEID]
        elif PP_HEADER_PINPOINT_TRACEID in headers:
            self.tid = headers[PP_HEADER_PINPOINT_TRACEID]
        else:
            self.tid = generateTid()
        pinpointPy.set_context_key(PP_TRANSCATION_ID, self.tid)

        if PP_HTTP_PINPOINT_PAPPNAME in headers:
            self.pname = headers[PP_HTTP_PINPOINT_PAPPNAME]
            pinpointPy.set_context_key(PP_PARENT_NAME, self.pname)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname)

        if PP_HTTP_PINPOINT_PAPPTYPE in headers:
            self.ptype = headers[PP_HTTP_PINPOINT_PAPPTYPE]
            pinpointPy.set_context_key(PP_PARENT_TYPE, self.ptype)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype)

        if PP_HTTP_PINPOINT_HOST in headers:
            self.Ah = headers[PP_HTTP_PINPOINT_HOST]
            pinpointPy.set_context_key(PP_PARENT_HOST, self.Ah)
            pinpointPy.add_clue(PP_PARENT_HOST, self.Ah)

        if PP_HTTP_PINPOINT_PSPANID in headers:
            pinpointPy.add_clue(PP_PARENT_SPAN_ID,
                                headers[PP_HTTP_PINPOINT_PSPANID])

        if PP_HEADER_PINPOINT_PAPPNAME in headers:
            self.pname = headers[PP_HEADER_PINPOINT_PAPPNAME]
            pinpointPy.set_context_key(PP_PARENT_NAME, self.pname)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname)

        if PP_HEADER_PINPOINT_PAPPTYPE in headers:
            self.ptype = headers[PP_HEADER_PINPOINT_PAPPTYPE]
            pinpointPy.set_context_key(PP_PARENT_TYPE, self.ptype)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype)

        if PP_HEADER_PINPOINT_HOST in headers:
            self.Ah = headers[PP_HEADER_PINPOINT_HOST]
            pinpointPy.set_context_key(PP_PARENT_HOST, self.Ah)
            pinpointPy.add_clue(PP_PARENT_HOST, self.Ah)

        pinpointPy.set_context_key(PP_HEADER_PINPOINT_SAMPLED, "s1")
        if (PP_HTTP_PINPOINT_SAMPLED in headers
                and headers[PP_HTTP_PINPOINT_SAMPLED]
                == PP_NOT_SAMPLED) or pinpointPy.check_tracelimit():
            pinpointPy.drop_trace()
            pinpointPy.set_context_key(PP_HEADER_PINPOINT_SAMPLED, "s0")

        pinpointPy.add_clue(PP_TRANSCATION_ID, self.tid)
        pinpointPy.add_clue(PP_SPAN_ID, self.sid)
        pinpointPy.set_context_key(PP_TRANSCATION_ID, self.tid)
        pinpointPy.set_context_key(PP_SPAN_ID, self.sid)

        ###############################################################
        return args, kwargs
Example #8
0
    def perRequestOnBefore(self, *args, **kwargs):
        super().onBefore(*args, **kwargs)
        APP_NAME = 'celery-task-queue'
        taskName = args[3]['task']
        APP_ID = taskName[0:24]

        pinpointPy.add_clue(PP_APP_NAME, APP_NAME)
        pinpointPy.add_clue(PP_APP_ID, APP_ID)
        pinpointPy.set_context_key(PP_APP_NAME, APP_NAME)
        ###############################################################

        headers = args[3]
        pinpointPy.add_clue(PP_INTERCEPTOR_NAME, 'worker')
        pinpointPy.add_clue(PP_REQ_URI, APP_ID)
        if 'hostname' in headers:
            pinpointPy.add_clue(PP_REQ_SERVER, headers['hostname'])
        # use PP_RABBITMQ_CLIENT as default
        serverType = PP_RABBITMQ_CLIENT

        if PP_HEADER_PINPOINT_SPANID in headers:
            self.sid = headers[PP_HEADER_PINPOINT_SPANID]
        else:
            self.sid = generateSid()
        pinpointPy.set_context_key(PP_SPAN_ID, self.sid)

        if PP_HEADER_PINPOINT_TRACEID in headers:
            self.tid = headers[PP_HEADER_PINPOINT_TRACEID]
        else:
            self.tid = generateTid()
        pinpointPy.set_context_key(PP_TRANSCATION_ID, self.tid)

        if 'delivery_info' in headers:
            pinpointPy.add_clue(PP_PARENT_NAME, "celery-beat")
            pinpointPy.add_clue(PP_REQ_CLIENT, "Unknown")
            if 'origin' in headers:
                pinpointPy.add_clue(PP_PARENT_HOST, headers['origin'])
            if 'exchange' in headers:
                pinpointPy.add_clue(
                    PP_REQ_URI, "rabbitmq://exchange=" + headers['exchange'])
            if 'routing_key' in headers:
                pinpointPy.add_clues(PP_RABBITMQ_ROUTINGKEY,
                                     headers['routing_key'])
            # set span id zero
            pinpointPy.add_clue(PP_PARENT_SPAN_ID, '0')

        if PP_HEADER_PINPOINT_CLIENT in headers:
            pinpointPy.add_clue(PP_REQ_CLIENT,
                                headers[PP_HEADER_PINPOINT_CLIENT])

        if PP_HTTP_PINPOINT_PAPPNAME in headers:
            self.pname = headers[PP_HTTP_PINPOINT_PAPPNAME]
            pinpointPy.set_context_key(PP_PARENT_NAME, self.pname)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname)

        if PP_HTTP_PINPOINT_PAPPTYPE in headers:
            self.ptype = headers[PP_HTTP_PINPOINT_PAPPTYPE]
            pinpointPy.set_context_key(PP_PARENT_TYPE, self.ptype)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype)
            pinpointPy.add_clue(PP_SERVER_TYPE, self.ptype)

        if PP_HEADER_PINPOINT_HOST in headers:
            self.Ah = headers[PP_HEADER_PINPOINT_HOST]
            pinpointPy.set_context_key(PP_PARENT_HOST, self.Ah)
            pinpointPy.add_clue(PP_PARENT_HOST, self.Ah)

        if PP_HEADER_PINPOINT_PSPANID in headers:
            pinpointPy.add_clue(PP_PARENT_SPAN_ID,
                                headers[PP_HEADER_PINPOINT_PSPANID])

        if PP_HEADER_PINPOINT_PAPPNAME in headers:
            self.pname = headers[PP_HEADER_PINPOINT_PAPPNAME]
            pinpointPy.set_context_key(PP_PARENT_NAME, self.pname)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname)

        if PP_HEADER_PINPOINT_PAPPTYPE in headers:
            self.ptype = headers[PP_HEADER_PINPOINT_PAPPTYPE]
            pinpointPy.set_context_key(PP_PARENT_TYPE, self.ptype)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype)
            serverType = PYTHON

        pinpointPy.set_context_key(PP_HEADER_PINPOINT_SAMPLED, "s1")
        if (PP_HEADER_PINPOINT_SAMPLED in headers
                and headers[PP_HEADER_PINPOINT_SAMPLED]
                == PP_NOT_SAMPLED) or pinpointPy.check_tracelimit():
            pinpointPy.drop_trace()
            pinpointPy.set_context_key(PP_HEADER_PINPOINT_SAMPLED, "s0")

        pinpointPy.add_clue(PP_TRANSCATION_ID, self.tid)
        pinpointPy.add_clue(PP_SPAN_ID, self.sid)
        pinpointPy.set_context_key(PP_TRANSCATION_ID, self.tid)
        pinpointPy.set_context_key(PP_SPAN_ID, self.sid)
        pinpointPy.add_clue(PP_SERVER_TYPE, serverType)
        pinpointPy.set_context_key(PP_SERVER_TYPE, serverType)

        ###############################################################
        return args, kwargs
    def onBefore(self, *args, **kwargs):
        super().onBefore(*args, **kwargs)
        pinpointPy.add_clue(PP_APP_NAME, APP_NAME, self.node_id)
        pinpointPy.add_clue(PP_APP_ID, APP_ID, self.node_id)
        ###############################################################
        insBaseHttp = args[0]
        assert isinstance(insBaseHttp, tornado.web.RequestHandler)
        pinpointPy.add_clue(PP_INTERCEPTOR_NAME, 'tornado.web.RequestHandler',
                            self.node_id)
        pinpointPy.add_clue(PP_REQ_URI, insBaseHttp.request.uri, self.node_id)
        pinpointPy.add_clue(PP_REQ_CLIENT, insBaseHttp.request.remote_ip,
                            self.node_id)
        pinpointPy.add_clue(PP_REQ_SERVER, insBaseHttp.request.host_name,
                            self.node_id)
        pinpointPy.add_clue(PP_SERVER_TYPE, PYTHON, self.node_id)

        insRequest = insBaseHttp.request
        # nginx add http
        if PP_HTTP_PINPOINT_PSPANID in insRequest.headers:
            pinpointPy.add_clue(PP_PARENT_SPAN_ID,
                                insRequest.headers[PP_HTTP_PINPOINT_PSPANID],
                                self.node_id)

        if PP_HTTP_PINPOINT_SPANID in insRequest.headers:
            self.sid = insRequest.headers[PP_HTTP_PINPOINT_SPANID]
        elif PP_HEADER_PINPOINT_SPANID in insRequest.headers:
            self.sid = insRequest.headers[PP_HEADER_PINPOINT_SPANID]
        else:
            self.sid = self.generateSid()
        pinpointPy.set_context_key(PP_SPAN_ID, self.sid, self.node_id)

        if PP_HTTP_PINPOINT_TRACEID in insRequest.headers:
            self.tid = insRequest.headers[PP_HTTP_PINPOINT_TRACEID]
        elif PP_HEADER_PINPOINT_TRACEID in insRequest.headers:
            self.tid = insRequest.headers[PP_HEADER_PINPOINT_TRACEID]
        else:
            self.tid = self.generateTid()
        pinpointPy.set_context_key(PP_TRANSCATION_ID, self.tid, self.node_id)

        if PP_HTTP_PINPOINT_PAPPNAME in insRequest.headers:
            self.pname = insRequest.headers[PP_HTTP_PINPOINT_PAPPNAME]
            pinpointPy.set_context_key(PP_PARENT_NAME, self.pname,
                                       self.node_id)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname, self.node_id)

        if PP_HTTP_PINPOINT_PAPPTYPE in insRequest.headers:
            self.ptype = insRequest.headers[PP_HTTP_PINPOINT_PAPPTYPE]
            pinpointPy.set_context_key(PP_PARENT_TYPE, self.ptype,
                                       self.node_id)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype, self.node_id)

        if PP_HTTP_PINPOINT_HOST in insRequest.headers:
            self.Ah = insRequest.headers[PP_HTTP_PINPOINT_HOST]
            pinpointPy.set_context_key(PP_PARENT_HOST, self.Ah, self.node_id)
            pinpointPy.add_clue(PP_PARENT_HOST, self.Ah, self.node_id)

        # Not nginx, no http
        if PP_HEADER_PINPOINT_PSPANID in insRequest.headers:
            pinpointPy.add_clue(PP_PARENT_SPAN_ID,
                                insRequest.headers[PP_HEADER_PINPOINT_PSPANID],
                                self.node_id)

        if PP_HEADER_PINPOINT_PAPPNAME in insRequest.headers:
            self.pname = insRequest.headers[PP_HEADER_PINPOINT_PAPPNAME]
            pinpointPy.set_context_key(PP_PARENT_NAME, self.pname,
                                       self.node_id)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname, self.node_id)

        if PP_HEADER_PINPOINT_PAPPTYPE in insRequest.headers:
            self.ptype = insRequest.headers[PP_HEADER_PINPOINT_PAPPTYPE]
            pinpointPy.set_context_key(PP_PARENT_TYPE, self.ptype,
                                       self.node_id)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype, self.node_id)

        if PP_HEADER_PINPOINT_HOST in insRequest.headers:
            self.Ah = insRequest.headers[PP_HEADER_PINPOINT_HOST]
            pinpointPy.set_context_key(PP_PARENT_HOST, self.Ah, self.node_id)
            pinpointPy.add_clue(PP_PARENT_HOST, self.Ah, self.node_id)

        if PP_NGINX_PROXY in insRequest.headers:
            pinpointPy.add_clue(PP_NGINX_PROXY,
                                insRequest.headers[PP_NGINX_PROXY],
                                self.node_id)

        if PP_APACHE_PROXY in insRequest.headers:
            pinpointPy.add_clue(PP_APACHE_PROXY,
                                insRequest.headers[PP_APACHE_PROXY],
                                self.node_id)

        if PP_HEADER_PINPOINT_SAMPLED in insRequest.headers:
            if insRequest.headers[
                    PP_HEADER_PINPOINT_SAMPLED] == PP_NOT_SAMPLED:
                self.isLimit = True
                pinpointPy.drop_trace(self.node_id)
                pinpointPy.set_context_key(PP_HEADER_PINPOINT_SAMPLED,
                                           PP_NOT_SAMPLED, self.node_id)
        else:
            if pinpointPy.check_tracelimit():
                self.isLimit = True
                pinpointPy.set_context_key(PP_HEADER_PINPOINT_SAMPLED,
                                           PP_NOT_SAMPLED, self.node_id)
            else:
                self.isLimit = False
                pinpointPy.set_context_key(PP_HEADER_PINPOINT_SAMPLED,
                                           PP_SAMPLED, self.node_id)

        pinpointPy.add_clue(PP_TRANSCATION_ID, self.tid, self.node_id)
        pinpointPy.add_clue(PP_SPAN_ID, self.sid, self.node_id)
        ###############################################################
        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
Example #11
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
    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)
        pinpointPy.set_context_key(PP_APP_NAME, APP_NAME)
        ###############################################################
        request = args[1]
        headers = request.META

        # assert isinstance(request,BaseHTTPRequestHandler)
        pinpointPy.add_clue(PP_INTERCEPTOR_NAME, 'BaseDjangoRequest request')
        pinpointPy.add_clue(PP_REQ_URI, request.path)
        # print(headers)
        pinpointPy.add_clue(PP_REQ_CLIENT, headers['REMOTE_ADDR'])
        pinpointPy.add_clue(PP_REQ_SERVER, request.get_host())
        pinpointPy.add_clue(PP_SERVER_TYPE, PYTHON)
        pinpointPy.set_context_key(PP_SERVER_TYPE, PYTHON)
        # nginx add http
        if PP_HTTP_PINPOINT_PSPANID in headers:
            pinpointPy.add_clue(PP_PARENT_SPAN_ID,
                                headers[PP_HTTP_PINPOINT_PSPANID])

        if PP_HTTP_PINPOINT_SPANID in headers:
            self.sid = headers[PP_HTTP_PINPOINT_SPANID]
        elif PP_HEADER_PINPOINT_SPANID in headers:
            self.sid = headers[PP_HEADER_PINPOINT_SPANID]
        else:
            self.sid = generateSid()
        pinpointPy.set_context_key(PP_SPAN_ID, self.sid)

        if PP_HTTP_PINPOINT_TRACEID in headers:
            self.tid = headers[PP_HTTP_PINPOINT_TRACEID]
        elif PP_HEADER_PINPOINT_TRACEID in headers:
            self.tid = headers[PP_HEADER_PINPOINT_TRACEID]
        else:
            self.tid = generateTid()
        pinpointPy.set_context_key(PP_TRANSCATION_ID, self.tid)

        if PP_HTTP_PINPOINT_PAPPNAME in headers:
            self.pname = headers[PP_HTTP_PINPOINT_PAPPNAME]
            pinpointPy.set_context_key(PP_PARENT_NAME, self.pname)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname)

        if PP_HTTP_PINPOINT_PAPPTYPE in headers:
            self.ptype = headers[PP_HTTP_PINPOINT_PAPPTYPE]
            pinpointPy.set_context_key(PP_PARENT_TYPE, self.ptype)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype)

        if PP_HTTP_PINPOINT_HOST in headers:
            self.Ah = headers[PP_HTTP_PINPOINT_HOST]
            pinpointPy.set_context_key(PP_PARENT_HOST, self.Ah)
            pinpointPy.add_clue(PP_PARENT_HOST, self.Ah)

        if PP_HTTP_PINPOINT_PSPANID in headers:
            pinpointPy.add_clue(PP_PARENT_SPAN_ID,
                                headers[PP_HTTP_PINPOINT_PSPANID])

        if PP_HEADER_PINPOINT_PAPPNAME in headers:
            self.pname = headers[PP_HEADER_PINPOINT_PAPPNAME]
            pinpointPy.set_context_key(PP_PARENT_NAME, self.pname)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname)

        if PP_HEADER_PINPOINT_PAPPTYPE in headers:
            self.ptype = headers[PP_HEADER_PINPOINT_PAPPTYPE]
            pinpointPy.set_context_key(PP_PARENT_TYPE, self.ptype)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype)

        if PP_HEADER_PINPOINT_HOST in headers:
            self.Ah = headers[PP_HEADER_PINPOINT_HOST]
            pinpointPy.set_context_key(PP_PARENT_HOST, self.Ah)
            pinpointPy.add_clue(PP_PARENT_HOST, self.Ah)

        if PP_NGINX_PROXY in headers:
            pinpointPy.add_clue(PP_APACHE_PROXY, headers[PP_NGINX_PROXY])

        if PP_APACHE_PROXY in headers:
            pinpointPy.add_clue(PP_APACHE_PROXY, headers[PP_APACHE_PROXY])

        pinpointPy.set_context_key(PP_HEADER_PINPOINT_SAMPLED, "s1")
        if (PP_HTTP_PINPOINT_SAMPLED in headers
                and headers[PP_HTTP_PINPOINT_SAMPLED]
                == PP_NOT_SAMPLED) or pinpointPy.check_tracelimit():
            pinpointPy.drop_trace()
            pinpointPy.set_context_key(PP_HEADER_PINPOINT_SAMPLED, "s0")

        pinpointPy.add_clue(PP_TRANSCATION_ID, self.tid)
        pinpointPy.add_clue(PP_SPAN_ID, self.sid)
        pinpointPy.set_context_key(PP_TRANSCATION_ID, self.tid)
        pinpointPy.set_context_key(PP_SPAN_ID, self.sid)
        pinpointPy.add_clues(PP_HTTP_METHOD, headers["REQUEST_METHOD"])

        ###############################################################
        return args, kwargs
Example #13
0
def startPinpointByEnviron(environ):
    pinpointPy.add_clue(PP_APP_NAME, APP_NAME)
    pinpointPy.add_clue(PP_APP_ID, APP_ID)
    ###############################################################
    # print("------------------- call before -----------------------")
    pinpointPy.add_clue(PP_INTERCEPTOR_NAME, 'WSGI handle')

    path, remote_addr, host = environ['PATH_INFO'], environ[
        'REMOTE_ADDR'], environ['HTTP_HOST']

    pinpointPy.add_clue(PP_REQ_URI, path)
    pinpointPy.add_clue(PP_REQ_CLIENT, remote_addr)
    pinpointPy.add_clue(PP_REQ_SERVER, host)
    pinpointPy.add_clue(PP_SERVER_TYPE, PYTHON)

    # nginx add http
    if PP_HTTP_PINPOINT_PSPANID in environ:
        pinpointPy.add_clue(PP_PARENT_SPAN_ID,
                            environ[PP_HTTP_PINPOINT_PSPANID])

    if PP_HTTP_PINPOINT_SPANID in environ:
        sid = environ[PP_HTTP_PINPOINT_SPANID]
    elif PP_HEADER_PINPOINT_SPANID in environ:
        sid = environ[PP_HEADER_PINPOINT_SPANID]
    else:
        sid = generateSid()

    if PP_HTTP_PINPOINT_TRACEID in environ:
        tid = environ[PP_HTTP_PINPOINT_TRACEID]
    elif PP_HEADER_PINPOINT_TRACEID in environ:
        tid = environ[PP_HEADER_PINPOINT_TRACEID]
    else:
        tid = generateTid()

    if PP_HTTP_PINPOINT_PAPPNAME in environ:
        pname = environ[PP_HTTP_PINPOINT_PAPPNAME]
        pinpointPy.set_context_key(PP_PARENT_NAME, pname)
        pinpointPy.add_clue(PP_PARENT_NAME, pname)

    if PP_HTTP_PINPOINT_PAPPTYPE in environ:
        ptype = environ[PP_HTTP_PINPOINT_PAPPTYPE]
        pinpointPy.set_context_key(PP_PARENT_TYPE, ptype)
        pinpointPy.add_clue(PP_PARENT_TYPE, ptype)

    if PP_HTTP_PINPOINT_HOST in environ:
        Ah = environ[PP_HTTP_PINPOINT_HOST]
        pinpointPy.set_context_key(PP_PARENT_HOST, Ah)
        pinpointPy.add_clue(PP_PARENT_HOST, Ah)

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

    if PP_HEADER_PINPOINT_PAPPNAME in environ:
        pname = environ[PP_HEADER_PINPOINT_PAPPNAME]
        pinpointPy.set_context_key(PP_PARENT_NAME, pname)
        pinpointPy.add_clue(PP_PARENT_NAME, pname)

    if PP_HEADER_PINPOINT_PAPPTYPE in environ:
        ptype = environ[PP_HEADER_PINPOINT_PAPPTYPE]
        pinpointPy.set_context_key(PP_PARENT_TYPE, ptype)
        pinpointPy.add_clue(PP_PARENT_TYPE, ptype)

    if PP_HEADER_PINPOINT_HOST in environ:
        Ah = environ[PP_HEADER_PINPOINT_HOST]
        pinpointPy.set_context_key(PP_PARENT_HOST, Ah)
        pinpointPy.add_clue(PP_PARENT_HOST, Ah)

    if PP_NGINX_PROXY in environ:
        pinpointPy.add_clue(PP_NGINX_PROXY, environ[PP_NGINX_PROXY])

    if PP_APACHE_PROXY in environ:
        pinpointPy.add_clue(PP_APACHE_PROXY, environ[PP_APACHE_PROXY])

    pinpointPy.set_context_key("Pinpoint-Sampled", "s1")
    if (PP_HTTP_SAMPLED in environ and environ[PP_HTTP_SAMPLED]
            == PP_NOT_SAMPLED) or pinpointPy.check_tracelimit():
        if environ[PP_HTTP_SAMPLED] == PP_NOT_SAMPLED:
            pinpointPy.drop_trace()
            pinpointPy.set_context_key("Pinpoint-Sampled", "s0")

    pinpointPy.add_clue(PP_TRANSCATION_ID, tid)
    pinpointPy.add_clue(PP_SPAN_ID, sid)
    pinpointPy.set_context_key(PP_TRANSCATION_ID, tid)
    pinpointPy.set_context_key(PP_SPAN_ID, sid)
Example #14
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
Example #15
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[0]
        ###############################################################
        # print("------------------- call before -----------------------")
        pinpointPy.add_clue(PP_INTERCEPTOR_NAME, 'BaseFlaskrequest')
        pinpointPy.add_clue(PP_REQ_URI, request.path)
        pinpointPy.add_clue(PP_REQ_CLIENT, request.remote_addr)
        pinpointPy.add_clue(PP_REQ_SERVER, request.host)
        pinpointPy.add_clue(PP_SERVER_TYPE, PYTHON)

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

        if PP_HTTP_PINPOINT_SPANID in request.headers:
            self.sid = request.headers[PP_HTTP_PINPOINT_SPANID]
        elif PP_HEADER_PINPOINT_SPANID in request.headers:
            self.sid = request.headers[PP_HEADER_PINPOINT_SPANID]
        else:
            self.sid = generateSid()
        pinpointPy.set_context_key(PP_SPAN_ID, self.sid)

        if PP_HTTP_PINPOINT_TRACEID in request.headers:
            self.tid = request.headers[PP_HTTP_PINPOINT_TRACEID]
        elif PP_HEADER_PINPOINT_TRACEID in request.headers:
            self.tid = request.headers[PP_HEADER_PINPOINT_TRACEID]
        else:
            self.tid = generateTid()
        pinpointPy.set_context_key(PP_TRANSCATION_ID, self.tid)

        if PP_HTTP_PINPOINT_PAPPNAME in request.headers:
            self.pname = request.headers[PP_HTTP_PINPOINT_PAPPNAME]
            pinpointPy.set_context_key(PP_PARENT_NAME, self.pname)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname)

        if PP_HTTP_PINPOINT_PAPPTYPE in request.headers:
            self.ptype = request.headers[PP_HTTP_PINPOINT_PAPPTYPE]
            pinpointPy.set_context_key(PP_PARENT_TYPE, self.ptype)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype)

        if PP_HTTP_PINPOINT_HOST in request.headers:
            self.Ah = request.headers[PP_HTTP_PINPOINT_HOST]
            pinpointPy.set_context_key(PP_PARENT_HOST, self.Ah)
            pinpointPy.add_clue(PP_PARENT_HOST, self.Ah)

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

        if PP_HEADER_PINPOINT_PAPPNAME in request.headers:
            self.pname = request.headers[PP_HEADER_PINPOINT_PAPPNAME]
            pinpointPy.set_context_key(PP_PARENT_NAME, self.pname)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname)

        if PP_HEADER_PINPOINT_PAPPTYPE in request.headers:
            self.ptype = request.headers[PP_HEADER_PINPOINT_PAPPTYPE]
            pinpointPy.set_context_key(PP_PARENT_TYPE, self.ptype)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype)

        if PP_HEADER_PINPOINT_HOST in request.headers:
            self.Ah = request.headers[PP_HEADER_PINPOINT_HOST]
            pinpointPy.set_context_key(PP_PARENT_HOST, self.Ah)
            pinpointPy.add_clue(PP_PARENT_HOST, self.Ah)

        if PP_NGINX_PROXY in request.headers:
            pinpointPy.add_clue(PP_NGINX_PROXY, request.headers[PP_NGINX_PROXY])

        if PP_APACHE_PROXY in request.headers:
            pinpointPy.add_clue(PP_APACHE_PROXY, request.headers[PP_APACHE_PROXY])

        pinpointPy.set_context_key(PP_HEADER_PINPOINT_SAMPLED, "s1")
        if (PP_HTTP_PINPOINT_SAMPLED in request.headers and request.headers[PP_HTTP_PINPOINT_SAMPLED] == PP_NOT_SAMPLED) or pinpointPy.check_tracelimit():
            pinpointPy.drop_trace()
            pinpointPy.set_context_key(PP_HEADER_PINPOINT_SAMPLED, "s0")

        pinpointPy.add_clue(PP_TRANSCATION_ID, self.tid)
        pinpointPy.add_clue(PP_SPAN_ID, self.sid)
        pinpointPy.set_context_key(PP_TRANSCATION_ID, self.tid)
        pinpointPy.set_context_key(PP_SPAN_ID, self.sid)
        return args, kwargs
Example #16
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):
        super().onBefore(*args, **kwargs)
        pinpointPy.add_clue(PP_APP_NAME, APP_NAME, self.traceId)
        pinpointPy.add_clue(PP_APP_ID, APP_ID, self.traceId)
        ###############################################################
        request = args[0]
        # pinpointPy.add_clue(PP_INTERCEPTOR_NAME, 'tornado.web.RequestHandler',self.node_id)
        # pinpointPy.add_clue(PP_REQ_URI, request.uri, self.traceId)
        # pinpointPy.add_clue(PP_REQ_CLIENT, request.remote_ip, self.traceId)
        # pinpointPy.add_clue(PP_REQ_SERVER, request.host_name, self.traceId)
        pinpointPy.add_clue(PP_SERVER_TYPE, PYTHON, self.traceId)

        # nginx add http
        if PP_HTTP_PINPOINT_PSPANID in request.headers:
            pinpointPy.add_clue(PP_PARENT_SPAN_ID,
                                request.headers[PP_HTTP_PINPOINT_PSPANID],
                                self.traceId)
        if PP_HTTP_PINPOINT_SPANID in request.headers:
            self.sid = request.headers[PP_HTTP_PINPOINT_SPANID]
        elif PP_HEADER_PINPOINT_SPANID in request.headers:
            self.sid = request.headers[PP_HEADER_PINPOINT_SPANID]
        else:
            self.sid = generateSid()
        pinpointPy.set_context_key(PP_SPAN_ID, self.sid, self.traceId)

        if PP_HTTP_PINPOINT_TRACEID in request.headers:
            self.tid = request.headers[PP_HTTP_PINPOINT_TRACEID]
        elif PP_HEADER_PINPOINT_TRACEID in request.headers:
            self.tid = request.headers[PP_HEADER_PINPOINT_TRACEID]
        else:
            self.tid = generateTid()
        pinpointPy.set_context_key(PP_TRANSCATION_ID, self.tid, self.traceId)

        if PP_HTTP_PINPOINT_PAPPNAME in request.headers:
            self.pname = request.headers[PP_HTTP_PINPOINT_PAPPNAME]
            pinpointPy.set_context_key(PP_PARENT_NAME, self.pname,
                                       self.traceId)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname, self.traceId)

        if PP_HTTP_PINPOINT_PAPPTYPE in request.headers:
            self.ptype = request.headers[PP_HTTP_PINPOINT_PAPPTYPE]
            pinpointPy.set_context_key(PP_PARENT_TYPE, self.ptype,
                                       self.traceId)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype, self.traceId)

        if PP_HTTP_PINPOINT_HOST in request.headers:
            self.Ah = request.headers[PP_HTTP_PINPOINT_HOST]
            pinpointPy.set_context_key(PP_PARENT_HOST, self.Ah, self.traceId)
            pinpointPy.add_clue(PP_PARENT_HOST, self.Ah, self.traceId)

        # Not nginx, no http
        if PP_HEADER_PINPOINT_PSPANID in request.headers:
            pinpointPy.add_clue(PP_PARENT_SPAN_ID,
                                request.headers[PP_HEADER_PINPOINT_PSPANID],
                                self.traceId)

        if PP_HEADER_PINPOINT_PAPPNAME in request.headers:
            self.pname = request.headers[PP_HEADER_PINPOINT_PAPPNAME]
            pinpointPy.set_context_key(PP_PARENT_NAME, self.pname,
                                       self.traceId)
            pinpointPy.add_clue(PP_PARENT_NAME, self.pname, self.traceId)

        if PP_HEADER_PINPOINT_PAPPTYPE in request.headers:
            self.ptype = request.headers[PP_HEADER_PINPOINT_PAPPTYPE]
            pinpointPy.set_context_key(PP_PARENT_TYPE, self.ptype,
                                       self.traceId)
            pinpointPy.add_clue(PP_PARENT_TYPE, self.ptype, self.traceId)

        if PP_HEADER_PINPOINT_HOST in request.headers:
            self.Ah = request.headers[PP_HEADER_PINPOINT_HOST]
            pinpointPy.set_context_key(PP_PARENT_HOST, self.Ah, self.traceId)
            pinpointPy.add_clue(PP_PARENT_HOST, self.Ah, self.traceId)

        if PP_NGINX_PROXY in request.headers:
            pinpointPy.add_clue(PP_NGINX_PROXY,
                                request.headers[PP_NGINX_PROXY], self.traceId)

        if PP_APACHE_PROXY in request.headers:
            pinpointPy.add_clue(PP_APACHE_PROXY,
                                request.headers[PP_APACHE_PROXY], self.traceId)

        pinpointPy.set_context_key("Pinpoint-Sampled", "s1", self.traceId)
        if (PP_HTTP_SAMPLED in request.headers
                and request.headers[PP_HTTP_SAMPLED]
                == PP_NOT_SAMPLED) or pinpointPy.check_tracelimit():
            if request.headers[PP_HTTP_SAMPLED] == PP_NOT_SAMPLED:
                pinpointPy.drop_trace(self.traceId)
                pinpointPy.set_context_key("Pinpoint-Sampled", "s0",
                                           self.traceId)

        pinpointPy.add_clue(PP_TRANSCATION_ID, self.tid, self.traceId)
        pinpointPy.add_clue(PP_SPAN_ID, self.sid, self.traceId)
        pinpointPy.set_context_key(PP_TRANSCATION_ID, self.tid, self.traceId)
        pinpointPy.set_context_key(PP_SPAN_ID, self.sid, self.traceId)
        return args, kwargs