github.com/grafana/pyroscope@v1.18.0/examples/language-sdk-instrumentation/python/simple/main.py (about) 1 #!/usr/bin/env python3 2 3 import logging 4 import os 5 import pyroscope 6 7 l = logging.getLogger() 8 l.setLevel(logging.DEBUG) 9 10 addr = os.getenv("PYROSCOPE_SERVER_ADDRESS") or "http://pyroscope:4040" 11 print(addr) 12 13 pyroscope.configure( 14 application_name = "simple.python.app", 15 server_address = addr, 16 enable_logging = True, 17 ) 18 19 def work(n): 20 i = 0 21 while i < n: 22 i += 1 23 24 def fast_function(): 25 with pyroscope.tag_wrapper({ "function": "fast" }): 26 work(20000) 27 28 def slow_function(): 29 with pyroscope.tag_wrapper({ "function": "slow" }): 30 work(80000) 31 32 if __name__ == "__main__": 33 while True: 34 fast_function() 35 slow_function()