Skip to content
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
27 changes: 5 additions & 22 deletions sentry_sdk/integrations/tornado.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import contextlib
import weakref
from inspect import iscoroutinefunction

import sentry_sdk
from sentry_sdk.api import continue_trace
Expand Down Expand Up @@ -30,7 +29,6 @@

try:
from tornado import version_info as TORNADO_VERSION
from tornado.gen import coroutine
from tornado.web import HTTPError, RequestHandler
except ImportError:
raise DidNotEnable("Tornado not installed")
Expand All @@ -56,26 +54,11 @@ def setup_once() -> None:

old_execute = RequestHandler._execute

awaitable = iscoroutinefunction(old_execute)

if awaitable:
# Starting Tornado 6 RequestHandler._execute method is a standard Python coroutine (async/await)
# In that case our method should be a coroutine function too
async def sentry_execute_request_handler(
self: "RequestHandler", *args: "Any", **kwargs: "Any"
) -> "Any":
with _handle_request_impl(self):
return await old_execute(self, *args, **kwargs)

else:

@coroutine # type: ignore
def sentry_execute_request_handler(
self: "RequestHandler", *args: "Any", **kwargs: "Any"
) -> "Any":
with _handle_request_impl(self):
result = yield from old_execute(self, *args, **kwargs)
return result
async def sentry_execute_request_handler(
self: "RequestHandler", *args: "Any", **kwargs: "Any"
) -> "Any":
with _handle_request_impl(self):
return await old_execute(self, *args, **kwargs)

RequestHandler._execute = sentry_execute_request_handler

Expand Down
Loading