Skip to content

Commit

Permalink
Sentry Monitoring (#75)
Browse files Browse the repository at this point in the history
* loading sentry dsn from env file

* only call init on sentry sdk if enabled

* removed sentry debug endpoint
  • Loading branch information
fullerzz authored Sep 29, 2024
1 parent 4699e3e commit 309502d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies = [
"hypercorn>=0.17.3",
"pyjwt[crypto]>=2.9.0",
"bcrypt>=4.2.0",
"sentry-sdk[fastapi]>=2.14.0",
]

[build-system]
Expand Down
2 changes: 2 additions & 0 deletions src/smolvault/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Settings(BaseSettings):
user_whitelist: str
users_limit: int
daily_upload_limit_bytes: int
sentry_enabled: bool
sentry_dsn: str

model_config = SettingsConfigDict(env_file=".env")

Expand Down
10 changes: 9 additions & 1 deletion src/smolvault/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from logging.handlers import RotatingFileHandler
from typing import Annotated

import sentry_sdk
from fastapi import BackgroundTasks, Depends, FastAPI, File, Form, HTTPException, UploadFile
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware
Expand All @@ -31,6 +32,14 @@
)
logger = logging.getLogger(__name__)

settings: Settings = get_settings()
if settings.sentry_enabled:
sentry_sdk.init(
dsn=settings.sentry_dsn,
traces_sample_rate=1.0, # Set traces_sample_rate to 1.0 to capture 100%
profiles_sample_rate=1.0,
)

app = FastAPI(title="smolvault", docs_url=None, redoc_url=None)

app.add_middleware(GZipMiddleware, minimum_size=1000)
Expand All @@ -43,7 +52,6 @@
)


settings: Settings = get_settings()
s3_client = S3Client(bucket_name=settings.smolvault_bucket)
cache = CacheManager(cache_dir=settings.smolvault_cache)

Expand Down
2 changes: 2 additions & 0 deletions tests/testing.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ SMOLVAULT_CACHE="./uploads/"
USER_WHITELIST="1,2"
USERS_LIMIT="3"
DAILY_UPLOAD_LIMIT_BYTES="50000"
SENTRY_ENABLED="false"
SENTRY_DSN="none"
20 changes: 20 additions & 0 deletions uv.lock

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

0 comments on commit 309502d

Please sign in to comment.