コード例 #1
0
ファイル: __init__.py プロジェクト: taskmgr/skywalking-python
def install():
    disable_patterns = config.disable_plugins
    if isinstance(disable_patterns, str):
        disable_patterns = [re.compile(p.strip()) for p in disable_patterns.split(',') if p.strip()]
    else:
        disable_patterns = [re.compile(p.strip()) for p in disable_patterns if p.strip()]
    for importer, modname, ispkg in pkgutil.iter_modules(skywalking.plugins.__path__):
        if any(pattern.match(modname) for pattern in disable_patterns):
            logger.info('plugin %s is disabled and thus won\'t be installed', modname)
            continue
        logger.debug('installing plugin %s', modname)
        plugin = importer.find_module(modname).load_module(modname)

        supported = pkg_version_check(plugin)
        if not supported:
            logger.debug('check version for plugin %s\'s corresponding package failed, thus '
                         'won\'t be installed', modname)
            continue

        if not hasattr(plugin, 'install') or inspect.ismethod(getattr(plugin, 'install')):
            logger.warning('no `install` method in plugin %s, thus the plugin won\'t be installed', modname)
            continue

        # noinspection PyBroadException
        try:
            plugin.install()
        except Exception:
            logger.warning('failed to install plugin %s', modname)
            traceback.print_exc() if logger.isEnabledFor(logging.DEBUG) else None
コード例 #2
0
def start():
    global __started
    if __started:
        return
    __started = True

    flag = False
    try:
        from gevent import monkey
        flag = monkey.is_module_patched("socket")
    except ModuleNotFoundError:
        logger.debug(
            "it was found that no gevent was used, if you don't use, please ignore."
        )
    if flag:
        import grpc.experimental.gevent as grpc_gevent
        grpc_gevent.init_gevent()

    loggings.init()
    config.finalize()

    __init()

    atexit.register(__fini)

    if (hasattr(os, 'register_at_fork')):
        os.register_at_fork(before=__fork_before,
                            after_in_parent=__fork_after_in_parent,
                            after_in_child=__fork_after_in_child)
コード例 #3
0
        def generator():
            while True:
                segment = queue.get()  # type: Segment

                logger.debug('reporting segment %s', segment)

                s = SegmentObject(
                    traceId=str(segment.related_traces[0]),
                    traceSegmentId=str(segment.segment_id),
                    service=config.service_name,
                    serviceInstance=config.service_instance,
                    spans=[
                        SpanObject(
                            spanId=span.sid,
                            parentSpanId=span.pid,
                            startTime=span.start_time,
                            endTime=span.end_time,
                            operationName=span.op,
                            peer=span.peer,
                            spanType=span.kind.name,
                            spanLayer=span.layer.name,
                            componentId=span.component.value,
                            isError=span.error_occurred,
                            logs=[
                                Log(
                                    time=int(log.timestamp * 1000),
                                    data=[
                                        KeyStringValuePair(key=item.key,
                                                           value=item.val)
                                        for item in log.items
                                    ],
                                ) for log in span.logs
                            ],
                            tags=[
                                KeyStringValuePair(
                                    key=str(tag.key),
                                    value=str(tag.val),
                                ) for tag in span.tags
                            ],
                            refs=[
                                SegmentReference(
                                    refType=0
                                    if ref.ref_type == "CrossProcess" else 1,
                                    traceId=ref.trace_id,
                                    parentTraceSegmentId=ref.segment_id,
                                    parentSpanId=ref.span_id,
                                    parentService=ref.service,
                                    parentServiceInstance=ref.service_instance,
                                    parentEndpoint=ref.endpoint,
                                    networkAddressUsedAtPeer=ref.
                                    client_address,
                                ) for ref in span.refs if ref.trace_id
                            ],
                        ) for span in segment.spans
                    ],
                )

                yield s

                queue.task_done()
コード例 #4
0
ファイル: kafka.py プロジェクト: taskmgr/skywalking-python
    def __init__(self):
        logger.debug("kafka reporter configs: %s", kafka_configs)
        self.producer = KafkaProducer(**kafka_configs)
        self.topic_key_register = "register-"
        self.topic = config.kafka_topic_management

        self.send_instance_props()
