当前位置: 首页>>代码示例>>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;未经允许,请勿转载。