def ready(self): self.mdk = start() timeout = getattr(settings, "MDK_DEFAULT_TIMEOUT", None) if timeout is not None: self.mdk.setDefaultDeadline(timeout) atexit.register(self.mdk.stop) self.mdk_ready(self.mdk)
def main(): url = sys.argv[1] mdk = start() session = mdk.session() session.setDeadline(1.0) mdk.stop() req_ssn = requests_session(session) try: req_ssn.get(url).content except Timeout: sys.exit(123) return
def mdk_setup(app, timeout=None, mdk=None): """ Setup MDK integration with Flask. :param app: A Flask application instance. :param timeout: Default timeout in seconds to set for the MDK session. :param mdk: An optional ``mdk.MDK`` instance to use instead of creating a new one. It will not be started or stopped. :return: The ``mdk.MDK`` instance. """ if mdk is None: app.mdk = start() atexit.register(app.mdk.stop) else: app.mdk = mdk if timeout is not None: app.mdk.setDefaultDeadline(timeout) request_started.connect(_on_request_started, app) got_request_exception.connect(_on_request_exception, app) request_tearing_down.connect(_on_request_tearing_down, app) return app.mdk
def main(mdk, service, version): while True: # Start a new session: ssn = mdk.session() # Wait 10 seconds for result, if no service is available an exception is # raised: url = ssn.resolve(service, version).address ssn.info("client", "Connecting to {}".format(url)) r = requests.get(url, headers={mdk.CONTEXT_HEADER: ssn.inject()}) ssn.info("client", "Got response {} (code {})".format(r.text, r.status_code)) print("%s => %d: %s" % (url, r.status_code, r.text)) time.sleep(1) if __name__ == '__main__': import sys if len(sys.argv) < 2: raise Exception("usage: client service_name"); service_name = sys.argv[1] MDK = mdk.start() try: main(MDK, service_name, "1.0.0") finally: MDK.stop()
"""Write some logs to the given tracing session.""" import sys import time from mdk import start mdk = start() def main(): context = sys.argv[1] session = mdk.join(context) session.info("process1", "hello") time.sleep(5) # make sure it's written sys.stdout.write(session.inject()) sys.stdout.flush() mdk.stop() if __name__ == '__main__': main()
while True: # Start a new session: ssn = mdk.session() # Wait 10 seconds for result, if no service is available an exception is # raised: url = ssn.resolve(service, version).address ssn.info("client", "Connecting to {}".format(url)) r = requests.get(url, headers={mdk.CONTEXT_HEADER: ssn.inject()}) ssn.info("client", "Got response {} (code {})".format(r.text, r.status_code)) print("%s => %d: %s" % (url, r.status_code, r.text)) time.sleep(1) if __name__ == '__main__': import sys if len(sys.argv) < 2: raise Exception("usage: client service_name") service_name = sys.argv[1] MDK = mdk.start() try: main(MDK, service_name, "1.0.0") finally: MDK.stop()
import mdk, time, requests m = mdk.start() ssn = m.session() while True: print requests.get(ssn.resolve("hello", "1.0").address).text time.sleep(1.0)
def main(): mdk = start() context = sys.argv[1] expected = set([tuple(l) for l in loads(sys.argv[2])]) Retriever(context, expected, mdk).read_logs()