Skip to content

Commit

Permalink
Instrument Sentry + Fix IAM Policy (#76)
Browse files Browse the repository at this point in the history
* IAM Policy Fix + Dev Server (#74)

* added script to start dev server on different port

* chmod +x

* added additional resource to smolvault-policy

* upgraded python deps

* Sentry Monitoring (#75)

* loading sentry dsn from env file

* only call init on sentry sdk if enabled

* removed sentry debug endpoint

* updated project version to 0.8.0
  • Loading branch information
fullerzz authored Sep 29, 2024
1 parent 754f471 commit 838ca8d
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 67 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "smolvault"
version = "0.7.1"
version = "0.8.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
Expand All @@ -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
8 changes: 8 additions & 0 deletions scripts/start_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

source .venv/bin/activate
hypercorn src.smolvault.main:app -b 0.0.0.0:8200 --debug \
--log-config=logging.conf --log-level=DEBUG \
--access-logfile=hypercorn.access.log \
--error-logfile=hypercorn.error.log \
--keep-alive=120 --workers=1
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: 1 addition & 1 deletion terraform/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data "aws_iam_policy_document" "smolvault-policy" {
statement {
effect = "Allow"
actions = ["s3:*"]
resources = [aws_s3_bucket.smolvault.arn]
resources = [aws_s3_bucket.smolvault.arn, "${aws_s3_bucket.smolvault.arn}/*"]
}
statement {
effect = "Allow"
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"
148 changes: 84 additions & 64 deletions uv.lock

Large diffs are not rendered by default.

0 comments on commit 838ca8d

Please sign in to comment.