✘✘ GRAYBYTE WORDPRESS FILE MANAGER ✘✘

​🇳​​🇦​​🇲​​🇪♯➤ server366.web-hosting.com ​🇻​♯➤ 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP 🇾​♯➤ 2025

𝗛𝗢𝗠𝗘 𝗜𝗗 ♯➤ 67.223.118.204 ♯➤ 𝗔𝗗𝗠𝗜𝗡 𝗜𝗗 216.73.217.86
𝗢𝗣𝗧𝗜𝗢𝗡𝗦 ♯ CRL ♯➤ 𝗢𝗞 ┃ WGT ♯➤ 𝗢𝗞 ┃ SDO ♯➤ 𝗢𝗙𝗙 ┃ PKEX ♯➤ 𝗢𝗙𝗙
𝗗𝗘𝗔𝗖𝗧𝗜𝗩𝗔𝗧𝗘𝗗 ♯➤ 𝗔𝗟𝗟 𝗪𝗢𝗥𝗞𝗜𝗡𝗚....

𝗛𝗢𝗠𝗘
𝗖𝗨𝗥𝗥𝗘𝗡𝗧 𝗙𝗜𝗟𝗘 : /opt/hc_python/lib/python3.12/site-packages/sentry_sdk/integrations//sanic.py
import sys
import warnings
import weakref
from inspect import isawaitable
from typing import TYPE_CHECKING
from urllib.parse import urlsplit

import sentry_sdk
from sentry_sdk import continue_trace
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.integrations._wsgi_common import RequestExtractor, _filter_headers
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.traces import SegmentSource, StreamedSpan
from sentry_sdk.tracing import TransactionSource
from sentry_sdk.tracing_utils import has_span_streaming_enabled
from sentry_sdk.utils import (
    CONTEXTVARS_ERROR_MESSAGE,
    HAS_REAL_CONTEXTVARS,
    capture_internal_exceptions,
    ensure_integration_enabled,
    event_from_exception,
    parse_version,
    reraise,
)

if TYPE_CHECKING:
    from collections.abc import Container
    from typing import Any, Callable, Dict, Optional, Union

    from sanic.request import Request, RequestParameters
    from sanic.response import BaseHTTPResponse
    from sanic.router import Route

    from sentry_sdk._types import Event, EventProcessor, ExcInfo, Hint

try:
    from sanic import Sanic
    from sanic import __version__ as SANIC_VERSION
    from sanic.exceptions import SanicException
    from sanic.handlers import ErrorHandler
    from sanic.router import Router
except ImportError:
    raise DidNotEnable("Sanic not installed")

old_error_handler_lookup = ErrorHandler.lookup
old_handle_request = Sanic.handle_request
old_router_get = Router.get

try:
    # This method was introduced in Sanic v21.9
    old_startup = Sanic._startup
except AttributeError:
    pass


class SanicIntegration(Integration):
    identifier = "sanic"
    origin = f"auto.http.{identifier}"
    version: "Optional[tuple[int, ...]]" = None

    def __init__(
        self, unsampled_statuses: "Optional[Container[int]]" = frozenset({404})
    ) -> None:
        """
        The unsampled_statuses parameter can be used to specify for which HTTP statuses the
        transactions should not be sent to Sentry. By default, transactions are sent for all
        HTTP statuses, except 404. Set unsampled_statuses to None to send transactions for all
        HTTP statuses, including 404.
        """
        self._unsampled_statuses = unsampled_statuses or set()

    @staticmethod
    def setup_once() -> None:
        SanicIntegration.version = parse_version(SANIC_VERSION)
        _check_minimum_version(SanicIntegration, SanicIntegration.version)

        if not HAS_REAL_CONTEXTVARS:
            # We better have contextvars or we're going to leak state between
            # requests.
            raise DidNotEnable(
                "The sanic integration for Sentry requires Python 3.7+ "
                " or the aiocontextvars package." + CONTEXTVARS_ERROR_MESSAGE
            )

        if SANIC_VERSION.startswith("0.8."):
            # Sanic 0.8 and older creates a logger named "root" and puts a
            # stringified version of every exception in there (without exc_info),
            # which our error deduplication can't detect.
            #
            # We explicitly check the version here because it is a very
            # invasive step to ignore this logger and not necessary in newer
            # versions at all.
            #
            # https://github.com/huge-success/sanic/issues/1332
            ignore_logger("root")

        if SanicIntegration.version is not None and SanicIntegration.version < (21, 9):
            _setup_legacy_sanic()
            return

        _setup_sanic()


