Skip to content
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

Fixed typing in aiohttp #2590

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.
Jump to
Jump to file
Failed to load files.
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

Check warning on line 47 in sentry_sdk/integrations/aiohttp.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/aiohttp.py#L47

Added line #L47 was not covered by tests
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 @@
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 @@
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 @@

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 @@
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 @@


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