Skip to content

Commit 05dc1b8

Browse files
GRACENOBLEclaude
andcommitted
fix(observability): address CodeRabbit review findings
- backend/.env.example: separate inline comments from FIREBASE var values so dotenv parsers don't treat # as a literal value - backend/docs/bootstrap.md: add missing SentryDSN field to Config struct docs - backend/docs/routing.md: update RegisterRoutes signature and NewServer wiring snippet to include sentryDSN param - backend/docs/observability.md: add dotenv language tag to code fence - middleware/sentry.go: log sentry.Init errors instead of discarding with _; degrade to no-op on failure - mobile/build.gradle.kts: read SENTRY_DSN from local.properties (gitignored) instead of hardcoding empty string - web/docs: fix stale .env.local.example references to .env.example; add language tag to code fence Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8ff3c44 commit 05dc1b8

8 files changed

Lines changed: 27 additions & 14 deletions

File tree

‎backend/.env.example‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ BLUEPRINT_DB_SSLMODE=disable
1010
REDIS_URL=
1111
RATE_LIMIT_RPS=100 # requests/sec per IP (omit or 0 = disabled)
1212
RATE_LIMIT_BURST=500 # burst capacity (defaults to RPS×5)
13-
FIREBASE_PROJECT_ID=# Firebase project ID — e.g. my-app-12345 (omit to disable auth)
14-
FIREBASE_SERVICE_ACCOUNT_JSON=# Service account key as a single-line JSON string. Get from: Firebase Console → Project Settings → Service Accounts → Generate new private key
13+
# Firebase project ID — e.g. my-app-12345 (omit to disable auth)
14+
FIREBASE_PROJECT_ID=
15+
# Service account key as a single-line JSON string. Get from: Firebase Console → Project Settings → Service Accounts → Generate new private key
16+
FIREBASE_SERVICE_ACCOUNT_JSON=
1517
# Sentry error tracking DSN (optional; leave empty to disable)
1618
SENTRY_DSN=

‎backend/docs/bootstrap.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Config struct {
3535
RateLimitBurst int
3636
FirebaseProjectID string
3737
FirebaseServiceAccountJSON string
38+
SentryDSN string
3839
}
3940
```
4041
`loadConfig()` reads all values from environment variables. `PORT` defaults to `8080`; `BLUEPRINT_DB_SCHEMA` defaults to `public`; `BLUEPRINT_DB_SSLMODE` defaults to `disable`. `RateLimitBurst` is derived as `int(RPS)*5` when omitted and RPS is set. Optional fields (`RedisURL`, `FirebaseProjectID`, `FirebaseServiceAccountJSON`) default to empty string — their respective services are skipped when empty.

‎backend/docs/observability.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Stored on `Config.SentryDSN`. Not validated — an empty value disables Sentry w
6363
## Supplying the DSN
6464

6565
**Local development** — add to `backend/.env`:
66-
```
66+
```dotenv
6767
SENTRY_DSN=https://<key>@o<org>.ingest.sentry.io/<project>
6868
```
6969

‎backend/docs/routing.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ h := handlers.NewHandler(healthUC)
3838