class SanicRequestExtractor(RequestExtractor):
    def content_length(self) -> int:
        if self.request.body is None:
            return 0
        return len(self.request.body)

    def cookies(self) -> "Dict[str, str]":
        return dict(self.request.cookies)

    def raw_data(self) -> bytes:
        return self.request.body

    def form(self) -> "RequestParameters":
        return self.request.form

    def is_json(self) -> bool:
        raise NotImplementedError()

    def json(self) -> "Optional[Any]":
        return self.request.json

    def files(self) -> "RequestParameters":
        return self.request.files

    def size_of_file(self, file: "Any") -> int:
        return len(file.body or ())


def _setup_sanic() -> None:
    Sanic._startup = _startup
    ErrorHandler.lookup = _sentry_error_handler_lookup


def _setup_legacy_sanic() -> None:
    Sanic.handle_request = _legacy_handle_request
    Router.get = _legacy_router_get
    ErrorHandler.lookup = _sentry_error_handler_lookup


async def _startup(self: "Sanic") -> None:
    # This happens about as early in the lifecycle as possible, just after the
    # Request object is created. The body has not yet been consumed.
    self.signal("http.lifecycle.request")(_context_enter)

    # This happens after the handler is complete. In v21.9 this signal is not
    # dispatched when there is an exception. Therefore we need to close out
    # and call _context_exit from the custom exception handler as well.
    # See https://github.com/sanic-org/sanic/issues/2297
    self.signal("http.lifecycle.response")(_context_exit)

    # This happens inside of request handling immediately after the route
    # has been identified by the router.
    self.signal("http.routing.after")(_set_transaction)

    # The above signals need to be declared before this can be called.
    await old_startup(self)


async def _context_enter(request: "Request") -> None:
    request.ctx._sentry_do_integration = (
        sentry_sdk.get_client().get_integration(SanicIntegration) is not None
    )

    if not request.ctx._sentry_do_integration:
        return

    client = sentry_sdk.get_client()
    is_span_streaming_enabled = has_span_streaming_enabled(client.options)

    weak_request = weakref.ref(request)
    request.ctx._sentry_scope = sentry_sdk.isolation_scope()
    scope = request.ctx._sentry_scope.__enter__()
    scope.clear_breadcrumbs()
    scope.add_event_processor(_make_request_processor(weak_request))

    if is_span_streaming_enabled:
        integration = client.get_integration(SanicIntegration)
        if (
            isinstance(integration, SanicIntegration)
            and integration._unsampled_statuses
        ):
            warnings.warn(
                "The `unsampled_statuses` option of SanicIntegration has no effect when span streaming is enabled.",
                stacklevel=2,
            )

        sentry_sdk.traces.continue_trace(dict(request.headers))
        scope.set_custom_sampling_context({"sanic_request": request})

        if should_send_default_pii() and request.remote_addr:
            scope.set_attribute(SPANDATA.USER_IP_ADDRESS, request.remote_addr)

        span = sentry_sdk.traces.start_span(
            # Unless the request results in a 404 error, the name and source
            # will get overwritten in _set_transaction
            name=request.path,
            attributes={
                "sentry.op": OP.HTTP_SERVER,
                "sentry.origin": SanicIntegration.origin,
                "sentry.span.source": SegmentSource.URL.value,
            },
            parent_span=None,
        )
        request.ctx._sentry_root_span = span
    else:
        transaction = continue_trace(
            dict(request.headers),
            op=OP.HTTP_SERVER,
            # Unless the request results in a 404 error, the name and source will get overwritten in _set_transaction
            name=request.path,
            source=TransactionSource.URL,
            origin=SanicIntegration.origin,
        )
        request.ctx._sentry_root_span = sentry_sdk.start_transaction(
            transaction
        ).__enter__()


