|
| 1 | +import os |
| 2 | + |
| 3 | +import sentry_sdk |
| 4 | +from pyramid.config import Configurator |
| 5 | +from pyramid.response import Response |
| 6 | +from waitress import serve |
| 7 | + |
| 8 | +sentry_sdk.init( |
| 9 | + dsn=os.environ.get("SENTRY_DSN"), |
| 10 | + environment=os.environ.get("ENV", "test"), |
| 11 | + traces_sample_rate=1.0, |
| 12 | + profiles_sample_rate=1.0, |
| 13 | + debug=True, |
| 14 | + _experiments={"trace_lifecycle": "stream"}, |
| 15 | +) |
| 16 | + |
| 17 | + |
| 18 | +def index(request): |
| 19 | + return Response("Hello from Pyramid!") |
| 20 | + |
| 21 | + |
| 22 | +def error(request): |
| 23 | + raise ValueError("help! an error!") |
| 24 | + |
| 25 | + |
| 26 | +def message(request): |
| 27 | + name = request.matchdict.get("name", "World") |
| 28 | + return Response(f"Hello, {name}!") |
| 29 | + |
| 30 | + |
| 31 | +def create_app(): |
| 32 | + with Configurator() as config: |
| 33 | + config.add_route("index", "/") |
| 34 | + config.add_view(index, route_name="index") |
| 35 | + |
| 36 | + config.add_route("error", "/error") |
| 37 | + config.add_view(error, route_name="error") |
| 38 | + |
| 39 | + config.add_route("message", "/message/{name}") |
| 40 | + config.add_view(message, route_name="message") |
| 41 | + |
| 42 | + app = config.make_wsgi_app() |
| 43 | + |
| 44 | + return app |
| 45 | + |
| 46 | + |
| 47 | +if __name__ == "__main__": |
| 48 | + app = create_app() |
| 49 | + print("Serving on http://localhost:8000") |
| 50 | + serve(app, host="0.0.0.0", port=8000) |
0 commit comments