Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ POSTGRES_PORT=5432
ACCESS_TOKEN_EXPIRE_MINUTES=480
ALGORITHM=HS256
AUTHENTICATION_API_RATE_LIMIT="5 per minute"

# Sentry
SENTRY_DSN="
3 changes: 3 additions & 0 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class Settings(BaseSettings):
SEND_WELCOME_EMAIL_MAX_RETRIES: int = 5
SEND_WELCOME_EMAIL_RETRY_BACKOFF_VALUE: int = 5

# Sentry
SENTRY_DSN: Optional[str] = None

@field_validator("BACKEND_CORS_ORIGINS", mode="before")
@classmethod
def assemble_cors_origins(
Expand Down
8 changes: 8 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any
from urllib.parse import urlparse

import sentry_sdk
from asgi_correlation_id import CorrelationIdMiddleware
from asgi_correlation_id.context import correlation_id
from celery import Celery
Expand All @@ -28,6 +29,13 @@
setup_logging(json_logs=settings.LOG_JSON_FORMAT, log_level=settings.LOG_LEVEL)
access_logger = structlog.stdlib.get_logger("api.access")

if settings.SENTRY_DSN:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we want sentry when running locally. Can you consult @DanTcheche or @jsarrolt on that?

Suggested change
if settings.SENTRY_DSN:
if settings.RUN_ENV != "local" and settings.SENTRY_DSN:

sentry_sdk.init(
dsn=settings.SENTRY_DSN,
environment=settings.RUN_ENV,
send_default_pii=True,
Comment on lines +34 to +36
Copy link
Contributor

Choose a reason for hiding this comment

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

Some other settings I've seen used in projects are:

  • traces_sample_rate
  • profiles_sample_rate
  • before_send_transaction
  • before_send

For example, the before send settings can help filter out endpoints that we don't need sentry for, like the health endpoint.

Could you look into this? 😄

)
Comment on lines 31 to +37
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move sentry initialization to the middleware section, to be initialized after the app instance has been created



# region Instances
app = FastAPI(
Expand Down
Loading