Ejemplo n.º 1
0
    def createSpan(self, stackMap):
        tSpan = PSpan()
        tSpan.apiId = self.agent.updateApiMeta(stackMap['name'], API_WEB_REQUEST)
        tSpan.version = 1
        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'])
        else:
            tSpan.parentSpanId = -1

        if 'tid' in stackMap:
            agentId, startTime, id = stackMap['tid'].split('^')
            tSpan.transactionId.agentId = agentId
            tSpan.transactionId.agentStartTime = int(startTime)
            tSpan.transactionId.sequence = int(id)

        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']

        accept = tSpan.acceptEvent

        if 'uri' in stackMap:
            accept.rpc = stackMap['uri']
        if 'server' in stackMap:
            accept.endPoint = stackMap['server']
        if 'client' in stackMap:
            accept.remoteAddr = stackMap['client']

        parent_info = accept.parentInfo

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

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

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

        if 'ERR' in stackMap:
            tSpan.err = 1
            id = self.agent.updateStringMeta('ERR')
            value = StringValue(value=stackMap['ERR']['msg'])
            tSpan.exceptionInfo.intValue = id
            tSpan.exceptionInfo.stringValue.CopyFrom(value)

        if 'EXP' in stackMap:
            id = self.agent.updateStringMeta('EXP')
            value = StringValue(value=stackMap['EXP'])
            tSpan.exceptionInfo.intValue = id
            tSpan.exceptionInfo.stringValue.CopyFrom(value)


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

        try:
            value = None
            if 'NP' in stackMap:  ## nginx
                value = PLongIntIntByteByteStringValue()
                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
                value = PLongIntIntByteByteStringValue()
                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)
            if value is not None:
                ann = PAnnotation(key=PROXY_HTTP_HEADER, value=PAnnotationValue(longIntIntByteByteStringValue=value))
                tSpan.annotation.append(ann)
        except Exception as e:
            TCLogger.error("input is illegal,Exception %s", e)

        return tSpan
Ejemplo n.º 2
0
    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