Ejemplo n.º 1
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
Ejemplo n.º 2
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)