Skip to content

Conversation

@TeKrop
Copy link
Owner

@TeKrop TeKrop commented Jan 4, 2026

Summary by Sourcery

Add optional Sentry-based monitoring and bump project version.

New Features:

  • Introduce configurable Sentry DSN setting for error and performance monitoring.
  • Integrate Sentry SDK with FastAPI application to capture errors, logs, traces, and profiling data when a DSN is provided.

Build:

  • Add sentry-sdk with FastAPI extras as a project dependency and increment the application version.

@TeKrop TeKrop self-assigned this Jan 4, 2026
@TeKrop TeKrop added the enhancement New feature or request label Jan 4, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 4, 2026

Reviewer's Guide

Adds optional Sentry monitoring integration gated by configuration, wires it into the FastAPI app startup, introduces a Sentry DSN setting, and declares the sentry-sdk dependency, along with a minor version bump.

Sequence diagram for FastAPI app startup with optional Sentry initialization

sequenceDiagram
    participant FastAPIApp
    participant main_module
    participant Settings
    participant SentrySDK

    FastAPIApp->>main_module: import app.main
    main_module->>Settings: load settings
    alt sentry_dsn is non empty
        main_module->>SentrySDK: init(dsn, send_default_pii, enable_logs, traces_sample_rate, profile_session_sample_rate, profile_lifecycle)
        SentrySDK-->>main_module: Sentry client initialized
    else sentry_dsn is empty
        main_module-->>FastAPIApp: Sentry not initialized
    end
    main_module-->>FastAPIApp: FastAPI instance with lifespan
Loading

Updated class diagram for Settings with Sentry configuration

classDiagram
    class BaseSettings

    class Settings {
        +string sentry_dsn
    }

    BaseSettings <|-- Settings
Loading

File-Level Changes

Change Details Files
Introduce optional Sentry monitoring initialization in the FastAPI app based on configuration.
  • Conditionally import sentry_sdk only when a Sentry DSN is configured in settings.
  • Initialize Sentry at module import time with DSN from settings and enable default PII, log forwarding, tracing, and profiling with full sampling.
  • Document key Sentry configuration choices via inline comments for future tuning.
app/main.py
Extend application configuration and dependencies to support Sentry.
  • Add a new sentry_dsn setting to the central Settings configuration with a default empty string.
  • Declare sentry-sdk with FastAPI extras as a project dependency and bump the project minor version to reflect the new feature.
  • Update environment/dist and lock files to align with the new configuration and dependency (if applicable).
app/config.py
pyproject.toml
.env.dist
uv.lock

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 4, 2026

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Consider making Sentry tuning parameters (PII collection, traces_sample_rate, profile_session_sample_rate, profile_lifecycle) configurable via Settings instead of hard-coding them in main.py so they can be adjusted per environment without code changes.
  • Since you are depending on sentry-sdk[fastapi], you may want to explicitly use FastAPI and logging integrations (e.g., FastApiIntegration, LoggingIntegration) in sentry_sdk.init to ensure framework-specific context and logs are captured correctly.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider making Sentry tuning parameters (PII collection, traces_sample_rate, profile_session_sample_rate, profile_lifecycle) configurable via Settings instead of hard-coding them in main.py so they can be adjusted per environment without code changes.
- Since you are depending on sentry-sdk[fastapi], you may want to explicitly use FastAPI and logging integrations (e.g., FastApiIntegration, LoggingIntegration) in sentry_sdk.init to ensure framework-specific context and logs are captured correctly.

## Individual Comments

### Comment 1
<location> `app/main.py:36-45` </location>
<code_context>
+if settings.sentry_dsn:
+    import sentry_sdk
+
+    sentry_sdk.init(
+        dsn=settings.sentry_dsn,
+        # Add data like request headers and IP for users,
+        # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
+        send_default_pii=True,
+        # Enable sending logs to Sentry
+        enable_logs=True,
+        # Set traces_sample_rate to 1.0 to capture 100%
+        # of transactions for tracing.
+        traces_sample_rate=1.0,
+        # Set profile_session_sample_rate to 1.0 to profile 100%
+        # of profile sessions.
+        profile_session_sample_rate=1.0,
+        # Set profile_lifecycle to "trace" to automatically
+        # run the profiler on when there is an active transaction
+        profile_lifecycle="trace",
+    )
+
</code_context>

<issue_to_address>
**suggestion:** Leverage the FastAPI-specific integration from `sentry-sdk[fastapi]` to get richer context and better error reporting.

Given we already depend on the `fastapi` extra, consider initializing Sentry with the FastAPI integration (e.g. `integrations=[sentry_sdk.integrations.fastapi.FastApiIntegration()]`). This will attach richer request/response context, better transaction naming, and improved handling of background tasks compared to using the default `init` alone.

Suggested implementation:

```python
from .players import router as players
from .roles import router as roles

if settings.sentry_dsn:
    import sentry_sdk
    from sentry_sdk.integrations.fastapi import FastApiIntegration

    sentry_sdk.init(
        dsn=settings.sentry_dsn,
        integrations=[FastApiIntegration()],
        # Add data like request headers and IP for users,
        # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
        send_default_pii=True,
        # Enable sending logs to Sentry
        enable_logs=True,

```

If there are further keyword arguments to `sentry_sdk.init` after `enable_logs=True,` in the real file (e.g. `traces_sample_rate`, `profile_session_sample_rate`, etc.), they will remain unchanged after this edit and will continue to work as before. No additional code changes should be needed as long as `settings` is already imported and configured in this module.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@TeKrop TeKrop merged commit 0bf2f26 into main Jan 4, 2026
5 checks passed
@TeKrop TeKrop deleted the feature/sentry branch January 4, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants