def post_report(self, report): local_rep = copy.deepcopy(report.report) format_report(local_rep) try: send_honeycomb(local_rep, self.config) except Exception as e: logger.debug("caught exception while sending report: {}".format(e)) finally: logger.debug("sent report to honeycomb") responses = libhoney.responses() resp = responses.get() if resp is None: logger.info("no response from honeycomb") else: logger.debug("got response from Honeycomb: {}".format(resp)) libhoney.close()
def read_responses(resp_queue): '''read responses from the libhoney queue, print them out.''' while True: resp = resp_queue.get() if resp is None: break status = "sending event with metadata {} took {}ms and got response code {} with message \"{}\"".format( resp["metadata"], resp["duration"], resp["status_code"], resp["body"].rstrip()) print status if __name__ == "__main__": libhoney.init(writekey=writekey, dataset=dataset, max_concurrent_batches=1) resps = libhoney.responses() t = threading.Thread(target=read_responses, args=(resps, )) t.start() # attach fields to top-level instance libhoney.add_field("version", "3.4.5") libhoney.add_dynamic_field(num_threads) # sends an event with "version", "num_threads", and "status" fields libhoney.send_now({"status": "starting run"}) run_fact(1, 2, libhoney.Builder({"range": "low"})) run_fact(31, 32, libhoney.Builder({"range": "high"})) # sends an event with "version", "num_threads", and "status" fields libhoney.send_now({"status": "ending run"}) graceful_shutdown(None, None)