Exemplo n.º 1
0
    def genSpanEvent(self, span):
        '''

        :param  dict span:
        :return TSpanEvent:
        '''
        assert 'name' in span
        spanEv = TSpanEvent()

        spanEv.apiId = self.updateApiMeta(span['name']).apiId
        spanEv.annotations = []
        if 'EXP' in  span:
            id = self.updateStringMeta('EXP').apiId
            spanEv.exceptionInfo = TIntStringValue(id, span['EXP'])

        if 'dst' in  span:
            spanEv.destinationId = span['dst']

        if 'S' in  span:
            spanEv.startElapsed = span['S']

        if 'E' in span:
            spanEv.endElapsed   = span['E']

        if 'dst' in span:
            spanEv.destinationId = span['dst']

        if 'nsid' in span:
            spanEv.nextSpanId   = int(span['nsid'])

        if 'stp' in span:
            spanEv.serviceType  = int(span['stp'])
        else:
            spanEv.serviceType = PHP_METHOD_CALL

        if 'clues' in span:
            for annotation in span['clues']:  # list
                id, value = annotation.split(':', 1)

                if value and value[0] =='[': ## value is a In
                    pass
                else: ## value is a string
                    ann = TAnnotation(int(id), TAnnotationValue(stringValue=value))
                    spanEv.annotations.append(ann)

        return spanEv
Exemplo n.º 2
0
    def createSpanEvent(self, stackMap):
        assert 'name' in stackMap
        spanEv = TSpanEvent()

        spanEv.apiId = self.agent.updateApiMeta(stackMap['name']).apiId
        spanEv.annotations = []
        if 'EXP' in stackMap:
            id = self.agent.updateStringMeta('EXP').apiId
            spanEv.exceptionInfo = TIntStringValue(id, stackMap['EXP'])

        if 'dst' in stackMap:
            spanEv.destinationId = stackMap['dst']

        if 'S' in stackMap:
            spanEv.startElapsed = stackMap['S']

        if 'E' in stackMap:
            spanEv.endElapsed = stackMap['E']

        if 'dst' in stackMap:
            spanEv.destinationId = stackMap['dst']

        if 'nsid' in stackMap:
            spanEv.nextSpanId = int(stackMap['nsid'])

        if 'stp' in stackMap:
            spanEv.serviceType = int(stackMap['stp'])
        else:
            spanEv.serviceType = PHP_METHOD_CALL

        if 'clues' in stackMap:
            for annotation in stackMap['clues']:  # list
                id, value = annotation.split(':', 1)
                ann = TAnnotation(int(id), TAnnotationValue(stringValue=value))
                spanEv.annotations.append(ann)

        return spanEv
    def createSpan(self, stackMap):
        tSpan = TSpan()
        tSpan.apiId = self.agent.updateApiMeta(stackMap['name'],
                                               API_WEB_REQUEST).apiId
        tSpan.agentStartTime = self.agent.startTimeStamp

        if 'appid' in stackMap:
            tSpan.agentId = stackMap['appid']
        else:
            tSpan.agentId = self.agent.app_id

        if 'appname' in stackMap:
            tSpan.applicationName = stackMap['appname']
        else:
            tSpan.applicationName = self.agent.app_name

        if 'stp' in stackMap:
            tSpan.serviceType = int(stackMap['stp'])
            tSpan.applicationServiceType = int(stackMap['stp'])
        else:
            tSpan.serviceType = PHP
            tSpan.applicationServiceType = PHP

        if 'psid' in stackMap:
            tSpan.parentSpanId = int(stackMap['psid'])

        if 'tid' in stackMap:
            tSpan.transactionId = TransactionId(
                encoded_str=stackMap['tid']).getBytes()

        if 'sid' in stackMap:
            tSpan.spanId = int(stackMap['sid'])

        if 'S' in stackMap:
            tSpan.startTime = stackMap['S']

        if 'E' in stackMap:
            tSpan.elapsed = stackMap['E']

        if 'uri' in stackMap:
            tSpan.rpc = stackMap['uri']

        if 'pname' in stackMap:
            tSpan.parentApplicationName = stackMap['pname']

        if 'ptype' in stackMap:
            tSpan.parentApplicationType = int(stackMap['ptype'])

        if 'client' in stackMap:
            tSpan.remoteAddr = stackMap['client']

        if 'server' in stackMap:
            tSpan.endPoint = stackMap['server']

        if 'ERR' in stackMap:
            tSpan.err = 1
            id = self.agent.updateStringMeta('ERR').apiId
            tSpan.exceptionInfo = TIntStringValue(id, stackMap['ERR']['msg'])

        if 'Ah' in stackMap:
            tSpan.acceptorHost = stackMap['Ah']

        tSpan.spanEventList = []
        tSpan.annotations = []

        if 'clues' in stackMap:
            for annotation in stackMap['clues']:  # list
                id, value = annotation.split(':', 1)
                ann = TAnnotation(int(id), TAnnotationValue(stringValue=value))
                tSpan.annotations.append(ann)

        try:
            value = TLongIntIntByteByteStringValue()
            if 'NP' in stackMap:  ## nginx
                arr = ThriftProtocolUtil._parseStrField(stackMap['NP'])
                value.intValue1 = 2
                if 'D' in arr:
                    value.intValue2 = ThriftProtocolUtil._parseDotFormat(
                        arr['D'])
                if 't' in arr:
                    value.longValue = ThriftProtocolUtil._parseDotFormat(
                        arr['t'])
            elif 'AP' in stackMap:  ## apache
                arr = ThriftProtocolUtil._parseStrField(stackMap['AP'])
                value.intValue1 = 3
                if 'i' in arr:
                    value.byteValue1 = int(arr['i'])
                if 'b' in arr:
                    value.byteValue2 = int(arr['b'])
                if 'D' in arr:
                    value.intValue2 = int(arr['D'])
                if 't' in arr:
                    value.longValue = int(int(arr['t']) / 1000)
            ann = TAnnotation(
                PROXY_HTTP_HEADER,
                TAnnotationValue(longIntIntByteByteStringValue=value))
            tSpan.annotations.append(ann)
        except Exception as e:
            TCLogger.error("input is illegal,Exception %s", e)

        return tSpan