當前位置: 首頁>>代碼示例>>Python>>正文


Python django.DjangoIntegration方法代碼示例

本文整理匯總了Python中sentry_sdk.integrations.django.DjangoIntegration方法的典型用法代碼示例。如果您正苦於以下問題:Python django.DjangoIntegration方法的具體用法?Python django.DjangoIntegration怎麽用?Python django.DjangoIntegration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sentry_sdk.integrations.django的用法示例。


在下文中一共展示了django.DjangoIntegration方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post_setup

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def post_setup(cls):
        """Post setup configuration.

        This is the place where you can configure settings that require other
        settings to be loaded.
        """
        super().post_setup()

        # The DJANGO_SENTRY_DSN environment variable should be set to activate
        # sentry for an environment
        if cls.SENTRY_DSN is not None:
            sentry_sdk.init(
                dsn=cls.SENTRY_DSN,
                environment=cls.ENVIRONMENT,
                release=cls.RELEASE,
                integrations=[DjangoIntegration()],
            )
            with sentry_sdk.configure_scope() as scope:
                scope.set_extra("application", "backend") 
開發者ID:openfun,項目名稱:marsha,代碼行數:21,代碼來源:settings.py

示例2: test_request_captured

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def test_request_captured(sentry_init, client, capture_events):
    sentry_init(integrations=[DjangoIntegration()], send_default_pii=True)
    events = capture_events()
    content, status, headers = client.get(reverse("message"))
    assert b"".join(content) == b"ok"

    (event,) = events
    assert event["transaction"] == "/message"
    assert event["request"] == {
        "cookies": {},
        "env": {"SERVER_NAME": "localhost", "SERVER_PORT": "80"},
        "headers": {"Host": "localhost"},
        "method": "GET",
        "query_string": "",
        "url": "http://localhost/message",
    } 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:18,代碼來源:test_basic.py

示例3: test_user_captured

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def test_user_captured(sentry_init, client, capture_events):
    sentry_init(integrations=[DjangoIntegration()], send_default_pii=True)
    events = capture_events()
    content, status, headers = client.get(reverse("mylogin"))
    assert b"".join(content) == b"ok"

    assert not events

    content, status, headers = client.get(reverse("message"))
    assert b"".join(content) == b"ok"

    (event,) = events

    assert event["user"] == {
        "email": "lennon@thebeatles.com",
        "username": "john",
        "id": "1",
    } 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:20,代碼來源:test_basic.py

示例4: test_custom_error_handler_request_context

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def test_custom_error_handler_request_context(sentry_init, client, capture_events):
    sentry_init(integrations=[DjangoIntegration()])
    events = capture_events()
    content, status, headers = client.post("/404")
    assert status.lower() == "404 not found"

    (event,) = events

    assert event["message"] == "not found"
    assert event["level"] == "error"
    assert event["request"] == {
        "env": {"SERVER_NAME": "localhost", "SERVER_PORT": "80"},
        "headers": {"Host": "localhost"},
        "method": "POST",
        "query_string": "",
        "url": "http://localhost/404",
    } 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:19,代碼來源:test_basic.py

示例5: test_sql_psycopg2_string_composition

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def test_sql_psycopg2_string_composition(sentry_init, capture_events, query):
    sentry_init(
        integrations=[DjangoIntegration()],
        send_default_pii=True,
        _experiments={"record_sql_params": True},
    )
    from django.db import connections

    if "postgres" not in connections:
        pytest.skip("postgres tests disabled")

    import psycopg2.sql

    sql = connections["postgres"].cursor()

    events = capture_events()
    with pytest.raises(ProgrammingError):
        sql.execute(query(psycopg2.sql), {"my_param": 10})

    capture_message("HI")

    (event,) = events
    crumb = event["breadcrumbs"][-1]
    assert crumb["message"] == ('SELECT %(my_param)s FROM "foobar"')
    assert crumb["data"]["db.params"] == {"my_param": 10} 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:27,代碼來源:test_basic.py

示例6: test_rest_framework_basic

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def test_rest_framework_basic(
    sentry_init, client, capture_events, capture_exceptions, ct, body, route
):
    pytest.importorskip("rest_framework")
    sentry_init(integrations=[DjangoIntegration()], send_default_pii=True)
    exceptions = capture_exceptions()
    events = capture_events()

    if ct == "application/json":
        client.post(
            reverse(route), data=json.dumps(body), content_type="application/json"
        )
    elif ct == "application/x-www-form-urlencoded":
        client.post(reverse(route), data=body)
    else:
        assert False

    (error,) = exceptions
    assert isinstance(error, ZeroDivisionError)

    (event,) = events
    assert event["exception"]["values"][0]["mechanism"]["type"] == "django"

    assert event["request"]["data"] == body
    assert event["request"]["headers"]["Content-Type"] == ct 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:27,代碼來源:test_basic.py

示例7: patch_channels_asgi_handler_impl

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def patch_channels_asgi_handler_impl(cls):
    # type: (Any) -> None
    old_app = cls.__call__

    async def sentry_patched_asgi_handler(self, receive, send):
        # type: (Any, Any, Any) -> Any
        if Hub.current.get_integration(DjangoIntegration) is None:
            return await old_app(self, receive, send)

        middleware = SentryAsgiMiddleware(
            lambda _scope: old_app.__get__(self, cls), unsafe_context_data=True
        )

        return await middleware(self.scope)(receive, send)

    cls.__call__ = sentry_patched_asgi_handler 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:18,代碼來源:asgi.py

