Skip to content

Instantly share code, notes, and snippets.

@mkmrgn
Last active December 9, 2017 00:48
Show Gist options
  • Save mkmrgn/323ab1fc641b567408b20019b126d84c to your computer and use it in GitHub Desktop.
Save mkmrgn/323ab1fc641b567408b20019b126d84c to your computer and use it in GitHub Desktop.
import time
import appoptics
#import the loader so modules get instrumented
from appoptics import loader
loader.load_inst_modules()
#functions using the log_method decorator will show up as custom spans in AppOptics
@appoptics.log_method('function_1_layer')
def function_1():
print 'this is a function'
time.sleep(1)
@appoptics.log_method('function_2_layer')
def function_2():
print 'this is another function'
time.sleep(1)
start_time = time.time() * 1e6 # start time for metric span
trace = appoptics.start_trace('Python', keys=None, xtr=None) # start a trace
# This is where the work happens
function_1()
function_2()
function_1()
function_2()
trace_context = appoptics.end_trace('Python') #end the trace
stop_time = time.time() * 1e6 # stop the timing for the metric span
status_code = 200 # set the status code of the current trasaction (maps to the UI)
# Create metric span
appoptics.util.SwigSpan.createHttpSpan(
None, "analyze prices", int(stop_time - start_time), status_code,
"GET", 499 < status_code < 600,
)
print 'Exit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment