# Path: rollbar/contrib/fastapi/middleware.py
# class ReporterMiddleware(StarletteReporterMiddleware):
#     ...


import fastapi
import rollbar
import uvicorn
from rollbar.contrib.fastapi import ReporterMiddleware as RollbarMiddleware
#       You may consider to use routing integration instead (see app.py example).
#
# Run: python app_middleware.py



# Initialize Rollbar SDK with your server-side ACCESS_TOKEN
rollbar.init(
    'ACCESS_TOKEN',
    environment='staging',
    handler='async',  # For asynchronous reporting use: default, async or httpx
)

# Integrate Rollbar with FastAPI application
app = fastapi.FastAPI()
app.add_middleware(RollbarMiddleware)  # should be added as the first middleware


# Verify application runs correctly
#
# $ curl http://localhost:8888
@app.get('/')
async def read_root():
    return {'hello': 'world'}


# Cause an uncaught exception to be sent to Rollbar
# GET query params will be sent to Rollbar and available in the UI
#
# $ curl http://localhost:8888/error?param1=hello&param2=world

# Path: rollbar/contrib/fastapi/middleware.py
# class ReporterMiddleware(StarletteReporterMiddleware):
#     ...


# Path: rollbar/examples/fastapi/app_middleware.py
import fastapi
import rollbar
import uvicorn
from rollbar.contrib.fastapi import ReporterMiddleware as RollbarMiddleware

#       You may consider to use routing integration instead (see app.py example).
#
# Run: python app_middleware.py



# Initialize Rollbar SDK with your server-side ACCESS_TOKEN
rollbar.init(
    'ACCESS_TOKEN',
    environment='staging',
    handler='async',  # For asynchronous reporting use: default, async or httpx
)

# Integrate Rollbar with FastAPI application
app = fastapi.FastAPI()
app.add_middleware(RollbarMiddleware)  # should be added as the first middleware


# Verify application runs correctly
#
# $ curl http://localhost:8888
@app.get('/')
async def read_root():
    return {'hello': 'world'}


# Cause an uncaught exception to be sent to Rollbar
# GET query params will be sent to Rollbar and available in the UI
#
# $ curl http://localhost:8888/error?param1=hello&param2=world

async def localfunc(arg1, arg2, arg3):