def test_middleware_exception(self): """Ensure exceptions raised in middleware are properly handled. Uncaught exceptions should result in error tagged spans. """ from .app.middleware import ExceptionMiddleware wsgiapp = ExceptionMiddleware(self._wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service="web") app = fixture.TestApp(app) with pytest.raises(Exception): app.get(url_for(controller="root", action="index")) spans = self.pop_spans() assert spans, spans assert len(spans) == 1 span = spans[0] assert_is_measured(span) assert span.service == "web" assert span.resource == "None.None" assert span.error == 1 assert span.get_tag(http.URL) == "http://localhost:80/" assert_span_http_status_code(span, 500) assert span.get_tag(errors.ERROR_MSG) == "Middleware exception" assert span.get_tag(errors.ERROR_TYPE) == "exceptions.Exception" assert span.get_tag(errors.ERROR_STACK)
def test_mw_exc_success(self): """Ensure exceptions can be properly handled by other middleware. No error should be reported in the span. """ from .app.middleware import ExceptionMiddleware from .app.middleware import ExceptionToSuccessMiddleware wsgiapp = ExceptionMiddleware(self._wsgiapp) wsgiapp = ExceptionToSuccessMiddleware(wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service="web") app = fixture.TestApp(app) app.get(url_for(controller="root", action="index")) spans = self.pop_spans() assert spans, spans assert len(spans) == 1 span = spans[0] assert_is_measured(span) assert span.service == "web" assert span.resource == "None.None" assert span.error == 0 assert span.get_tag(http.URL) == "http://localhost:80/" assert_span_http_status_code(span, 200) assert span.get_tag(errors.ERROR_MSG) is None assert span.get_tag(errors.ERROR_TYPE) is None assert span.get_tag(errors.ERROR_STACK) is None
def test_controller_exception(self): """Ensure exceptions thrown in controllers can be handled. No error tags should be set in the span. """ from .app.middleware import ExceptionToSuccessMiddleware wsgiapp = ExceptionToSuccessMiddleware(self._wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service="web") app = fixture.TestApp(app) app.get(url_for(controller="root", action="raise_exception")) spans = self.pop_spans() assert spans, spans assert len(spans) == 1 span = spans[0] assert_is_measured(span) assert span.service == "web" assert span.resource == "root.raise_exception" assert span.error == 0 assert span.get_tag(http.URL) == "http://localhost:80/raise_exception" assert_span_http_status_code(span, 200) assert http.QUERY_STRING not in span.meta assert span.get_tag(errors.ERROR_MSG) is None assert span.get_tag(errors.ERROR_TYPE) is None assert span.get_tag(errors.ERROR_STACK) is None assert span.span_type == "web"
def test_set_tag_measured_change_value(): s = Span(tracer=None, name="test.span") s.set_tag(SPAN_MEASURED_KEY, True) assert_is_measured(s) s.set_tag(SPAN_MEASURED_KEY, False) assert_is_not_measured(s) s.set_tag(SPAN_MEASURED_KEY) assert_is_measured(s)
def test_success_200(self, query_string=""): if query_string: fqs = "?" + query_string else: fqs = "" res = self.app.get(url_for(controller="root", action="index") + fqs) assert res.status == 200 spans = self.pop_spans() assert spans, spans assert len(spans) == 1 span = spans[0] assert_is_measured(span) assert span.service == "web" assert span.resource == "root.index" assert_span_http_status_code(span, 200) if config.pylons.trace_query_string: assert span.meta.get(http.QUERY_STRING) == query_string else: assert http.QUERY_STRING not in span.meta assert span.error == 0
def test_exc_success(self): from .app.middleware import ExceptionToSuccessMiddleware wsgiapp = ExceptionToSuccessMiddleware(self._wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service="web") app = fixture.TestApp(app) app.get(url_for(controller="root", action="raise_exception")) spans = self.pop_spans() assert spans, spans assert len(spans) == 1 span = spans[0] assert_is_measured(span) assert span.service == "web" assert span.resource == "root.raise_exception" assert span.error == 0 assert span.get_tag(http.URL) == "http://localhost:80/raise_exception" assert_span_http_status_code(span, 200) assert span.get_tag(errors.ERROR_MSG) is None assert span.get_tag(errors.ERROR_TYPE) is None assert span.get_tag(errors.ERROR_STACK) is None
def test_set_tag_measured_no_value(): s = Span(tracer=None, name="test.span") s.set_tag(SPAN_MEASURED_KEY) assert_is_measured(s)