Skip to content

Instantly share code, notes, and snippets.

@dkuebric
Created January 22, 2016 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkuebric/d116511f0528277919db to your computer and use it in GitHub Desktop.
Save dkuebric/d116511f0528277919db to your computer and use it in GitHub Desktop.
AppNeta TraceView - Tracing Example - ZeroMQ Client
import oboe
import pickle
import time
import zmq
def instrumented_rpc(socket, message):
""" Example instrumented RPC method."""
keys = {'IsService': True, 'RemoteURL': 'tcp://localhost:5556'}
oboe.log_entry('RPC-Client', keys=keys)
wrapper = pickle.dumps({'TraceContext': str(oboe.Context.get_default()), 'Payload': message})
socket.send(wrapper)
wrapper = pickle.loads(socket.recv())
reply = wrapper['Payload']
c = oboe.Context(wrapper['TraceContext'])
c.set_as_default()
oboe.log_exit('RPC-Client')
return reply
def run_client():
print('Distributed tracing client: sleep, send a message, receive reply, end transaction')
# tracing setup: normally handled by AppNeta instrumentation, only necessary for non-web apps
oboe.config['tracing_mode'] = 'always'
keys={'URL': '/client.py', 'Domain': 'localhost'}
oboe.start_trace('Frontend', keys=keys)
time.sleep(0.5) # just to make the traces a little more interesting
# Socket to talk to serve
zmq_context = zmq.Context()
socket = zmq_context.socket(zmq.REQ)
socket.connect('tcp://localhost:5556')
print('Sending request')
reply = instrumented_rpc(socket, 'Hello')
print('Received reply %s' % (reply,))
# trace end: as above, normally handled by AppNeta instrumentation
oboe.end_trace('Frontend')
if __name__ == '__main__':
run_client()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment