-
Notifications
You must be signed in to change notification settings - Fork 554
(2) Move capture_*
from Hub to Client
#2555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
f2a4a3a
4869365
e5f9e9d
a338099
d900a1b
0afb3ab
fe77d04
4ba7dce
b15613a
8331bd0
ce1759f
9a08b6e
f9b8d5a
d233ae5
2932adc
3a7af73
345c419
bb3250a
3a22dd6
c78b1f5
0901e72
269fd56
0354065
3d5825e
4e78d1f
ba72216
c5a7ae7
bbb93e6
12e632d
eb56a12
074a9ef
6733114
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
from importlib import import_module | ||
import os | ||
import sys | ||
import uuid | ||
import random | ||
import socket | ||
|
||
from sentry_sdk._compat import datetime_utcnow, string_types, text_type, iteritems | ||
from sentry_sdk.scope import _update_scope | ||
from sentry_sdk.utils import ( | ||
capture_internal_exceptions, | ||
current_stacktrace, | ||
disable_capture_event, | ||
event_from_exception, | ||
exc_info_from_error, | ||
format_timestamp, | ||
get_sdk_name, | ||
get_type_name, | ||
|
@@ -48,7 +52,7 @@ | |
|
||
from sentry_sdk.integrations import Integration | ||
from sentry_sdk.scope import Scope | ||
from sentry_sdk._types import Event, Hint | ||
from sentry_sdk._types import Event, ExcInfo, Hint | ||
from sentry_sdk.session import Session | ||
|
||
|
||
|
@@ -544,6 +548,8 @@ def capture_event( | |
event, # type: Event | ||
hint=None, # type: Optional[Hint] | ||
scope=None, # type: Optional[Scope] | ||
top_scope=None, # type: Optional[Scope] | ||
**scope_kwargs # type: Any | ||
): | ||
# type: (...) -> Optional[str] | ||
"""Captures an event. | ||
|
@@ -552,14 +558,21 @@ def capture_event( | |
|
||
: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. | ||
|
||
:param scope: An optional scope to use for determining whether this event | ||
should be captured. | ||
:param scope: An optional scope to use for determining whether this event should be captured. | ||
|
||
:param top_scope: An optional top scope that should also be merged into the scope to be applied to the event. | ||
|
||
:param scope_kwargs: For supported `**scope_kwargs` see | ||
:py:meth:`sentry_sdk.Scope.update_from_kwargs`. | ||
|
||
: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): | ||
return None | ||
|
||
if scope_kwargs is not None and top_scope is not None: | ||
scope = _update_scope(top_scope, scope, scope_kwargs) | ||
|
||
if hint is None: | ||
hint = {} | ||
event_id = event.get("event_id") | ||
|
@@ -647,6 +660,89 @@ def capture_event( | |
|
||
return event_id | ||
|
||
def capture_message( | ||
self, | ||
message, # type: str | ||
level=None, # type: Optional[str] | ||
scope=None, # type: Optional[Scope] | ||
top_scope=None, # type: Optional[Scope] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not add If you see the RFC, the 3 scopes will be processed by The managing of the scopes is currently done by the Hub and will be moved to Scope later. I think the client should just get one scope as before and the merging will be moved later from Hub -> Scope. |
||
**scope_kwargs # type: Any | ||
): | ||
# type: (...) -> Optional[str] | ||
""" | ||
Captures a message. | ||
|
||
:param message: The string to send as the message. | ||
|
||
:param level: If no level is provided, the default level is `info`. | ||
|
||
:param scope: An optional :py:class:`sentry_sdk.Scope` to use. | ||
|
||
:param top_scope: An optional top scope that should also be merged into the scope to be applied to the event. | ||
|
||
:param scope_kwargs: For supported `**scope_kwargs` see | ||
:py:meth:`sentry_sdk.Scope.update_from_kwargs`. | ||
|
||
:returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.Client.capture_event`). | ||
""" | ||
if level is None: | ||
level = "info" | ||
|
||
return self.capture_event( | ||
{"message": message, "level": level}, | ||
scope=scope, | ||
top_scope=top_scope, | ||
**scope_kwargs | ||
) | ||
|
||
def capture_exception( | ||
self, | ||
error=None, # type: Optional[Union[BaseException, ExcInfo]] | ||
scope=None, # type: Optional[Scope] | ||
top_scope=None, # type: Optional[Scope] | ||
**scope_kwargs # type: Any | ||
): | ||
# type: (...) -> Optional[str] | ||
"""Captures an exception. | ||
|
||
:param error: An exception to catch. If `None`, `sys.exc_info()` will be used. | ||
|
||
:param scope: An optional :py:class:`sentry_sdk.Scope` to use. | ||
|
||
:param top_scope: An optional top scope that should also be merged into the scope to be applied to the event. | ||
|
||
:param scope_kwargs: For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`. | ||
|
||
:returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.Client.capture_event`). | ||
""" | ||
if error is not None: | ||
exc_info = exc_info_from_error(error) | ||
else: | ||
exc_info = sys.exc_info() | ||
|
||
event, hint = event_from_exception(exc_info, client_options=self.options) | ||
|
||
try: | ||
return self.capture_event( | ||
event, hint=hint, scope=scope, top_scope=top_scope, **scope_kwargs | ||
) | ||
except Exception: | ||
self._capture_internal_exception(sys.exc_info()) | ||
|
||
return None | ||
|
||
def _capture_internal_exception( | ||
self, exc_info # type: Any | ||
): | ||
# type: (...) -> Any | ||
""" | ||
Capture an exception that is likely caused by a bug in the SDK | ||
itself. | ||
|
||
These exceptions do not end up in Sentry and are just logged instead. | ||
""" | ||
logger.error("Internal error in sentry_sdk", exc_info=exc_info) | ||
|
||
def capture_session( | ||
self, session # type: Session | ||
): | ||
|
Uh oh!
There was an error while loading. Please reload this page.