async def _context_exit(
    request: "Request", response: "Optional[BaseHTTPResponse]" = None
) -> None:
    with capture_internal_exceptions():
        if not request.ctx._sentry_do_integration:
            return

        integration = sentry_sdk.get_client().get_integration(SanicIntegration)

        response_status = None if response is None else response.status

        # This capture_internal_exceptions block has been intentionally nested here, so that in case an exception
        # happens while trying to end the transaction, we still attempt to exit the hub.
        with capture_internal_exceptions():
            span = request.ctx._sentry_root_span
            if isinstance(span, StreamedSpan):
                with capture_internal_exceptions():
                    for attr, value in _get_request_attributes(request).items():
                        span.set_attribute(attr, value)
                if response_status is not None:
                    span.set_attribute(SPANDATA.HTTP_STATUS_CODE, response_status)
                    span.status = "error" if response_status >= 400 else "ok"

                span.end()

            else:
                span.set_http_status(response_status)
                span.sampled &= (
                    isinstance(integration, SanicIntegration)
                    and response_status not in integration._unsampled_statuses
                )

                span.__exit__(None, None, None)

        request.ctx._sentry_scope.__exit__(None, None, None)


async def _set_transaction(request: "Request", route: "Route", **_: "Any") -> None:
    if request.ctx._sentry_do_integration:
        with capture_internal_exceptions():
            scope = sentry_sdk.get_current_scope()
            route_name = route.name.replace(request.app.name, "").strip(".")
            scope.set_transaction_name(route_name, source=TransactionSource.COMPONENT)


def _sentry_error_handler_lookup(
    self: "Any", exception: Exception, *args: "Any", **kwargs: "Any"
) -> "Optional[object]":
    _capture_exception(exception)
    old_error_handler = old_error_handler_lookup(self, exception, *args, **kwargs)

    if old_error_handler is None:
        return None

    if sentry_sdk.get_client().get_integration(SanicIntegration) is None:
        return old_error_handler

    async def sentry_wrapped_error_handler(
        request: "Request", exception: Exception
    ) -> "Any":
        try:
            response = old_error_handler(request, exception)
            if isawaitable(response):
                response = await response
            return response
        except Exception:
            # Report errors that occur in Sanic error handler. These
            # exceptions will not even show up in Sanic's
            # `sanic.exceptions` logger.
            exc_info = sys.exc_info()
            _capture_exception(exc_info)
            reraise(*exc_info)
        finally:
            # As mentioned in previous comment in _startup, this can be removed
            # after https://github.com/sanic-org/sanic/issues/2297 is resolved
            if SanicIntegration.version and SanicIntegration.version == (21, 9):
                await _context_exit(request)

    return sentry_wrapped_error_handler


async def _legacy_handle_request(
    self: "Any", request: "Request", *args: "Any", **kwargs: "Any"
) -> "Any":
    if sentry_sdk.get_client().get_integration(SanicIntegration) is None:
        return await old_handle_request(self, request, *args, **kwargs)

    weak_request = weakref.ref(request)

    with sentry_sdk.isolation_scope() as scope:
        scope.clear_breadcrumbs()
        scope.add_event_processor(_make_request_processor(weak_request))

        response = old_handle_request(self, request, *args, **kwargs)
        if isawaitable(response):
            response = await response

        return response


def _legacy_router_get(self: "Any", *args: "Union[Any, Request]") -> "Any":
    rv = old_router_get(self, *args)
    if sentry_sdk.get_client().get_integration(SanicIntegration) is not None:
        with capture_internal_exceptions():
            scope = sentry_sdk.get_isolation_scope()
            if SanicIntegration.version and SanicIntegration.version >= (21, 3):
                # Sanic versions above and including 21.3 append the app name to the
                # route name, and so we need to remove it from Route name so the
                # transaction name is consistent across all versions
                sanic_app_name = self.ctx.app.name
                sanic_route = rv[0].name

                if sanic_route.startswith("%s." % sanic_app_name):
                    # We add a 1 to the len of the sanic_app_name because there is a dot
                    # that joins app name and the route name
                    # Format: app_name.route_name
                    sanic_route = sanic_route[len(sanic_app_name) + 1 :]

                scope.set_transaction_name(
                    sanic_route, source=TransactionSource.COMPONENT
                )
            else:
                scope.set_transaction_name(
                    rv[0].__name__, source=TransactionSource.COMPONENT
                )

    return rv


@ensure_integration_enabled(SanicIntegration)
def _capture_exception(exception: "Union[ExcInfo, BaseException]") -> None:
    with capture_internal_exceptions():
        event, hint = event_from_exception(
            exception,
            client_options=sentry_sdk.get_client().options,
            mechanism={"type": "sanic", "handled": False},
        )

        if hint and hasattr(hint["exc_info"][0], "quiet") and hint["exc_info"][0].quiet:
            return

        sentry_sdk.capture_event(event, hint=hint)


def _get_request_attributes(request: "Request") -> "Dict[str, Any]":
    """
    Return span attributes related to the HTTP request from a Sanic request.
    """
    attributes = {}  # type: Dict[str, Any]

    if request.method:
        attributes[SPANDATA.HTTP_REQUEST_METHOD] = request.method.upper()

    headers = _filter_headers(dict(request.headers), use_annotated_value=False)
    for header, value in headers.items():
        attributes[f"{SPANDATA.HTTP_REQUEST_HEADER}.{header.lower()}"] = value

    urlparts = urlsplit(request.url)

    if urlparts.query:
        attributes[SPANDATA.HTTP_QUERY] = urlparts.query

    attributes[SPANDATA.URL_FULL] = request.url

    if urlparts.scheme:
        attributes[SPANDATA.NETWORK_PROTOCOL_NAME] = urlparts.scheme

    if should_send_default_pii() and request.remote_addr:
        attributes[SPANDATA.CLIENT_ADDRESS] = request.remote_addr

    return attributes


def _make_request_processor(weak_request: "Callable[[], Request]") -> "EventProcessor":
    def sanic_processor(event: "Event", hint: "Optional[Hint]") -> "Optional[Event]":
        try:
            if hint and issubclass(hint["exc_info"][0], SanicException):
                return None
        except KeyError:
            pass

        request = weak_request()
        if request is None:
            return event

        with capture_internal_exceptions():
            extractor = SanicRequestExtractor(request)
            extractor.extract_into_event(event)

            request_info = event["request"]
            urlparts = urlsplit(request.url)

            request_info["url"] = "%s://%s%s" % (
                urlparts.scheme,
                urlparts.netloc,
                urlparts.path,
            )

            request_info["query_string"] = urlparts.query
            request_info["method"] = request.method
            request_info["env"] = {"REMOTE_ADDR": request.remote_addr}
            request_info["headers"] = _filter_headers(dict(request.headers))

        return event

    return sanic_processor


Current_dir [ 𝗡𝗢𝗧 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ] Document_root [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ]


[ Back ]
𝗡𝗔𝗠𝗘
𝗦𝗜𝗭𝗘
𝗟𝗔𝗦𝗧 𝗧𝗢𝗨𝗖𝗛
𝗨𝗦𝗘𝗥
𝗦𝗧𝗔𝗧𝗨𝗦
𝗙𝗨𝗡𝗖𝗧𝗜𝗢𝗡𝗦
..
--
11 Jun 2026 5.00 AM
root / root
0755
__pycache__
--
11 Jun 2026 5.00 AM
root / root
0755
celery
--
11 Jun 2026 5.00 AM
root / root
0755
django
--
11 Jun 2026 5.00 AM
root / root
0755
google_genai
--
11 Jun 2026 5.00 AM
root / root
0755
grpc
--
11 Jun 2026 5.00 AM
root / root
0755
openai_agents
--
11 Jun 2026 5.00 AM
root / root
0755
opentelemetry
--
11 Jun 2026 5.00 AM
root / root
0755
pydantic_ai
--
11 Jun 2026 5.00 AM
root / root
0755
redis
--
11 Jun 2026 5.00 AM
root / root
0755
spark
--
11 Jun 2026 5.00 AM
root / root
0755
__init__.py
12.511 KB
11 Jun 2026 5.00 AM
root / root
0644
_asgi_common.py
4.003 KB
11 Jun 2026 5.00 AM
root / root
0644
_wsgi_common.py
7.281 KB
11 Jun 2026 5.00 AM
root / root
0644
aiohttp.py
19.277 KB
11 Jun 2026 5.00 AM
root / root
0644
aiomysql.py
9.09 KB
11 Jun 2026 5.00 AM
root / root
0644
anthropic.py
39 KB
11 Jun 2026 5.00 AM
root / root
0644
argv.py
0.855 KB
11 Jun 2026 5.00 AM
root / root
0644
ariadne.py
5.698 KB
11 Jun 2026 5.00 AM
root / root
0644
arq.py
9.229 KB
11 Jun 2026 5.00 AM
root / root
0644
asgi.py
20.061 KB
11 Jun 2026 5.00 AM
root / root
0644
asyncio.py
9.275 KB
11 Jun 2026 5.00 AM
root / root
0644
asyncpg.py
9.68 KB
11 Jun 2026 5.00 AM
root / root
0644
atexit.py
1.509 KB
11 Jun 2026 5.00 AM
root / root
0644
aws_lambda.py
17.41 KB
11 Jun 2026 5.00 AM
root / root
0644
beam.py
4.907 KB
11 Jun 2026 5.00 AM
root / root
0644
boto3.py
6.198 KB
11 Jun 2026 5.00 AM
root / root
0644
bottle.py
7.208 KB
11 Jun 2026 5.00 AM
root / root
0644
chalice.py
4.506 KB
11 Jun 2026 5.00 AM
root / root
0644
clickhouse_driver.py
5.846 KB
11 Jun 2026 5.00 AM
root / root
0644
cloud_resource_context.py
7.488 KB
11 Jun 2026 5.00 AM
root / root
0644
cohere.py
10.44 KB
11 Jun 2026 5.00 AM
root / root
0644
dedupe.py
1.857 KB
11 Jun 2026 5.00 AM
root / root
0644
dramatiq.py
8.016 KB
11 Jun 2026 5.00 AM
root / root
0644
excepthook.py
2.249 KB
11 Jun 2026 5.00 AM
root / root
0644
executing.py
1.935 KB
11 Jun 2026 5.00 AM
root / root
0644
falcon.py
9.04 KB
11 Jun 2026 5.00 AM
root / root
0644
fastapi.py
5.281 KB
11 Jun 2026 5.00 AM
root / root
0644
flask.py
8.274 KB
11 Jun 2026 5.00 AM
root / root
0644
gcp.py
10.57 KB
11 Jun 2026 5.00 AM
root / root
0644
gnu_backtrace.py
2.724 KB
11 Jun 2026 5.00 AM
root / root
0644
gql.py
4.927 KB
11 Jun 2026 5.00 AM
root / root
0644
graphene.py
5.707 KB
11 Jun 2026 5.00 AM
root / root
0644
httpx.py
9.788 KB
11 Jun 2026 5.00 AM
root / root
0644
httpx2.py
9.804 KB
11 Jun 2026 5.00 AM
root / root
0644
huey.py
8.189 KB
11 Jun 2026 5.00 AM
root / root
0644
huggingface_hub.py
15.282 KB
11 Jun 2026 5.00 AM
root / root
0644
langchain.py
48.313 KB
11 Jun 2026 5.00 AM
root / root
0644
langgraph.py
18.125 KB
11 Jun 2026 5.00 AM
root / root
0644
launchdarkly.py
1.873 KB
11 Jun 2026 5.00 AM
root / root
0644
litellm.py
13.033 KB
11 Jun 2026 5.00 AM
root / root
0644
litestar.py
11.464 KB
11 Jun 2026 5.00 AM
root / root
0644
logging.py
15.692 KB
11 Jun 2026 5.00 AM
root / root
0644
loguru.py
6.352 KB
11 Jun 2026 5.00 AM
root / root
0644
mcp.py
23.121 KB
11 Jun 2026 5.00 AM
root / root
0644
modules.py
0.769 KB
11 Jun 2026 5.00 AM
root / root
0644
openai.py
53.385 KB
11 Jun 2026 5.00 AM
root / root
0644
openfeature.py
1.076 KB
11 Jun 2026 5.00 AM
root / root
0644
otlp.py
7.99 KB
11 Jun 2026 5.00 AM
root / root
0644
pure_eval.py
4.413 KB
11 Jun 2026 5.00 AM
root / root
0644
pymongo.py
8.212 KB
11 Jun 2026 5.00 AM
root / root
0644
pyramid.py
7.416 KB
11 Jun 2026 5.00 AM
root / root
0644
pyreqwest.py
6.824 KB
11 Jun 2026 5.00 AM
root / root
0644
quart.py
7.318 KB
11 Jun 2026 5.00 AM
root / root
0644
ray.py
5.747 KB
11 Jun 2026 5.00 AM
root / root
0644
rq.py
7.807 KB
11 Jun 2026 5.00 AM
root / root
0644
rust_tracing.py
9.436 KB
11 Jun 2026 5.00 AM
root / root
0644
sanic.py
15.252 KB
11 Jun 2026 5.00 AM
root / root
0644
serverless.py
1.583 KB
11 Jun 2026 5.00 AM
root / root
0644
socket.py
5.018 KB
11 Jun 2026 5.00 AM
root / root
0644
sqlalchemy.py
5.242 KB
11 Jun 2026 5.00 AM
root / root
0644
starlette.py
27.935 KB
11 Jun 2026 5.00 AM
root / root
0644
starlite.py
11.037 KB
11 Jun 2026 5.00 AM
root / root
0644
statsig.py
1.186 KB
11 Jun 2026 5.00 AM
root / root
0644
stdlib.py
14.007 KB
11 Jun 2026 5.00 AM
root / root
0644
strawberry.py
17.391 KB
11 Jun 2026 5.00 AM
root / root
0644
sys_exit.py
2.352 KB
11 Jun 2026 5.00 AM
root / root
0644
threading.py
6.875 KB
11 Jun 2026 5.00 AM
root / root
0644
tornado.py
10.789 KB
11 Jun 2026 5.00 AM
root / root
0644
trytond.py
1.675 KB
11 Jun 2026 5.00 AM
root / root
0644
typer.py
1.725 KB
11 Jun 2026 5.00 AM
root / root
0644
unleash.py
1.021 KB
11 Jun 2026 5.00 AM
root / root
0644
unraisablehook.py
1.654 KB
11 Jun 2026 5.00 AM
root / root
0644
wsgi.py
15.031 KB
11 Jun 2026 5.00 AM
root / root
0644

✘✘ GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME ✘✘
Static GIF Static GIF