From 3161319d0fe3feafe2b5fed48b9383680f9f0547 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 23 Oct 2020 00:06:50 -0700 Subject: basic test for issue-db pipeline --- fatcat_scholar/web.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'fatcat_scholar/web.py') diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py index f266e08..79b4f30 100644 --- a/fatcat_scholar/web.py +++ b/fatcat_scholar/web.py @@ -13,6 +13,7 @@ from fastapi.staticfiles import StaticFiles from fastapi.responses import PlainTextResponse import sentry_sdk from sentry_sdk.integrations.asgi import SentryAsgiMiddleware +from starlette_prometheus import metrics, PrometheusMiddleware from fatcat_scholar.config import settings, GIT_REVISION from fatcat_scholar.hacks import Jinja2Templates, parse_accept_lang @@ -26,16 +27,6 @@ I18N_LANG_OPTIONS = I18N_LANG_TRANSLATIONS + [ settings.I18N_LANG_DEFAULT, ] -# note the middleware also installed at the end of this file -if settings.SENTRY_DSN: - logger.info("Sentry integration enabled") - sentry_sdk.init( - dsn=settings.SENTRY_DSN, - environment=settings.SCHOLAR_ENV, - max_breadcrumbs=10, - release=GIT_REVISION, - ) - class LangPrefix: """ @@ -261,5 +252,19 @@ async def robots_txt(response_class: Any = PlainTextResponse) -> Any: else: return PlainTextResponse(ROBOTS_DISALLOW) -# add sentry middleware -app = SentryAsgiMiddleware(app) + +# configure middleware + +if settings.SENTRY_DSN: + logger.info("Sentry integration enabled") + sentry_sdk.init( + dsn=settings.SENTRY_DSN, + environment=settings.SCHOLAR_ENV, + max_breadcrumbs=10, + release=GIT_REVISION, + ) + app.add_middleware(SentryAsgiMiddleware) + +if settings.ENABLE_PROMETHEUS: + app.add_middleware(PrometheusMiddleware) + app.add_route("/prometheus/", metrics) -- cgit v1.2.3