3939
return &http.Server{
4040
Addr: fmt.Sprintf(":%d", app.Config.Port),
41-
Handler: h.RegisterRoutes(app.Config.RateLimitRPS, app.Config.RateLimitBurst, app.Firebase),
41+
Handler: h.RegisterRoutes(app.Config.RateLimitRPS, app.Config.RateLimitBurst, app.Firebase, app.Config.SentryDSN),
4242
IdleTimeout: time.Minute,
4343
ReadTimeout: 10 * time.Second,
4444
WriteTimeout: 30 * time.Second,
@@ -51,7 +51,7 @@ All routes registered in `RegisterRoutes()` on `*Handler`, which returns `http.H
5151
`verifier` is a `usecase.FirebaseTokenVerifier`; pass `nil` to skip Firebase auth (development only — see [auth](auth.md)).
5252

5353
```go
54-
func (h *Handler) RegisterRoutes(rps float64, burst int, verifier usecase.FirebaseTokenVerifier) http.Handler {
54+
func (h *Handler) RegisterRoutes(rps float64, burst int, verifier usecase.FirebaseTokenVerifier, sentryDSN string) http.Handler {
5555
r := gin.New()
5656

5757
// Gin's colorful logger locally; structured slog logger in staging/production.
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
package middleware
22

33
import (
4+
"log/slog"
5+
46
sentry "github.com/getsentry/sentry-go"
57
sentrygin "github.com/getsentry/sentry-go/gin"
6-
78
"github.com/gin-gonic/gin"
89
)
910

1011
// SentryMiddleware reports panics and errors to Sentry.
1112
// When dsn is empty it returns a no-op handler so the app works without Sentry configured.
13+
// When dsn is set but sentry.Init fails (e.g. malformed DSN), the error is logged and
14+
// the middleware degrades to a no-op rather than preventing startup.
1215
func SentryMiddleware(dsn string) gin.HandlerFunc {
1316
if dsn == "" {
1417
return func(c *gin.Context) { c.Next() }
1518
}
16-
_ = sentry.Init(sentry.ClientOptions{Dsn: dsn})
19+
if err := sentry.Init(sentry.ClientOptions{Dsn: dsn}); err != nil {
20+
slog.Default().Warn("sentry: init failed, continuing without error tracking", "error", err)
21+
return func(c *gin.Context) { c.Next() }
22+
}
1723
return sentrygin.New(sentrygin.Options{Repanic: true})
1824
}

‎mobile/app/build.gradle.kts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
import java.util.Properties
2+
13
plugins {
24
alias(libs.plugins.android.application)
35
alias(libs.plugins.kotlin.compose)
46
}
57

8+
val localProps = Properties().apply {
9+
rootProject.file("local.properties").takeIf { it.exists() }?.inputStream()?.use { load(it) }
10+
}
11+
612
android {
713
namespace = "com.company.template"
814
compileSdk {
@@ -19,7 +25,7 @@ android {
1925
versionName = "1.0"
2026

2127
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
22-
buildConfigField("String", "SENTRY_DSN", "\"\"")
28+
buildConfigField("String", "SENTRY_DSN", "\"${localProps.getProperty("SENTRY_DSN", "")}\"")
2329
}
2430

2531
buildTypes {

‎web/docs/_index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ The `docs` agent reads this index first to locate the right file.
1010
| Styling with Tailwind CSS v4 | [styling.md](styling.md) | `app/globals.css`, `postcss.config.mjs` |
1111
| Component conventions | [components.md](components.md) | `app/` (all component files) |
1212
| Testing patterns | [testing.md](testing.md) | `vitest.config.ts`, `vitest.setup.ts`, `__tests__/page.test.tsx` |
13-
| Observability (Sentry error tracking) | [observability.md](observability.md) | `sentry.client.config.ts`, `sentry.server.config.ts`, `sentry.edge.config.ts`, `next.config.ts`, `.env.local.example` |
13+
| Observability (Sentry error tracking) | [observability.md](observability.md) | `sentry.client.config.ts`, `sentry.server.config.ts`, `sentry.edge.config.ts`, `next.config.ts`, `.env.example` |

‎web/docs/observability.md‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sources:
66
- sentry.server.config.ts
77
- sentry.edge.config.ts
88
- next.config.ts
9-
- .env.local.example
9+
- .env.example
1010
---
1111

1212
# Observability
@@ -45,13 +45,11 @@ Next.js picks up each file automatically based on the execution context — no m
4545

4646
The `NEXT_PUBLIC_` prefix makes the value available in the browser bundle. When the variable is absent or empty, `Sentry.init` is a no-op.
4747

48-
**Local development** — add to `web/.env.local`:
49-
```
48+
**Local development** — copy `web/.env.example` to `web/.env.local` and fill in your DSN:
49+
```dotenv
5050
NEXT_PUBLIC_SENTRY_DSN=https://<key>@o<org>.ingest.sentry.io/<project>
5151
```
5252

53-
`web/.env.local.example` documents this with an empty placeholder.
54-
5553
**Production** — set `NEXT_PUBLIC_SENTRY_DSN` in your deployment platform's environment configuration.
5654

5755
## next.config.ts — withSentryConfig

0 commit comments

Comments
 (0)