Skip to content

Commit b435bf1

Browse files
committed
feat: integrate Sentry for error tracking and performance monitoring
1 parent fa2e192 commit b435bf1

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,21 @@ If you are hosting it on a domain, you can specify the allowed hostnames via env
216216
ALLOWED_HOSTS="example.com, localhost, 127.0.0.1"
217217
```
218218

219+
### Environment Variables
220+
221+
The application can be configured using the following environment variables:
222+
223+
- **ALLOWED_HOSTS**: Comma-separated list of allowed hostnames (default: "gitingest.com, *.gitingest.com, localhost, 127.0.0.1")
224+
- **GITINGEST_METRICS_ENABLED**: Enable Prometheus metrics server (set to any value to enable)
225+
- **GITINGEST_METRICS_HOST**: Host for the metrics server (default: "127.0.0.1")
226+
- **GITINGEST_METRICS_PORT**: Port for the metrics server (default: "9090")
227+
- **GITINGEST_SENTRY_ENABLED**: Enable Sentry error tracking (set to any value to enable)
228+
- **GITINGEST_SENTRY_DSN**: Sentry DSN (required if Sentry is enabled)
229+
- **GITINGEST_SENTRY_TRACES_SAMPLE_RATE**: Sampling rate for performance data (default: "1.0", range: 0.0-1.0)
230+
- **GITINGEST_SENTRY_PROFILE_SESSION_SAMPLE_RATE**: Sampling rate for profile sessions (default: "1.0", range: 0.0-1.0)
231+
- **GITINGEST_SENTRY_PROFILE_LIFECYCLE**: Profile lifecycle mode (default: "trace")
232+
- **GITINGEST_SENTRY_SEND_DEFAULT_PII**: Send default personally identifiable information (default: "true")
233+
219234
## 🤝 Contributing
220235

221236
### Non-technical ways to contribute
@@ -235,6 +250,7 @@ Gitingest aims to be friendly for first time contributors, with a simple Python
235250
- [Jinja2](https://jinja.palletsprojects.com) - HTML templating
236251
- [tiktoken](https://github.com/openai/tiktoken) - Token estimation
237252
- [posthog](https://github.com/PostHog/posthog) - Amazing analytics
253+
- [Sentry](https://sentry.io) - Error tracking and performance monitoring
238254

239255
### Looking for a JavaScript/FileSystemNode package?
240256

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pathspec>=0.12.1
55
prometheus-client
66
pydantic
77
python-dotenv
8+
sentry-sdk[fastapi]
89
slowapi
910
starlette>=0.40.0 # Vulnerable to https://osv.dev/vulnerability/GHSA-f96h-pmfr-66vw
1011
tiktoken>=0.7.0 # Support for o200k_base encoding

src/server/main.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import threading
77
from pathlib import Path
88

9+
import sentry_sdk
910
from dotenv import load_dotenv
1011
from fastapi import FastAPI, Request
1112
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
@@ -21,6 +22,30 @@
2122
# Load environment variables from .env file
2223
load_dotenv()
2324

25+
# Initialize Sentry SDK if enabled
26+
if os.getenv("GITINGEST_SENTRY_ENABLED") is not None:
27+
sentry_dsn = os.getenv("GITINGEST_SENTRY_DSN")
28+
29+
# Only initialize Sentry if DSN is provided
30+
if sentry_dsn:
31+
# Configure Sentry options from environment variables
32+
traces_sample_rate = float(os.getenv("GITINGEST_SENTRY_TRACES_SAMPLE_RATE", "1.0"))
33+
profile_session_sample_rate = float(os.getenv("GITINGEST_SENTRY_PROFILE_SESSION_SAMPLE_RATE", "1.0"))
34+
profile_lifecycle = os.getenv("GITINGEST_SENTRY_PROFILE_LIFECYCLE", "trace")
35+
send_default_pii = os.getenv("GITINGEST_SENTRY_SEND_DEFAULT_PII", "true").lower() == "true"
36+
37+
sentry_sdk.init(
38+
dsn=sentry_dsn,
39+
# Add data like request headers and IP for users
40+
send_default_pii=send_default_pii,
41+
# Set traces_sample_rate to capture transactions for tracing
42+
traces_sample_rate=traces_sample_rate,
43+
# Set profile_session_sample_rate to profile sessions
44+
profile_session_sample_rate=profile_session_sample_rate,
45+
# Set profile_lifecycle to automatically run the profiler
46+
profile_lifecycle=profile_lifecycle,
47+
)
48+
2449
# Initialize the FastAPI application with lifespan
2550
app = FastAPI(lifespan=lifespan, docs_url=None, redoc_url=None)
2651
app.state.limiter = limiter

0 commit comments

Comments
 (0)