def zipkin_ot_tracer_from_args(): """Initializes OpenZipkin from the commandline args. """ parser = argparse.ArgumentParser() parser.add_argument( '--host', help='The OpenZipkin reporting service host to contact.', default='localhost') parser.add_argument('--port', help='The OpenZipkin reporting service port.', type=int, default=9411) parser.add_argument('--service_name', help='The OpenZipkin component name', default='TrivialExample') args = parser.parse_args() return zipkin_ot.Tracer(service_name=args.service_name, collector_host=args.host, collector_port=args.port, verbosity=1)
import os, random, time, sys import opentracing import zipkin_ot import flask app = flask.Flask("calc_backend") opentracing.tracer = zipkin_ot.Tracer( service_name="demo_arch", collector_host=os.environ.get("ZIPKIN_HOST")) files_dir = None @app.before_request def launch_trace(): headers = {} for k, v in flask.request.headers.items(): headers[k] = v parent_context = opentracing.tracer.extract( opentracing.Format.HTTP_HEADERS, headers) span = opentracing.tracer.start_span(operation_name="calc_service", child_of=parent_context) span.set_tag("span.kind", "server") span.set_tag("component", "calc frontend service") span.set_tag("http.url", "http://calc_backend:4570") flask.g.span = span
import coordinate import weather s = socket.socket() # Create a socket object host = socket.gethostname() # Get local machine name port = 12345 # Reserve a port for your service. s.bind((host, port)) # Bind to the port s.listen(5) # Now wait for client connection. if __name__ == '__main__': with zipkin_ot.Tracer( service_name= 'Weather-server', # connect opantracing to zipkin server collector_host='localhost', collector_port=9411, verbosity=1) as tracer: opentracing.tracer = tracer while True: c, addr = s.accept() # Establish connection with client. print 'Got connection from', addr while True: data = c.recv(1024) #print "data ", data text_carrier = None address = None if not data: break