<commit_before>import sys

from starlette.requests import Request
from starlette.types import Receive, Scope, Send

import rollbar
from .requests import store_current_request
from rollbar.contrib.asgi import ReporterMiddleware as ASGIReporterMiddleware
from rollbar.lib._async import RollbarAsyncError, try_report


class ReporterMiddleware(ASGIReporterMiddleware):
    async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
        try:
            store_current_request(scope, receive)
            await self.app(scope, receive, send)
        except Exception:
            if scope['type'] == 'http':
                request = Request(scope, receive, send)

                # Consuming the request body in Starlette middleware is problematic.
                # See: https://github.com/encode/starlette/issues/495#issuecomment-494008175
                # Uncomment lines below if you know the risks.
                #
                # await request.body()
                # await request.form()

                exc_info = sys.exc_info()

                try:
                    await try_report(exc_info, request)
                except RollbarAsyncError:
                    rollbar.report_exc_info(exc_info, request)
            raise<commit_msg>Do not pass Send message to Request<commit_after>import sys

from starlette.requests import Request
from starlette.types import Receive, Scope, Send

import rollbar
from .requests import store_current_request
from rollbar.contrib.asgi import ReporterMiddleware as ASGIReporterMiddleware
from rollbar.lib._async import RollbarAsyncError, try_report


class ReporterMiddleware(ASGIReporterMiddleware):
    async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
        try:
            store_current_request(scope, receive)
            await self.app(scope, receive, send)
        except Exception:
            if scope['type'] == 'http':
                request = Request(scope, receive)

                # Consuming the request body in Starlette middleware is problematic.
                # See: https://github.com/encode/starlette/issues/495#issuecomment-494008175
                # Uncomment lines below if you know the risks.
                #
                # await request.body()
                # await request.form()

                exc_info = sys.exc_info()

                try:
                    await try_report(exc_info, request)
                except RollbarAsyncError:
                    rollbar.report_exc_info(exc_info, request)
            raise
{'fraction_non_alphanumeric': 0.06897895557287607, 'fraction_numerical': 0.009353078721745909, 'mean_word_length': 2.2007481296758105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3939653', 'n_tokens_mistral': 681, 'n_tokens_neox': 640, 'n_words': 186}