示例#1
0
def generatePPRabbitMqHeader(func,headers):

    if pinpointPy.check_tracelimit():
        headers[PP_HEADER_PINPOINT_SAMPLED] = PP_NOT_SAMPLED
        return
    else:
        headers[PP_HEADER_PINPOINT_SAMPLED] = PP_SAMPLED
    headers[PP_HEADER_PINPOINT_PAPPTYPE] = pinpointPy.get_context_key(PP_SERVER_TYPE)
    headers[PP_HEADER_PINPOINT_PAPPNAME] = pinpointPy.get_context_key(PP_APP_NAME)
    headers['Pinpoint-Flags'] = "0"
    headers[PP_HEADER_PINPOINT_HOST] = func
    headers[PP_HEADER_PINPOINT_CLIENT] = local_ip
    headers[PP_HEADER_PINPOINT_TRACEID] = pinpointPy.get_context_key(PP_TRANSCATION_ID)
    headers[PP_HEADER_PINPOINT_PSPANID] = pinpointPy.get_context_key(PP_SPAN_ID)
    headers[PP_HEADER_PINPOINT_SPANID] = pinpointPy.get_context_key(PP_NEXT_SPAN_ID)
示例#2
0
def generatePinpointHeader(host, headers):
    headers[PP_HEADER_PINPOINT_SAMPLED] = PP_SAMPLED
    headers[PP_HEADER_PINPOINT_PAPPTYPE] = pinpointPy.get_context_key(
        PP_SERVER_TYPE)
    headers[PP_HEADER_PINPOINT_PAPPNAME] = pinpointPy.get_context_key(
        PP_APP_NAME)
    headers['Pinpoint-Flags'] = "0"
    headers[PP_HEADER_PINPOINT_HOST] = host
    headers[PP_HEADER_PINPOINT_TRACEID] = pinpointPy.get_context_key(
        PP_TRANSCATION_ID)
    headers[PP_HEADER_PINPOINT_PSPANID] = pinpointPy.get_context_key(
        PP_SPAN_ID)
    nsid = generateSid()
    pinpointPy.set_context_key(PP_NEXT_SPAN_ID, nsid)
    headers[PP_HEADER_PINPOINT_SPANID] = nsid
    def test_trace_life(self):
        self.assertFalse(pinpointPy.trace_has_root())
        pinpointPy.start_trace()
        self.assertTrue(pinpointPy.trace_has_root())
        pinpointPy.start_trace()
        self.assertTrue(pinpointPy.trace_has_root())
        pinpointPy.start_trace()
        pinpointPy.start_trace()
        # self.assertRaises(Exception,lambda: pinpointPy.trace_has_root(1025))
        # self.assertRaises(Exception,lambda: pinpointPy.trace_has_root(-1025))

        pinpointPy.add_clue("key", "value")
        pinpointPy.add_clue("key", "value3")
        pinpointPy.set_context_key('sid', '12345')
        value = pinpointPy.get_context_key('sid')
        self.assertEqual(value, '12345')
        pinpointPy.add_clues("key", "values")
        pinpointPy.add_clues("key", "values")
        pinpointPy.add_clues("key", "values")

        pinpointPy.end_trace()
        pinpointPy.end_trace()
        pinpointPy.end_trace()
        pinpointPy.end_trace()
        pinpointPy.force_flush_trace(10)
        self.assertFalse(pinpointPy.trace_has_root())
    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)
