Skip to content

Instantly share code, notes, and snippets.

@dkuebric
Created January 22, 2016 18:19
Show Gist options
  • Save dkuebric/ed9af79d4447226955e5 to your computer and use it in GitHub Desktop.
Save dkuebric/ed9af79d4447226955e5 to your computer and use it in GitHub Desktop.
AppNeta TraceView - Tracing Example - ZeroMQ Server
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