Skip to content

Commit

Permalink
Merge pull request #32 from MbxrAteeq/feature/sentry-integration
Browse files Browse the repository at this point in the history
Add Sentry integration for error monitoring
  • Loading branch information
asacristani authored Apr 14, 2024
2 parents 36eba73 + 72e755a commit f594fcd
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 39 deletions.
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ rabbit_port=5672

# REDIS
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PORT=6379

# Sentry
SENTRY_DSN=
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ If you are using VS Code, I recommend you to install some plugins:

> ℹ️ You can test the pre-commit without committing running `trunk check`
#### Sentry Integration

To integrate Sentry for error monitoring, add the Sentry DSN (Data Source Name) to the `.env` file. Set up your environment by signing in to [Sentry](https://sentry.io/welcome/) to create a project and obtain the Sentry DSN.

In the `.env` file, include the following variable:

```shell
SENTRY_DSN=your_sentry_dsn_here
```

> With this configuration, errors will be captured and reported to your Sentry project for effective monitoring.
### 🔌 Build and run

Build and run the Docker services for using in Locaql.
Expand Down Expand Up @@ -245,6 +257,8 @@ Also, it is possible you want to modify the expiry time of access/refresh tokens
### Monitoring

- [ ] Add logging
- [x] Add Sentry
- [ ] Add Flower

### Testing

Expand Down
7 changes: 7 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pika
import redis
import sentry_sdk
from fastapi import FastAPI
from fastapi.routing import APIRoute
from sqladmin import Admin
Expand All @@ -21,6 +22,12 @@ def custom_generate_unique_id(route: APIRoute):
return f"{route.tags[0]}-{route.name}"


# Sentry Integration
sentry_sdk.init(
dsn=settings.sentry_dsn,
traces_sample_rate=settings.trace_rate,
)

app = FastAPI(generate_unique_id_function=custom_generate_unique_id)

# ROUTERS
Expand Down
4 changes: 4 additions & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class Settings(BaseSettings):
redis_host: str
redis_port: str

# Sentry
sentry_dsn: str
trace_rate: float = 1.0

class Config:
env_file = ".env"

Expand Down
141 changes: 103 additions & 38 deletions 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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ celery = { extras = ["redis"], version = "^5.3.4" }
pytz = "^2023.3.post1"
pika = "^1.3.2"
bcrypt = "^4.1.2"
sentry-sdk = "^1.32.0"


[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit f594fcd

Please sign in to comment.