Esempio n. 1
0
    def test_traceparent_header_wsgi(self):
        # Assert that posting something to store will not create another
        # (transaction) event under any circumstances.
        #
        # We use Werkzeug's test client because Django's test client bypasses a
        # lot of request handling code that we want to test implicitly (such as
        # all our WSGI middlewares and the entire Django instrumentation by
        # sentry-sdk).
        #
        # XXX(markus): Ideally methods such as `_postWithHeader` would always
        # call the WSGI application => swap out Django's test client with e.g.
        # Werkzeug's.
        client = WerkzeugClient(application)

        calls = []

        def new_disable_transaction_events():
            with configure_scope() as scope:
                assert scope.span.sampled
                assert scope.span.transaction
                disable_transaction_events()
                assert not scope.span.sampled

            calls.append(1)

        events = []

        auth = get_auth_header("_postWithWerkzeug/0.0.0",
                               self.projectkey.public_key,
                               self.projectkey.secret_key, "7")

        with mock.patch("sentry.web.api.disable_transaction_events",
                        new_disable_transaction_events):
            with self.tasks():
                with Hub(
                        Client(
                            transport=events.append,
                            integrations=[
                                CeleryIntegration(),
                                DjangoIntegration()
                            ],
                        )):
                    app_iter, status, headers = client.post(
                        reverse("sentry-api-store"),
                        data=b'{"message": "hello"}',
                        headers={
                            "x-sentry-auth": auth,
                            "sentry-trace": "1",
                            "content-type": "application/octet-stream",
                        },
                        environ_base={"REMOTE_ADDR": "127.0.0.1"},
                    )

                    body = "".join(app_iter)

        assert status == "200 OK", body
        assert set(
            (e.get("type"), e.get("transaction"))
            for e in events) == {("transaction", "rule_processor_apply")}
        assert calls == [1]
Esempio n. 2
0
    def test_traceparent_header_wsgi(self):
        # Assert that posting something to store will not create another
        # (transaction) event under any circumstances.
        #
        # We use Werkzeug's test client because Django's test client bypasses a
        # lot of request handling code that we want to test implicitly (such as
        # all our WSGI middlewares and the entire Django instrumentation by
        # sentry-sdk).
        #
        # XXX(markus): Ideally methods such as `_postWithHeader` would always
        # call the WSGI application => swap out Django's test client with e.g.
        # Werkzeug's.
        client = WerkzeugClient(application)

        calls = []

        def new_disable_transaction_events():
            with configure_scope() as scope:
                assert scope.span.sampled
                assert scope.span.transaction
                disable_transaction_events()
                assert not scope.span.sampled

            calls.append(1)

        events = []

        auth = get_auth_header('_postWithWerkzeug/0.0.0',
                               self.projectkey.public_key,
                               self.projectkey.secret_key, '7')

        with mock.patch('sentry.web.api.disable_transaction_events',
                        new_disable_transaction_events):
            with self.tasks():
                with Hub(
                        Client(transport=events.append,
                               integrations=[
                                   CeleryIntegration(),
                                   DjangoIntegration()
                               ])):
                    app_iter, status, headers = client.post(
                        reverse('sentry-api-store'),
                        data=b'{"message": "hello"}',
                        headers={
                            'x-sentry-auth': auth,
                            'sentry-trace': '1',
                            'content-type': 'application/octet-stream',
                        },
                        environ_base={'REMOTE_ADDR': '127.0.0.1'})

                    body = ''.join(app_iter)

        assert status == '200 OK', body
        assert not events
        assert calls == [1]