github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/examples/python/rideshare/fastapi/lib/server.py (about) 1 import os 2 import time 3 import pyroscope 4 from fastapi import FastAPI 5 from lib.bike.bike import order_bike 6 from lib.car.car import order_car 7 from lib.scooter.scooter import order_scooter 8 9 pyroscope.configure( 10 application_name = "ride-sharing-app", 11 server_address = "http://pyroscope:4040", 12 tags = { 13 "region": f'{os.getenv("REGION")}', 14 } 15 ) 16 17 18 app = FastAPI() 19 20 @app.get("/") 21 def read_root(): 22 return {"Hello": "World"} 23 24 @app.get("/bike") 25 def bike(): 26 order_bike(0.2) 27 return "<p>Bike ordered</p>" 28 29 30 @app.get("/scooter") 31 def scooter(): 32 order_scooter(0.3) 33 return "<p>Scooter ordered</p>" 34 35 36 @app.get("/car") 37 def car(): 38 order_car(0.4) 39 return "<p>Car ordered</p>" 40 41 42 @app.get("/") 43 def environment(): 44 result = "<h1>environment vars:</h1>" 45 for key, value in os.environ.items(): 46 result +=f"<p>{key}={value}</p>" 47 return result