# Path: rollbar/contrib/fastapi/routing.py
# @fastapi_min_version('0.41.0')
# @integrate(framework_name=f'fastapi {__version__}')
# def add_to(app_or_router: Union[FastAPI, APIRouter]) -> Optional[Type[APIRoute]]:
#     """
#     Adds RollbarLoggingRoute handler to the router app.
# 
#     This is the recommended way for integration with FastAPI.
#     Alternatively to using middleware, the handler may fill
#     more data in the payload (e.g. request body).
# 
#     app_or_router: FastAPI app or router
# 
#     Note: The route handler must be added before adding user routes
# 
#     Requirements: FastAPI v0.41.0+
# 
#     Example usage:
# 
#     from fastapi import FastAPI
#     from rollbar.contrib.fastapi import add_to as rollbar_add_to
# 
#     app = FastAPI()
#     rollbar_add_to(app)
# 
#     """
# 
#     if not has_bare_routing(app_or_router):
#         log.error(
#             'RollbarLoggingRoute must to be added to a bare router'
#             ' (before adding routes). See docs for more details.'
#         )
#         return None
# 
#     installed_middlewares = get_installed_middlewares(app_or_router)
#     if installed_middlewares:
#         log.warning(
#             f'Detected middleware installed {installed_middlewares}'
#             ' while loading Rollbar route handler.'
#             ' This can cause in duplicate occurrences.'
#         )
# 
#     if isinstance(app_or_router, FastAPI):
#         _add_to_app(app_or_router)
#     elif isinstance(app_or_router, APIRouter):
#         _add_to_router(app_or_router)
#     else:
#         log.error('Error adding RollbarLoggingRoute to application.')
#         return None
# 
#     return RollbarLoggingRoute


import fastapi
import rollbar
import uvicorn
from rollbar.contrib.fastapi import add_to as rollbar_add_to

# This example uses Uvicorn package that must be installed. However, it can be
# replaced with any other ASGI-compliant server.
#
# Optional asynchronous reporting requires HTTPX package to be installed.
#
# NOTE: This example requires FastAPI v0.41.0+ (see app_middleware.py for alternative).
#
# Run: python app.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
    include_request_body=True,
)

# Integrate Rollbar with FastAPI application before adding routes to the app
app = fastapi.FastAPI()
rollbar_add_to(app)


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

# Path: rollbar/contrib/fastapi/routing.py
# @fastapi_min_version('0.41.0')
# @integrate(framework_name=f'fastapi {__version__}')
# def add_to(app_or_router: Union[FastAPI, APIRouter]) -> Optional[Type[APIRoute]]:
#     """
#     Adds RollbarLoggingRoute handler to the router app.
# 
#     This is the recommended way for integration with FastAPI.
#     Alternatively to using middleware, the handler may fill
#     more data in the payload (e.g. request body).
# 
#     app_or_router: FastAPI app or router
# 
#     Note: The route handler must be added before adding user routes
# 
#     Requirements: FastAPI v0.41.0+
# 
#     Example usage:
# 
#     from fastapi import FastAPI
#     from rollbar.contrib.fastapi import add_to as rollbar_add_to
# 
#     app = FastAPI()
#     rollbar_add_to(app)
# 
#     """
# 
#     if not has_bare_routing(app_or_router):
#         log.error(
#             'RollbarLoggingRoute must to be added to a bare router'
#             ' (before adding routes). See docs for more details.'
#         )
#         return None
# 
#     installed_middlewares = get_installed_middlewares(app_or_router)
#     if installed_middlewares:
#         log.warning(
#             f'Detected middleware installed {installed_middlewares}'
#             ' while loading Rollbar route handler.'
#             ' This can cause in duplicate occurrences.'
#         )
# 
#     if isinstance(app_or_router, FastAPI):
#         _add_to_app(app_or_router)
#     elif isinstance(app_or_router, APIRouter):
#         _add_to_router(app_or_router)
#     else:
#         log.error('Error adding RollbarLoggingRoute to application.')
#         return None
# 
#     return RollbarLoggingRoute


# Path: rollbar/examples/fastapi/app.py
import fastapi
import rollbar
import uvicorn
from rollbar.contrib.fastapi import add_to as rollbar_add_to


# This example uses Uvicorn package that must be installed. However, it can be
# replaced with any other ASGI-compliant server.
#
# Optional asynchronous reporting requires HTTPX package to be installed.
#
# NOTE: This example requires FastAPI v0.41.0+ (see app_middleware.py for alternative).
#
# Run: python app.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
    include_request_body=True,
)

# Integrate Rollbar with FastAPI application before adding routes to the app
app = fastapi.FastAPI()
rollbar_add_to(app)


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

    return {'hello': 'world'}