for key, value in iteritems(options): if key notin rv: raise TypeError("Unknown option %r" % (key,))
rv[key] = value
if rv["dsn"] isNone:
rv["dsn"] = os.environ.get("SENTRY_DSN")
if rv["release"] isNone:
rv["release"] = os.environ.get("SENTRY_RELEASE")
if rv["environment"] isNone:
rv["environment"] = os.environ.get("SENTRY_ENVIRONMENT")
if rv["server_name"] isNoneand hasattr(socket, "gethostname"):
rv["server_name"] = socket.gethostname()
return rv
class _Client(object): """The client is internally responsible for capturing the events and
forwarding them to sentry through the configured transport. It takes
the client options as keyword arguments and optionally the DSN as first
argument. """
def _send_sessions(sessions): # type: (List[Any]) -> None
transport = self.transport if sessions and transport:
envelope = Envelope() for session in sessions:
envelope.add_session(session)
transport.capture_envelope(envelope)
request_bodies = ("always", "never", "small", "medium") if self.options["request_bodies"] notin request_bodies: raise ValueError( "Invalid value for request_bodies. Must be one of {}".format(
request_bodies
)
)
for errcls in self.options["ignore_errors"]: # String types are matched against the type name in the # exception only if isinstance(errcls, string_types): if errcls == full_name or errcls == type_name: returnTrue else: if issubclass(exc_info[0], errcls): returnTrue
# Figure out if this counts as an error and if we should mark the # session as crashed.
level = event.get("level") if level == "fatal":
crashed = True ifnot crashed:
exceptions = (event.get("exception") or {}).get("values") if exceptions:
errored = True for error in exceptions:
mechanism = error.get("mechanism") if mechanism and mechanism.get("handled") isFalse:
crashed = True break
user = event.get("user")
if session.user_agent isNone:
headers = (event.get("request") or {}).get("headers") for (k, v) in iteritems(headers or {}): if k.lower() == "user-agent":
user_agent = v break
:param event: A ready-made event that can be directly sent to Sentry.
:param hint: Contains metadata about the event that can be read from `before_send`, such as the original exception object or a HTTP request object.
:returns: An event ID. May be `None` if there is no DSN set or of if the SDK decided to discard the event for other reasons. In such situations setting `debug=True` on `init()` may help. """ if disable_capture_event.get(False): returnNone
if self.transport isNone: returnNone if hint isNone:
hint = {}
event_id = event.get("event_id") if event_id isNone:
event["event_id"] = event_id = uuid.uuid4().hex ifnot self._should_capture(event, hint, scope): returnNone
event_opt = self._prepare_event(event, hint, scope) if event_opt isNone: returnNone
# whenever we capture an event we also check if the session needs # to be updated based on that information.
session = scope._session if scope elseNone if session:
self._update_session_from_event(session, event)
def close(
self,
timeout=None, # type: Optional[float]
callback=None, # type: Optional[Callable[[int, float], None]]
): # type: (...) -> None """
Close the client and shut down the transport. Arguments have the same
semantics as :py:meth:`Client.flush`. """ if self.transport isnotNone:
self.flush(timeout=timeout, callback=callback)
self.session_flusher.kill()
self.transport.kill()
self.transport = None
def flush(
self,
timeout=None, # type: Optional[float]
callback=None, # type: Optional[Callable[[int, float], None]]
): # type: (...) -> None """
Wait for the current events to be sent.
:param timeout: Wait for at most `timeout` seconds. If no `timeout` is provided, the `shutdown_timeout` option value is used.
:param callback: Is invoked with the number of pending events and the configured timeout. """ if self.transport isnotNone: if timeout isNone:
timeout = self.options["shutdown_timeout"]
self.session_flusher.flush()
self.transport.flush(timeout=timeout, callback=callback)
if MYPY: # Make mypy, PyCharm and other static analyzers think `get_options` is a # type to have nicer autocompletion for params. # # Use `ClientConstructor` to define the argument types of `init` and # `Dict[str, Any]` to tell static analyzers about the return type.
class get_options(ClientConstructor, Dict[str, Any]): # noqa: N801 pass
class Client(ClientConstructor, _Client): pass
else: # Alias `get_options` for actual usage. Go through the lambda indirection # to throw PyCharm off of the weakly typed signature (it would otherwise # discover both the weakly typed signature of `_init` and our faked `init` # type).
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 und die Messung sind noch experimentell.