示例8: post_setup

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def post_setup(cls):
        """Post setup configuration.
        This is the place where you can configure settings that require other
        settings to be loaded.
        """
        super().post_setup()

        # The SENTRY_DSN setting should be available to activate sentry for an environment
        if cls.SENTRY_DSN is not None:
            sentry_sdk.init(
                dsn=cls.SENTRY_DSN,
                environment=cls.ENVIRONMENT,
                release=cls.RELEASE,
                integrations=[DjangoIntegration()],
            )
            with sentry_sdk.configure_scope() as scope:
                scope.set_extra("application", "backend") 
開發者ID:openfun,項目名稱:richie,代碼行數:19,代碼來源:settings.py

示例9: test_sentry_initialized_from_envvar

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def test_sentry_initialized_from_envvar(self):
        """ The DSN for Sentry comes from config. """
        fake_dsn = 'https://hex-code@sentry.io/123446'

        with mock.patch.dict('os.environ', {'RAVEN_DSN': fake_dsn}):
            with mock.patch.object(settings.sentry_sdk, 'init') as init_sentry:
                self._fresh_settings_load()
        init_sentry.assert_called_once_with(
            fake_dsn,
            integrations=[mock.ANY, mock.ANY],  # Django & Celery, checked separately
            send_default_pii=True,
        )
        integrations = init_sentry.call_args_list[0][1]['integrations']

        self.assertTrue(isinstance(integrations[0], DjangoIntegration))
        self.assertTrue(isinstance(integrations[1], CeleryIntegration)) 
開發者ID:DavidCain,項目名稱:mitoc-trips,代碼行數:18,代碼來源:test_settings.py

示例10: test_view_exceptions

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def test_view_exceptions(sentry_init, client, capture_exceptions, capture_events):
    sentry_init(integrations=[DjangoIntegration()], send_default_pii=True)
    exceptions = capture_exceptions()
    events = capture_events()
    client.get(reverse("view_exc"))

    (error,) = exceptions
    assert isinstance(error, ZeroDivisionError)

    (event,) = events
    assert event["exception"]["values"][0]["mechanism"]["type"] == "django" 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:13,代碼來源:test_basic.py

示例11: test_middleware_exceptions

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def test_middleware_exceptions(sentry_init, client, capture_exceptions):
    sentry_init(integrations=[DjangoIntegration()], send_default_pii=True)
    exceptions = capture_exceptions()
    client.get(reverse("middleware_exc"))

    (error,) = exceptions
    assert isinstance(error, ZeroDivisionError) 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:9,代碼來源:test_basic.py

示例12: test_transaction_with_class_view

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def test_transaction_with_class_view(sentry_init, client, capture_events):
    sentry_init(
        integrations=[DjangoIntegration(transaction_style="function_name")],
        send_default_pii=True,
    )
    events = capture_events()
    content, status, headers = client.head(reverse("classbased"))
    assert status.lower() == "200 ok"

    (event,) = events

    assert (
        event["transaction"] == "tests.integrations.django.myapp.views.ClassBasedView"
    )
    assert event["message"] == "hi" 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:17,代碼來源:test_basic.py

示例13: test_500

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def test_500(sentry_init, client, capture_events):
    sentry_init(integrations=[DjangoIntegration()], send_default_pii=True)
    events = capture_events()

    content, status, headers = client.get("/view-exc")
    assert status.lower() == "500 internal server error"
    content = b"".join(content).decode("utf-8")

    (event,) = events
    event_id = event["event_id"]
    assert content == "Sentry error: %s" % event_id 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:13,代碼來源:test_basic.py

示例14: test_sql_queries

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def test_sql_queries(sentry_init, capture_events, with_integration):
    sentry_init(
        integrations=[DjangoIntegration()] if with_integration else [],
        send_default_pii=True,
        _experiments={"record_sql_params": True},
    )

    from django.db import connection

    sentry_init(
        integrations=[DjangoIntegration()],
        send_default_pii=True,
        _experiments={"record_sql_params": True},
    )

    events = capture_events()

    sql = connection.cursor()

    with pytest.raises(OperationalError):
        # table doesn't even exist
        sql.execute("""SELECT count(*) FROM people_person WHERE foo = %s""", [123])

    capture_message("HI")

    (event,) = events

    if with_integration:
        crumb = event["breadcrumbs"][-1]

        assert crumb["message"] == "SELECT count(*) FROM people_person WHERE foo = %s"
        assert crumb["data"]["db.params"] == [123] 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:34,代碼來源:test_basic.py

示例15: test_sql_dict_query_params

# 需要導入模塊: from sentry_sdk.integrations import django [as 別名]
# 或者: from sentry_sdk.integrations.django import DjangoIntegration [as 別名]
def test_sql_dict_query_params(sentry_init, capture_events):
    sentry_init(
        integrations=[DjangoIntegration()],
        send_default_pii=True,
        _experiments={"record_sql_params": True},
    )

    from django.db import connections

    if "postgres" not in connections:
        pytest.skip("postgres tests disabled")

    sql = connections["postgres"].cursor()

    events = capture_events()
    with pytest.raises(ProgrammingError):
        sql.execute(
            """SELECT count(*) FROM people_person WHERE foo = %(my_foo)s""",
            {"my_foo": 10},
        )

    capture_message("HI")
    (event,) = events

    crumb = event["breadcrumbs"][-1]
    assert crumb["message"] == (
        "SELECT count(*) FROM people_person WHERE foo = %(my_foo)s"
    )
    assert crumb["data"]["db.params"] == {"my_foo": 10} 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:31,代碼來源:test_basic.py


注:本文中的sentry_sdk.integrations.django.DjangoIntegration方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。