Skip to content

Commit

Permalink
loading sentry dsn from env file
Browse files Browse the repository at this point in the history
  • Loading branch information
fullerzz committed Sep 29, 2024
1 parent 4699e3e commit 513f601
Show file tree
Hide file tree
Showing 4 changed files with 36 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
1 change: 1 addition & 0 deletions src/smolvault/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Settings(BaseSettings):
user_whitelist: str
users_limit: int
daily_upload_limit_bytes: int
sentry_dsn: str

model_config = SettingsConfigDict(env_file=".env")

Expand Down
15 changes: 14 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,13 @@
)
logger = logging.getLogger(__name__)

settings: Settings = get_settings()
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 +51,6 @@
)


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

Expand Down Expand Up @@ -263,3 +270,9 @@ async def delete_file(
status_code=200,
media_type="application/json",
)


@app.get("/sentry-debug")
async def trigger_error() -> float:
division_by_zero = 1 / 0
return division_by_zero
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 513f601

Please sign in to comment.