Skip to content

Fixed typing in aiohttp #2590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@

if TYPE_CHECKING:
from aiohttp.web_request import Request
from aiohttp.abc import AbstractMatchInfo
from aiohttp.web_urldispatcher import UrlMappingMatchInfo
from aiohttp import TraceRequestStartParams, TraceRequestEndParams
from types import SimpleNamespace
from typing import Any
from typing import Dict
from typing import Optional
from typing import Tuple
from typing import Callable
from typing import Union

from sentry_sdk.utils import ExcInfo
Expand Down Expand Up @@ -113,8 +112,9 @@ async def sentry_app_handle(self, request, *args, **kwargs):
scope.clear_breadcrumbs()
scope.add_event_processor(_make_request_processor(weak_request))

headers = dict(request.headers)
transaction = continue_trace(
request.headers,
headers,
op=OP.HTTP_SERVER,
# If this transaction name makes it to the UI, AIOHTTP's
# URL resolver did not find a route or died trying.
Expand All @@ -141,12 +141,12 @@ async def sentry_app_handle(self, request, *args, **kwargs):
transaction.set_http_status(response.status)
return response

Application._handle = sentry_app_handle
Application._handle = sentry_app_handle # type: ignore[method-assign]

old_urldispatcher_resolve = UrlDispatcher.resolve

async def sentry_urldispatcher_resolve(self, request):
# type: (UrlDispatcher, Request) -> AbstractMatchInfo
# type: (UrlDispatcher, Request) -> UrlMappingMatchInfo
rv = await old_urldispatcher_resolve(self, request)

hub = Hub.current
Expand All @@ -173,12 +173,12 @@ async def sentry_urldispatcher_resolve(self, request):

return rv

UrlDispatcher.resolve = sentry_urldispatcher_resolve
UrlDispatcher.resolve = sentry_urldispatcher_resolve # type: ignore[method-assign]

old_client_session_init = ClientSession.__init__

def init(*args, **kwargs):
# type: (Any, Any) -> ClientSession
# type: (Any, Any) -> None
hub = Hub.current
if hub.get_integration(AioHttpIntegration) is None:
return old_client_session_init(*args, **kwargs)
Expand All @@ -190,7 +190,7 @@ def init(*args, **kwargs):
kwargs["trace_configs"] = client_trace_configs
return old_client_session_init(*args, **kwargs)

ClientSession.__init__ = init
ClientSession.__init__ = init # type: ignore[method-assign]


def create_trace_config():
Expand Down Expand Up @@ -253,7 +253,7 @@ async def on_request_end(session, trace_config_ctx, params):


def _make_request_processor(weak_request):
# type: (Callable[[], Request]) -> EventProcessor
# type: (weakref.ReferenceType[Request]) -> EventProcessor
def aiohttp_processor(
event, # type: Dict[str, Any]
hint, # type: Dict[str, Tuple[type, BaseException, Any]]
Expand Down