github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/examples/python/rideshare/flask/lib/server.py (about)

     1  import os
     2  import time
     3  import pyroscope
     4  from flask import Flask
     5  from bike.bike import order_bike
     6  from car.car import order_car
     7  from scooter.scooter import order_scooter
     8  
     9  app_name = os.getenv("PYROSCOPE_APPLICATION_NAME", "flask-ride-sharing-app")
    10  server_addr = os.getenv("PYROSCOPE_SERVER_ADDRESS", "http://pyroscope:4040")
    11  auth_token = os.getenv("PYROSCOPE_AUTH_TOKEN", "")
    12  
    13  pyroscope.configure(
    14  	application_name = app_name,
    15  	server_address   = server_addr,
    16      auth_token       = auth_token,
    17  	tags             = {
    18          "region":   f'{os.getenv("REGION")}',
    19  	}
    20  )
    21  
    22  app = Flask(__name__)
    23  
    24  @app.route("/bike")
    25  def bike():
    26      order_bike(0.2)
    27      return "<p>Bike ordered</p>"
    28  
    29  
    30  @app.route("/scooter")
    31  def scooter():
    32      order_scooter(0.3)
    33      return "<p>Scooter ordered</p>"
    34  
    35  
    36  @app.route("/car")
    37  def car():
    38      order_car(0.4)
    39      return "<p>Car ordered</p>"
    40  
    41  
    42  @app.route("/")
    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
    48  
    49  if __name__ == '__main__':
    50      app.run(threaded=False, processes=1, host='0.0.0.0', debug=False)
    51