示例#1
0
def _init(*args, **kwargs):
    # type: (*Optional[str], **Any) -> ContextManager[Any]
    """Initializes the SDK and optionally integrations.

    This takes the same arguments as the client constructor.
    """
    client = Client(*args, **kwargs)  # type: ignore
    Hub.current.bind_client(client)
    rv = _InitGuard(client)
    return rv
示例#2
0
def init(*args, **kwargs):
    """Initializes the SDK and optionally integrations.

    This takes the same arguments as the client constructor.
    """
    global _initial_client
    client = Client(*args, **kwargs)
    Hub.current.bind_client(client)
    rv = _InitGuard(client)
    if client is not None:
        _initial_client = weakref.ref(client)
    return rv
示例#3
0
    def send_message(self, message):

        sentry_client = Client(dsn=self.sentry_dsn,
                               environment=self.environment)

        with configure_scope() as scope:
            scope.set_tag("project_name", self.project_name)

            scope.set_extra("job_link", message.get("job_link", ""))
            scope.set_extra("spider_name", message.get("spider_name", ""))
            scope.set_extra("items_count", message.get("items_count", 0))

            scope.set_extra("passed_monitors_count",
                            message.get("passed_monitors_count", 0))
            scope.set_extra("failed_monitors_count",
                            message.get("failed_monitors_count", 0))

            scope.set_extra("failed_monitors",
                            message.get("failed_monitors", []))

            sentry_client.capture_event(
                {
                    "message":
                    "{title} \n {description}".format(
                        title=message.get("title"),
                        description=message.get("failure_reasons", ""),
                    ),
                    "level":
                    self.sentry_log_level,
                },
                scope=scope,
            )
        logger.info("Notification sent to the sentry dashboard!!")

        sentry_client.close()
示例#4
0
def init(*args, **kwargs):
    # type: (*str, **Any) -> ContextManager[Any]
    # TODO: https://github.com/getsentry/sentry-python/issues/272
    """Initializes the SDK and optionally integrations.

    This takes the same arguments as the client constructor.
    """
    global _initial_client
    client = Client(*args, **kwargs)
    Hub.current.bind_client(client)
    rv = _InitGuard(client)
    if client is not None:
        _initial_client = weakref.ref(client)
    return rv
示例#5
0
def test_exception_pass(monkeypatch):
    def check_event(event):
        assert len(
            event["exception"]["values"][0]["stacktrace"]["frames"]) == 12

    message_queue = multiprocessing.Queue()
    p = multiprocessing.Process(target=executor_fun, args=(message_queue, ))
    p.start()
    p.join()
    ex, event, _tr = message_queue.get()
    assert isinstance(ex, ValueError)
    assert isinstance(event, dict)
    client = Client("https://[email protected]/77")
    Hub.current.bind_client(client)
    monkeypatch.setattr(client.transport, "capture_event", check_event)
    event_id = sentry_sdk.capture_event(event)
    assert event_id is not None
示例#6
0
def test_sentry_report(monkeypatch):
    message = "a" * 5000
    happen = [False]

    def check_event(event):
        happen[0] = True
        assert len(event["message"]) == 512
        assert len(event["extra"]["lorem"]) == 512

    try:
        raise ValueError("eeee")
    except ValueError as e:
        event, hint = sentry_sdk.utils.event_from_exception(e)
        event["message"] = message
        client = Client("https://[email protected]/77")
        Hub.current.bind_client(client)
        monkeypatch.setattr(client.transport, "capture_event", check_event)
        with sentry_sdk.push_scope() as scope:
            scope.set_extra("lorem", message)
            sentry_sdk.capture_event(event, hint=hint)
        assert happen[0] is True
示例#7
0
from sentry_sdk.integrations.dedupe import DedupeIntegration
from sentry_sdk.integrations.stdlib import StdlibIntegration
from sentry_sdk.integrations.modules import ModulesIntegration
from sentry_sdk.integrations.argv import ArgvIntegration

from helpdesk.config import SENTRY_DSN

logger = logging.getLogger(__name__)

_client = Client(
    dsn=SENTRY_DSN,
    default_integrations=False,
    integrations=[
        ExcepthookIntegration(),
        DedupeIntegration(),
        StdlibIntegration(),
        ModulesIntegration(),
        ArgvIntegration(),
    ],
    max_breadcrumbs=5,
    attach_stacktrace=True,
)
_hub = Hub(_client)


def report(msg=None, **kw):
    if not _hub:
        return
    try:
        extra = kw.pop('extra', {})