Current Path: > > opt > cloudlinux > venv > lib64 > python3.11 > > site-packages > sentry_sdk > integrations
Operation : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64 Software : Apache Server IP : 162.0.232.56 | Your IP: 216.73.216.111 Domains : 1034 Domain(s) Permission : [ 0755 ]
Name | Type | Size | Last Modified | Actions |
---|---|---|---|---|
__pycache__ | Directory | - | - | |
django | Directory | - | - | |
grpc | Directory | - | - | |
opentelemetry | Directory | - | - | |
redis | Directory | - | - | |
spark | Directory | - | - | |
__init__.py | File | 6827 bytes | April 17 2025 13:10:59. | |
_wsgi_common.py | File | 4537 bytes | April 17 2025 13:10:59. | |
aiohttp.py | File | 11553 bytes | April 17 2025 13:10:59. | |
argv.py | File | 963 bytes | April 17 2025 13:10:59. | |
arq.py | File | 6737 bytes | April 17 2025 13:10:59. | |
asgi.py | File | 11821 bytes | April 17 2025 13:10:59. | |
asyncio.py | File | 3049 bytes | April 17 2025 13:10:59. | |
atexit.py | File | 1846 bytes | April 17 2025 13:10:59. | |
aws_lambda.py | File | 15815 bytes | April 17 2025 13:10:59. | |
beam.py | File | 5689 bytes | April 17 2025 13:10:59. | |
boto3.py | File | 4542 bytes | April 17 2025 13:10:59. | |
bottle.py | File | 6471 bytes | April 17 2025 13:10:59. | |
celery.py | File | 19100 bytes | April 17 2025 13:10:59. | |
chalice.py | File | 4769 bytes | April 17 2025 13:10:59. | |
cloud_resource_context.py | File | 6755 bytes | April 17 2025 13:10:59. | |
dedupe.py | File | 1184 bytes | April 17 2025 13:10:59. | |
excepthook.py | File | 2260 bytes | April 17 2025 13:10:59. | |
executing.py | File | 2041 bytes | April 17 2025 13:10:59. | |
falcon.py | File | 7984 bytes | April 17 2025 13:10:59. | |
fastapi.py | File | 4496 bytes | April 17 2025 13:10:59. | |
flask.py | File | 7907 bytes | April 17 2025 13:10:59. | |
gcp.py | File | 8213 bytes | April 17 2025 13:10:59. | |
gnu_backtrace.py | File | 2930 bytes | April 17 2025 13:10:59. | |
httpx.py | File | 5005 bytes | April 17 2025 13:10:59. | |
huey.py | File | 4700 bytes | April 17 2025 13:10:59. | |
logging.py | File | 9181 bytes | April 17 2025 13:10:59. | |
loguru.py | File | 3051 bytes | April 17 2025 13:10:59. | |
modules.py | File | 2110 bytes | April 17 2025 13:10:59. | |
pure_eval.py | File | 4554 bytes | April 17 2025 13:10:59. | |
pymongo.py | File | 6007 bytes | April 17 2025 13:10:59. | |
pyramid.py | File | 7442 bytes | April 17 2025 13:10:59. | |
quart.py | File | 7377 bytes | April 17 2025 13:10:59. | |
rq.py | File | 5411 bytes | April 17 2025 13:10:59. | |
sanic.py | File | 11326 bytes | April 17 2025 13:10:59. | |
serverless.py | File | 1975 bytes | April 17 2025 13:10:59. | |
socket.py | File | 2945 bytes | April 17 2025 13:10:59. | |
sqlalchemy.py | File | 4244 bytes | April 17 2025 13:10:59. | |
starlette.py | File | 23211 bytes | April 17 2025 13:10:59. | |
starlite.py | File | 10089 bytes | April 17 2025 13:10:59. | |
stdlib.py | File | 8251 bytes | April 17 2025 13:10:59. | |
threading.py | File | 2937 bytes | April 17 2025 13:10:59. | |
tornado.py | File | 7342 bytes | April 17 2025 13:10:59. | |
trytond.py | File | 1745 bytes | April 17 2025 13:10:59. | |
wsgi.py | File | 9581 bytes | April 17 2025 13:10:59. |
from __future__ import absolute_import from sentry_sdk.hub import Hub from sentry_sdk.integrations import Integration, DidNotEnable from sentry_sdk.integrations._wsgi_common import RequestExtractor from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware from sentry_sdk.tracing import SOURCE_FOR_STYLE from sentry_sdk.utils import ( capture_internal_exceptions, event_from_exception, parse_version, ) from sentry_sdk._types import TYPE_CHECKING if TYPE_CHECKING: from typing import Any from typing import Dict from typing import Optional from sentry_sdk._types import EventProcessor # In Falcon 3.0 `falcon.api_helpers` is renamed to `falcon.app_helpers` # and `falcon.API` to `falcon.App` try: import falcon # type: ignore from falcon import __version__ as FALCON_VERSION except ImportError: raise DidNotEnable("Falcon not installed") try: import falcon.app_helpers # type: ignore falcon_helpers = falcon.app_helpers falcon_app_class = falcon.App FALCON3 = True except ImportError: import falcon.api_helpers # type: ignore falcon_helpers = falcon.api_helpers falcon_app_class = falcon.API FALCON3 = False class FalconRequestExtractor(RequestExtractor): def env(self): # type: () -> Dict[str, Any] return self.request.env def cookies(self): # type: () -> Dict[str, Any] return self.request.cookies def form(self): # type: () -> None return None # No such concept in Falcon def files(self): # type: () -> None return None # No such concept in Falcon def raw_data(self): # type: () -> Optional[str] # As request data can only be read once we won't make this available # to Sentry. Just send back a dummy string in case there was a # content length. # TODO(jmagnusson): Figure out if there's a way to support this content_length = self.content_length() if content_length > 0: return "[REQUEST_CONTAINING_RAW_DATA]" else: return None if FALCON3: def json(self): # type: () -> Optional[Dict[str, Any]] try: return self.request.media except falcon.errors.HTTPBadRequest: return None else: def json(self): # type: () -> Optional[Dict[str, Any]] try: return self.request.media except falcon.errors.HTTPBadRequest: # NOTE(jmagnusson): We return `falcon.Request._media` here because # falcon 1.4 doesn't do proper type checking in # `falcon.Request.media`. This has been fixed in 2.0. # Relevant code: https://github.com/falconry/falcon/blob/1.4.1/falcon/request.py#L953 return self.request._media class SentryFalconMiddleware(object): """Captures exceptions in Falcon requests and send to Sentry""" def process_request(self, req, resp, *args, **kwargs): # type: (Any, Any, *Any, **Any) -> None hub = Hub.current integration = hub.get_integration(FalconIntegration) if integration is None: return with hub.configure_scope() as scope: scope._name = "falcon" scope.add_event_processor(_make_request_event_processor(req, integration)) TRANSACTION_STYLE_VALUES = ("uri_template", "path") class FalconIntegration(Integration): identifier = "falcon" transaction_style = "" def __init__(self, transaction_style="uri_template"): # type: (str) -> None if transaction_style not in TRANSACTION_STYLE_VALUES: raise ValueError( "Invalid value for transaction_style: %s (must be in %s)" % (transaction_style, TRANSACTION_STYLE_VALUES) ) self.transaction_style = transaction_style @staticmethod def setup_once(): # type: () -> None version = parse_version(FALCON_VERSION) if version is None: raise DidNotEnable("Unparsable Falcon version: {}".format(FALCON_VERSION)) if version < (1, 4): raise DidNotEnable("Falcon 1.4 or newer required.") _patch_wsgi_app() _patch_handle_exception() _patch_prepare_middleware() def _patch_wsgi_app(): # type: () -> None original_wsgi_app = falcon_app_class.__call__ def sentry_patched_wsgi_app(self, env, start_response): # type: (falcon.API, Any, Any) -> Any hub = Hub.current integration = hub.get_integration(FalconIntegration) if integration is None: return original_wsgi_app(self, env, start_response) sentry_wrapped = SentryWsgiMiddleware( lambda envi, start_resp: original_wsgi_app(self, envi, start_resp) ) return sentry_wrapped(env, start_response) falcon_app_class.__call__ = sentry_patched_wsgi_app def _patch_handle_exception(): # type: () -> None original_handle_exception = falcon_app_class._handle_exception def sentry_patched_handle_exception(self, *args): # type: (falcon.API, *Any) -> Any # NOTE(jmagnusson): falcon 2.0 changed falcon.API._handle_exception # method signature from `(ex, req, resp, params)` to # `(req, resp, ex, params)` if isinstance(args[0], Exception): ex = args[0] else: ex = args[2] was_handled = original_handle_exception(self, *args) hub = Hub.current integration = hub.get_integration(FalconIntegration) if integration is not None and _exception_leads_to_http_5xx(ex): # If an integration is there, a client has to be there. client = hub.client # type: Any event, hint = event_from_exception( ex, client_options=client.options, mechanism={"type": "falcon", "handled": False}, ) hub.capture_event(event, hint=hint) return was_handled falcon_app_class._handle_exception = sentry_patched_handle_exception def _patch_prepare_middleware(): # type: () -> None original_prepare_middleware = falcon_helpers.prepare_middleware def sentry_patched_prepare_middleware( middleware=None, independent_middleware=False ): # type: (Any, Any) -> Any hub = Hub.current integration = hub.get_integration(FalconIntegration) if integration is not None: middleware = [SentryFalconMiddleware()] + (middleware or []) return original_prepare_middleware(middleware, independent_middleware) falcon_helpers.prepare_middleware = sentry_patched_prepare_middleware def _exception_leads_to_http_5xx(ex): # type: (Exception) -> bool is_server_error = isinstance(ex, falcon.HTTPError) and (ex.status or "").startswith( "5" ) is_unhandled_error = not isinstance( ex, (falcon.HTTPError, falcon.http_status.HTTPStatus) ) return is_server_error or is_unhandled_error def _set_transaction_name_and_source(event, transaction_style, request): # type: (Dict[str, Any], str, falcon.Request) -> None name_for_style = { "uri_template": request.uri_template, "path": request.path, } event["transaction"] = name_for_style[transaction_style] event["transaction_info"] = {"source": SOURCE_FOR_STYLE[transaction_style]} def _make_request_event_processor(req, integration): # type: (falcon.Request, FalconIntegration) -> EventProcessor def event_processor(event, hint): # type: (Dict[str, Any], Dict[str, Any]) -> Dict[str, Any] _set_transaction_name_and_source(event, integration.transaction_style, req) with capture_internal_exceptions(): FalconRequestExtractor(req).extract_into_event(event) return event return event_processor
SILENT KILLER Tool