コード例 #5
0
        def generator():
            while True:
                segment = queue.get()  # type: Segment

                logger.debug('reporting segment %s', segment)

                yield segment

                queue.task_done()
コード例 #6
0
ファイル: grpc.py プロジェクト: apache/skywalking-python
 def _cb(self, state):
     logger.debug('grpc channel connectivity changed, [%s -> %s]',
                  self.state, state)
     self.state = state
     if self.connected():
         try:
             self.service_management.send_instance_props()
         except grpc.RpcError:
             self.on_error()
コード例 #7
0
ファイル: http.py プロジェクト: apache/skywalking-python
 def send_instance_props(self):
     res = self.session.post(self.url_instance_props,
                             json={
                                 'service': config.service_name,
                                 'serviceInstance': config.service_instance,
                                 'properties': [{
                                     'language': 'Python',
                                 }]
                             })
     logger.debug('heartbeat response: %s', res)
コード例 #8
0
ファイル: grpc.py プロジェクト: taskmgr/skywalking-python
 def send_heart_beat(self):
     logger.debug(
         'service heart beats, [%s], [%s]',
         config.service_name,
         config.service_instance,
     )
     self.service_stub.keepAlive(
         InstancePingPkg(
             service=config.service_name,
             serviceInstance=config.service_instance,
         ))
コード例 #9
0
ファイル: http.py プロジェクト: apache/skywalking-python
 def send_heart_beat(self):
     logger.debug(
         'service heart beats, [%s], [%s]',
         config.service_name,
         config.service_instance,
     )
     res = self.session.post(self.url_heart_beat,
                             json={
                                 'service': config.service_name,
                                 'serviceInstance': config.service_instance,
                             })
     logger.debug('heartbeat response: %s', res)
コード例 #10
0
ファイル: http.py プロジェクト: taskmgr/skywalking-python
 def send_instance_props(self):
     url = config.collector_address.rstrip(
         '/') + '/v3/management/reportProperties'
     res = self.session.post(url,
                             json={
                                 'service': config.service_name,
                                 'serviceInstance': config.service_instance,
                                 'properties': [{
                                     'language': 'Python',
                                 }]
                             })
     logger.debug('heartbeat response: %s', res)
コード例 #11
0
        def generator():
            while True:
                try:
                    segment = queue.get(block=block)  # type: Segment
                except Empty:
                    return

                logger.debug('reporting segment %s', segment)

                yield segment

                queue.task_done()
コード例 #12
0
ファイル: http.py プロジェクト: taskmgr/skywalking-python
 def send_heart_beat(self):
     logger.debug(
         'service heart beats, [%s], [%s]',
         config.service_name,
         config.service_instance,
     )
     url = config.collector_address.rstrip('/') + '/v3/management/keepAlive'
     res = self.session.post(url,
                             json={
                                 'service': config.service_name,
                                 'serviceInstance': config.service_instance,
                             })
     logger.debug('heartbeat response: %s', res)
コード例 #13
0
        def generator():
            while True:
                try:
                    timeout = max(0, config.QUEUE_TIMEOUT -
                                  int(time() - start))  # type: int
                    segment = queue.get(block=block,
                                        timeout=timeout)  # type: Segment
                except Empty:
                    return

                logger.debug('reporting segment %s', segment)

                yield segment

                queue.task_done()
コード例 #14
0
    def execute(self, command: ProfileTaskCommand):
        logger.debug(
            "ProfileTaskCommandExecutor start execute ProfileTaskCommand [{%s}]",
            command.serial_number)

        profile_task = ProfileTask(
            task_id=command.task_id,
            first_span_op_name=command.endpoint_name,
            duration=command.duration,
            min_duration_threshold=command.min_duration_threshold,
            thread_dump_period=command.dump_period,
            max_sampling_count=command.max_sampling_count,
            start_time=command.start_time,
            create_time=command.create_time)

        profile_task_execution_service.add_profile_task(profile_task)
