Exemplo n.º 1
0
    def log(self, log_statement, payload=None, level=None, span_guid=None):
        """ Record a log statement with optional payload and importance level.

            :param str logStatement: log text
            :param payload: an string, int, object, etc. whose serialization
                will be sent to the server
            :param str span_guid: associate the log with a specifc span
                operation by providing a span_guid
            :param char level: for internal use only
                importance level of log - 'I' info, 'W' warning, 'E' error,
                'F' fatal
        """
        if self._disabled_runtime:
            return
        timestamp = util._now_micros()
        guid = self._runtime.guid
        log_record = ttypes.LogRecord(timestamp, guid, message=log_statement,
                                      level=level, span_guid=span_guid)

        if payload is not None:
            try:
                log_record.payload_json = \
                    jsonpickle.encode(payload, constants.JSON_UNPICKLABLE,
                                      max_depth=constants.JSON_MAX_DEPTH)
            except:
                log_record.payload_json = jsonpickle.encode(constants.JSON_FAIL)

        self._add_log(log_record)
Exemplo n.º 2
0
    def __init__(self, group_name, access_token,
                 secure=True, service_host="api.traceguide.io",
                 service_port=9997, debugger=None):
        # Thrift runtime configuration
        guid = util._generate_guid()
        timestamp = util._now_micros()
        self._runtime = ttypes.Runtime(guid, timestamp, group_name)
        self._service_url = util._service_url_from_hostport(secure,
                                                            service_host,
                                                            service_port)
        self._auth = ttypes.Auth(access_token)
        self._mutex = threading.Lock()
        self._log_records, self._span_records = ([] for i in range(2))

        # Only establish timer-based flush if no debugger is provided
        self._debugger = debugger
        self._connection = conn._Connection(self._service_url)
        self._connection._open()
        self._event = threading.Event()
        self._flush_thread = threading.Thread(target=self._timed_flush,
                                              name=constants.FLUSH_THREAD_NAME)
        self._flush_thread.daemon = True
        if self._debugger is None:
            self._flush_thread.start()

        # Configuration for clean up & runtime disabling
        register(self.shutdown)
        self._disabled_runtime = False
Exemplo n.º 3
0
    def end(self):
        """ End the active span so that it can be reported to the server

            :return: whether span recording successfully ended
            :rtype: bool
        """
        if self._runtime is None:
            return False
        if self._span_record is None:
            return False
        self._span_record.youngest_micros = util._now_micros()
        self._runtime._add_span(self._span_record)
        return True
Exemplo n.º 4
0
    def span(self, name):
        """ Mark the start of a span operation

            :param str name: the name by which the recording span can
                be identified
            :return: ActiveSpan that references the newly initialized span
            :rtype: ActiveSpan
        """
        if self._disabled_runtime:
            return ActiveSpan(None, None)
        span_guid = util._generate_guid()
        runtime_guid = self._runtime.guid
        timestamp = util._now_micros()
        join_ids = []
        span_record = ttypes.SpanRecord(span_guid, runtime_guid, name, join_ids,
                                        timestamp)
        return ActiveSpan(self, span_record)