def get_app(tracer=None): # initialize a traced Falcon application middleware = [TraceMiddleware(tracer)] if tracer else [] app = falcon.API(middleware=middleware) # add resource routing app.add_route('/200', resources.Resource200()) app.add_route('/201', resources.Resource201()) app.add_route('/500', resources.Resource500()) app.add_route('/exception', resources.ResourceException()) app.add_route('/not_found', resources.ResourceNotFound()) return app
def get_app(tracer=None, distributed_tracing=None): # initialize a traced Falcon application middleware = [ TraceMiddleware(tracer, distributed_tracing=distributed_tracing) ] if tracer else [] app = falcon.API(middleware=middleware) # add resource routing app.add_route("/200", resources.Resource200()) app.add_route("/201", resources.Resource201()) app.add_route("/500", resources.Resource500()) app.add_route("/exception", resources.ResourceException()) app.add_route("/not_found", resources.ResourceNotFound()) return app
def setUp(self): self._tracer = Tracer() self._writer = DummyWriter() self._tracer.writer = self._writer self._service = "my-falcon" self.api = falcon.API(middleware=[TraceMiddleware(self._tracer, self._service)]) resources = [ Resource200, Resource500, ResourceExc, ] for r in resources: self.api.add_route(r.ROUTE, r())
class Resource500(object): BODY = "noo" ROUTE = "/500" def on_get(self, req, resp, **kwargs): resp.status = falcon.HTTP_500 resp.body = self.BODY class ResourceExc(object): ROUTE = "/exc" def on_get(self, req, resp, **kwargs): raise Exception("argh") # run the thing trace_middleware = TraceMiddleware(tracer, 'my-falcon-app') app = falcon.API(middleware=[trace_middleware]) resources = [ Resource200, Resource500, ResourceExc, ] for r in resources: app.add_route(r.ROUTE, r())
def test_500(self): out = self.simulate_get(Resource500.ROUTE) eq_(out.status_code, 500) eq_(out.content.decode('utf-8'), Resource500.BODY) spans = self._writer.pop() eq_(len(spans), 1) span = spans[0] eq_(span.service, self._service) eq_(span.resource, "GET tests.contrib.falcon.test.Resource500") eq_(span.get_tag(httpx.STATUS_CODE), '500') eq_(span.name, "falcon.request") if __name__ == '__main__': mt = TraceMiddleware(Tracer()) app = falcon.API(middleware=[mt]) resources = [ Resource200, Resource500, ResourceExc, ] for r in resources: app.add_route(r.ROUTE, r()) port = 8000 httpd = simple_server.make_server('127.0.0.1', port, app) routes = [r.ROUTE for r in resources] print('running test app on %s. routes: %s' % (port, ' '.join(routes))) httpd.serve_forever()