# Path: rollbar/contrib/asgi/middleware.py
# class ReporterMiddleware(IntegrationBase):
#     def __init__(self, app: ASGIApp) -> None:
#         super().__init__()
# 
#         self.app = app
# 
#     async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
#         try:
#             await self.app(scope, receive, send)
#         except Exception:
#             if scope['type'] == 'http':
#                 exc_info = sys.exc_info()
# 
#                 try:
#                     await try_report(exc_info)
#                 except RollbarAsyncError:
#                     log.warning(
#                         'Failed to report asynchronously. Trying to report synchronously.'
#                     )
#                     rollbar.report_exc_info(exc_info)
#             raise


import rollbar
import uvicorn
from rollbar.contrib.asgi import ReporterMiddleware as RollbarMiddleware
from starlette.applications import Starlette
from starlette.responses import PlainTextResponse
    handler='async',  # For asynchronous reporting use: default, async or httpx
)

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


# Verify application runs correctly
#
# $ curl http://localhost:8888
@app.route('/')
async def root(request):
    return PlainTextResponse('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):
    # Both local variables and function arguments will be sent to Rollbar
    # and available in the UI
    localvar = 'local variable'
    cause_error_with_local_variables


@app.route('/error')
async def error(request):
    await localfunc('func_arg1', 'func_arg2', 1)

# Path: rollbar/contrib/asgi/middleware.py
# class ReporterMiddleware(IntegrationBase):
#     def __init__(self, app: ASGIApp) -> None:
#         super().__init__()
# 
#         self.app = app
# 
#     async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
#         try:
#             await self.app(scope, receive, send)
#         except Exception:
#             if scope['type'] == 'http':
#                 exc_info = sys.exc_info()
# 
#                 try:
#                     await try_report(exc_info)
#                 except RollbarAsyncError:
#                     log.warning(
#                         'Failed to report asynchronously. Trying to report synchronously.'
#                     )
#                     rollbar.report_exc_info(exc_info)
#             raise


# Path: rollbar/examples/asgi/app.py
import rollbar
import uvicorn
from rollbar.contrib.asgi import ReporterMiddleware as RollbarMiddleware
from starlette.applications import Starlette
from starlette.responses import PlainTextResponse

    handler='async',  # For asynchronous reporting use: default, async or httpx
)

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


# Verify application runs correctly
#
# $ curl http://localhost:8888
@app.route('/')
async def root(request):
    return PlainTextResponse('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):
    # Both local variables and function arguments will be sent to Rollbar
    # and available in the UI
    localvar = 'local variable'
    cause_error_with_local_variables


@app.route('/error')
async def error(request):
    await localfunc('func_arg1', 'func_arg2', 1)

    return PlainTextResponse("You shouldn't be seeing this")