Created
January 22, 2016 18:19
-
-
Save dkuebric/ed9af79d4447226955e5 to your computer and use it in GitHub Desktop.
AppNeta TraceView - Tracing Example - ZeroMQ Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import oboe | |
import pickle | |
import time | |
import zmq | |
def run_server(): | |
print('Distributed tracing server: receive request, sleep, reply') | |
zmq_context = zmq.Context() | |
socket = zmq_context.socket(zmq.REP) | |
socket.bind('tcp://*:5556') | |
while True: | |
# Wait for next request from client | |
wrapper = pickle.loads(socket.recv()) | |
message = wrapper['Payload'] | |
# Begin backend trace based on upstream context | |
keys={'URL': '/server.py', 'Domain': 'localhost'} | |
oboe.start_trace('Backend', keys=keys, xtr=wrapper['TraceContext']) | |
print('Received request: %s' % (message,)) | |
# Do some 'work' | |
time.sleep(1) | |
message = 'World' | |
# End backend trace, reply back to client | |
trace_context = oboe.end_trace('Backend') | |
wrapper = pickle.dumps({'TraceContext': str(trace_context), 'Payload': message}) | |
socket.send(wrapper) | |
if __name__ == '__main__': | |
run_server() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment