import os import sys import linecache import logging
from datetime import datetime
import sentry_sdk from sentry_sdk._compat import urlparse, text_type, implements_str, PY2
from sentry_sdk._types import MYPY
if MYPY: from types import FrameType from types import TracebackType from typing import Any from typing import Callable from typing import Dict from typing import ContextManager from typing import Iterator from typing import List from typing import Optional from typing import Set from typing import Tuple from typing import Union from typing import Type
from sentry_sdk._types import ExcInfo
epoch = datetime(1970, 1, 1)
# The logger is created here but initialized in the debug support module
logger = logging.getLogger("sentry_sdk.errors")
try:
pre_context = [
strip_string(line.strip("\r\n")) for line in source[lower_bound:lineno]
]
context_line = strip_string(source[lineno].strip("\r\n"))
post_context = [
strip_string(line.strip("\r\n")) for line in source[(lineno + 1) : upper_bound]
] return pre_context, context_line, post_context except IndexError: # the file may have changed since it was loaded into memory return [], None, []
# At this point `rv` contains a bunch of literal escape codes, like # this (exaggerated example): # # u"\\x2f" # # But we want to show this string as: # # u"/" try: # unicode-escape does this job, but can only decode latin1. So we # attempt to encode in latin1. return rv.encode("latin1").decode("unicode-escape") except Exception: # Since usually strings aren't latin1 this can break. In those # cases we just give up. return rv except Exception: # If e.g. the call to `repr` already fails return u""
f = sys._getframe() # type: Optional[FrameType] while f isnotNone: ifnot should_hide_frame(f):
frames.append(serialize_frame(f, with_locals=with_locals))
f = f.f_back
while (
exc_type isnotNone and exc_value isnotNone and id(exc_value) notin seen_exception_ids
): yield exc_type, exc_value, tb
# Avoid hashing random types we don't know anything # about. Use the list to keep a ref so that the `id` is # not used for another object.
seen_exceptions.append(exc_value)
seen_exception_ids.add(id(exc_value))
if exc_value.__suppress_context__:
cause = exc_value.__cause__ else:
cause = exc_value.__context__ if cause isNone: break
exc_type = type(cause)
exc_value = cause
tb = getattr(cause, "__traceback__", None)
def iter_event_stacktraces(event): # type: (Dict[str, Any]) -> Iterator[Dict[str, Any]] if"stacktrace"in event: yield event["stacktrace"] if"threads"in event: for thread in event["threads"].get("values") or (): if"stacktrace"in thread: yield thread["stacktrace"] if"exception"in event: for exception in event["exception"].get("values") or (): if"stacktrace"in exception: yield exception["stacktrace"]
def iter_event_frames(event): # type: (Dict[str, Any]) -> Iterator[Dict[str, Any]] for stacktrace in iter_event_stacktraces(event): for frame in stacktrace.get("frames") or (): yield frame
def _module_in_set(name, set): # type: (str, Optional[List[str]]) -> bool ifnot set: returnFalse for item in set or (): if item == name or name.startswith(item + "."): returnTrue returnFalse
def strip_string(value, max_length=None): # type: (str, Optional[int]) -> Union[AnnotatedValue, str] # TODO: read max_length from config ifnot value: return value
if max_length isNone: # This is intentionally not just the default such that one can patch `MAX_STRING_LENGTH` and affect `strip_string`.
max_length = MAX_STRING_LENGTH
if is_object_patched("threading", "local"): returnTrue except ImportError: pass
try: from eventlet.patcher import is_monkey_patched # type: ignore
if is_monkey_patched("thread"): returnTrue except ImportError: pass
returnFalse
def _get_contextvars(): # type: () -> Tuple[bool, type] """ Try to import contextvars and use it if it's deemed safe. We should not use
contextvars if gevent or eventlet have patched thread locals, as
contextvars are unaffected by that patch.
https://github.com/gevent/gevent/issues/1407 """ ifnot _is_threading_local_monkey_patched(): # aiocontextvars is a PyPI package that ensures that the contextvars # backport (also a PyPI package) works with asyncio under Python 3.6 # # Import it if available. ifnot PY2 and sys.version_info < (3, 7): try: from aiocontextvars import ContextVar # noqa
returnTrue, ContextVar except ImportError: pass
try: from contextvars import ContextVar
returnTrue, ContextVar except ImportError: pass
from threading import local
class ContextVar(object): # Super-limited impl of ContextVar
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.