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
def flush(self): """ Send unreported data to the server. Every few seconds automatic reports are sent to the server. However, one can also manually send reports to the server. Calling flush() will ensure that any current unreported data will be immediately sent to the host server. """ if self._disabled_runtime: return if self._debugger is None: connection = conn._Connection(self._service_url) connection._open() self._flush_worker(connection) connection._close() else: self._debug_flush()