コード例 #15
0
ファイル: kafka.py プロジェクト: taskmgr/skywalking-python
    def send_heart_beat(self):
        logger.debug(
            'service heart beats, [%s], [%s]',
            config.service_name,
            config.service_instance,
        )

        instance_ping_pkg = InstancePingPkg(
            service=config.service_name,
            serviceInstance=config.service_instance,
        )

        key = bytes(instance_ping_pkg.serviceInstance, encoding="utf-8")
        value = bytes(instance_ping_pkg.SerializeToString())
        future = self.producer.send(topic=self.topic, key=key, value=value)
        res = future.get(timeout=10)
        logger.debug('heartbeat response: %s', res)
コード例 #16
0
    def receive_command(self, commands: Commands):
        for command in commands.commands:
            try:
                base_command = CommandDeserializer.deserialize(command)
                logger.debug("Received command [{%s} {%s}]", base_command.command, base_command.serial_number)

                if self.__is_command_executed(base_command):
                    logger.warning("Command[{%s}] is executed, ignored.", base_command.command)
                    continue

                try:
                    self.__commands.put(base_command)
                except queue.Full:
                    logger.warning("Command[{%s}, {%s}] cannot add to command list. because the command list is full.",
                                   base_command.command, base_command.serial_number)
            except UnsupportedCommandException as e:
                logger.warning("Received unsupported command[{%s}].", e.command.command)
コード例 #17
0
def start():
    flag = False
    try:
        from gevent import monkey
        flag = monkey.is_module_patched("socket")
    except ModuleNotFoundError:
        logger.debug(
            "it was found that no gevent was used, if you don't use, please ignore."
        )
    if flag:
        import grpc.experimental.gevent as grpc_gevent
        grpc_gevent.init_gevent()
    global __started
    if __started:
        raise RuntimeError('the agent can only be started once')
    loggings.init()
    config.finalize()
    __started = True
    __init()
    __heartbeat_thread.start()
    __report_thread.start()
    atexit.register(__fini)
コード例 #18
0
ファイル: grpc.py プロジェクト: apache/skywalking-python
 def query_profile_commands(self):
     logger.debug("query profile commands")
     self.profile_query.do_query()
コード例 #19
0
ファイル: http.py プロジェクト: apache/skywalking-python
 def report(self, generator):
     for segment in generator:
         res = self.session.post(self.url_report,
                                 json={
                                     'traceId':
                                     str(segment.related_traces[0]),
                                     'traceSegmentId':
                                     str(segment.segment_id),
                                     'service':
                                     config.service_name,
                                     'serviceInstance':
                                     config.service_instance,
                                     'spans': [{
                                         'spanId':
                                         span.sid,
                                         'parentSpanId':
                                         span.pid,
                                         'startTime':
                                         span.start_time,
                                         'endTime':
                                         span.end_time,
                                         'operationName':
                                         span.op,
                                         'peer':
                                         span.peer,
                                         'spanType':
                                         span.kind.name,
                                         'spanLayer':
                                         span.layer.name,
                                         'componentId':
                                         span.component.value,
                                         'isError':
                                         span.error_occurred,
                                         'logs': [{
                                             'time':
                                             int(log.timestamp * 1000),
                                             'data': [{
                                                 'key': item.key,
                                                 'value': item.val,
                                             } for item in log.items],
                                         } for log in span.logs],
                                         'tags': [{
                                             'key': tag.key,
                                             'value': tag.val,
                                         } for tag in span.tags],
                                         'refs': [{
                                             'refType':
                                             0,
                                             'traceId':
                                             ref.trace_id,
                                             'parentTraceSegmentId':
                                             ref.segment_id,
                                             'parentSpanId':
                                             ref.span_id,
                                             'parentService':
                                             ref.service,
                                             'parentServiceInstance':
                                             ref.service_instance,
                                             'parentEndpoint':
                                             ref.endpoint,
                                             'networkAddressUsedAtPeer':
                                             ref.client_address,
                                         } for ref in span.refs
                                                  if ref.trace_id]
                                     } for span in segment.spans]
                                 })
         logger.debug('report traces response: %s', res)