示例#5
0
def generatePinpointHeader(url, headers):

    if pinpointPy.check_tracelimit():
        headers[PP_HEADER_PINPOINT_SAMPLED] = PP_NOT_SAMPLED
        return
    else:
        headers[PP_HEADER_PINPOINT_SAMPLED] = PP_SAMPLED
    headers[PP_HEADER_PINPOINT_PAPPTYPE] = PYTHON
    headers[PP_HEADER_PINPOINT_PAPPNAME] = APP_NAME
    headers['Pinpoint-Flags'] = "0"
    headers[PP_HEADER_PINPOINT_HOST] = urlparse(url).netloc
    headers[PP_HEADER_PINPOINT_TRACEID] = pinpointPy.get_context_key(
        PP_TRANSCATION_ID)
    headers[PP_HEADER_PINPOINT_PSPANID] = pinpointPy.get_context_key(
        PP_SPAN_ID)
    nsid = generateSid()
    pinpointPy.set_context_key(PP_NEXT_SPAN_ID, nsid)
    headers[PP_HEADER_PINPOINT_SPANID] = nsid
 def onEnd(self, ret):
     ###############################################################
     pinpointPy.add_clue(PP_NEXT_SPAN_ID,
                         pinpointPy.get_context_key(PP_NEXT_SPAN_ID))
     pinpointPy.add_clues(PP_HTTP_STATUS_CODE, str(ret.status_code))
     pinpointPy.add_clues(PP_RETURN, str(ret))
     ###############################################################
     super().onEnd(ret)
     return ret
示例#7
0
 def isSample(self, args):
     '''
     if not root, no trace
     :return:
     '''
     if pinpointPy.trace_has_root() and pinpointPy.get_context_key(
             PP_HEADER_PINPOINT_SAMPLED) == "s1":
         return True
     else:
         return False
示例#8
0
 def onEnd(self,ret):
     ###############################################################
     pinpointPy.add_clue(PP_DESTINATION, urlparse(self.url)['netloc'])
     pinpointPy.add_clue(PP_SERVER_TYPE, PP_REMOTE_METHOD)
     pinpointPy.add_clue(PP_NEXT_SPAN_ID, pinpointPy.get_context_key(PP_NEXT_SPAN_ID))
     pinpointPy.add_clues(PP_HTTP_URL, self.url)
     pinpointPy.add_clues(PP_HTTP_STATUS_CODE, str(ret.status_code))
     pinpointPy.add_clues(PP_RETURN, str(ret))
     ###############################################################
     super(UrlOpenPlugin,self).onEnd(ret)
     return ret
示例#9
0
            async def pinpoint_trace(*args, **kwargs):
                id = pinpointId.get()
                id = pinpointPy.start_trace(id)
                pinpointId.set(id)
                func_name = func.__name__
                pinpointPy.add_clue('name', func_name, id, 0)
                pinpointPy.add_clues('start', '3434', id)
                pinpointPy.set_context_key('sid', '12345', id)
                value = pinpointPy.get_context_key('sid', id)
                self.assertEqual(value, '12345')

                ret = await func(*args, **kwargs)
                pinpointPy.add_clue('end', '3434', id)
                id = pinpointPy.end_trace(id)
 def isSample(self, args):
     '''
     if not root, no trace
     :return:
     '''
     url = args[0][0]
     target = urlparse(url).netloc
     kwargs = args[1]
     if "headers" not in kwargs:
         kwargs["headers"] = {}
     if pinpointPy.get_context_key(PP_HEADER_PINPOINT_SAMPLED) == "s1":
         generatePinpointHeader(target, kwargs['headers'])
         return True
     else:
         kwargs['headers'][PP_HEADER_PINPOINT_SAMPLED] = PP_NOT_SAMPLED
         return False
示例#11
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()
示例#12
0
    def test_trace_life(self):
        pinpointPy.start_trace()
        pinpointPy.start_trace()
        pinpointPy.start_trace()
        pinpointPy.start_trace()
        pinpointPy.add_clue("key", "value")
        pinpointPy.add_clue("key", "value3")
        pinpointPy.set_context_key('sid', '12345')
        value = pinpointPy.get_context_key('sid')
        self.assertEqual(value, '12345')
        pinpointPy.add_clues("key", "values")
        pinpointPy.add_clues("key", "values")
        pinpointPy.add_clues("key", "values")

        pinpointPy.end_trace()
        pinpointPy.end_trace()
        pinpointPy.end_trace()
        pinpointPy.end_trace()
        pinpointPy.force_flush_trace(10)