Skip to content

Commit

Permalink
feat(api): Add glitchtip to API backend and worker to monitor excepti…
Browse files Browse the repository at this point in the history
…ons (#76)
  • Loading branch information
vvatelot authored May 15, 2024
1 parent 332b37c commit c0fdc46
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 270 deletions.
4 changes: 4 additions & 0 deletions bases/ecoindex/backend/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from ecoindex.backend import get_api_version
from ecoindex.backend.routers import router
from ecoindex.backend.services.cache import cache
from ecoindex.config import Settings
from ecoindex.database.engine import init_db
from fastapi import FastAPI
from fastapi.concurrency import asynccontextmanager
from sentry_sdk import init as sentry_init


def init_app():
cache.init()
if Settings().GLITCHTIP_DSN:
sentry_init(Settings().GLITCHTIP_DSN)

@asynccontextmanager
async def lifespan(app: FastAPI):
Expand Down
4 changes: 4 additions & 0 deletions bases/ecoindex/worker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
from ecoindex.scraper.scrap import EcoindexScraper
from ecoindex.worker_component import app
from playwright._impl._errors import Error as WebDriverException
from sentry_sdk import init as sentry_init

if Settings().GLITCHTIP_DSN:
sentry_init(Settings().GLITCHTIP_DSN)


@app.task(
Expand Down
2 changes: 2 additions & 0 deletions components/ecoindex/config/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
CORS_ALLOWED_CREDENTIALS: bool = True
CORS_ALLOWED_HEADERS: list = ["*"]
Expand All @@ -12,6 +13,7 @@ class Settings(BaseSettings):
ENABLE_SCREENSHOT: bool = False
EXCLUDED_HOSTS: list[str] = ["localhost", "127.0.0.1"]
FRONTEND_BASE_URL: str = "https://www.ecoindex.fr"
GLITCHTIP_DSN: str = ""
REDIS_CACHE_HOST: str = "localhost"
SCREENSHOTS_GID: int | None = None
SCREENSHOTS_UID: int | None = None
Expand Down
52 changes: 51 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions projects/ecoindex_api/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# EXCLUDED_HOSTS='["localhost","127.0.0.1"]'
# FLOWER_BASIC_AUTH=ecoindex:password
# FLOWER_PORT=5555
# GLITCHTIP_DSN=
# REDIS_CACHE_HOST=redis
# SCREENSHOTS_GID=1006
# SCREENSHOTS_UID=1006
Expand Down
1 change: 1 addition & 0 deletions projects/ecoindex_api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Here are the environment variables you can configure in your `.env` file:
| API | `EXCLUDED_HOSTS` | `["localhost", "127.0.0.1"]` | You can configure a list of hosts that will be excluded from the analysis. |
| API, Worker | `DAILY_LIMIT_PER_HOST` | 0 | When this variable is set, it won't be possible for a same host to make more request than defined in the same day to avoid overload. If the variable is set, you will get a header `x-remaining-daily-requests: 6` in your response. It is used for the POST methods. If you reach your authorized request quota for the day, the next requests will give you a 429 response. If the variable is set to 0, no limit is set |
| API, Worker | `DATABASE_URL` | `sqlite+aiosqlite:///./sql_app.db` | If you run your mysql instance on a dedicated server, you can configure it with your credentials. By default, it uses an sqlite database when running in local | |
| API, Worker | `GLITCHTIP_DSN` | `` | If you want to use [Glitchtip](https://glitchtip.com/) to monitor your application, you can set this variable with your DSN. |
| API, Worker, Flower | `REDIS_CACHE_HOST` | `localhost` | The hostname of the redis backend used by Celery but also API to cache results |
| API, Worker | `TZ` | `Europe/Paris` | The timezone used by the API and the worker. |
| Worker | `ENABLE_SCREENSHOT` | `False` | If screenshots are enabled, when analyzing the page the image will be generated in the `./screenshot` directory with the image name corresponding to the analysis ID and will be available on the path `/{version}/ecoindexes/{id}/screenshot` |
Expand Down
Loading

1 comment on commit c0fdc46

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage PR

Branch coverage •
FileStmtsMissCoverMissing
components/ecoindex/config
   settings.py210100% 
TOTAL69623066% 

Please sign in to comment.