Skip to content

Commit 590e55a

Browse files
authored
feat: integrate Sentry for error tracking and performance monitoring (#408)
1 parent 03b0150 commit 590e55a

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

.env.example

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Gitingest Environment Variables
2+
3+
# Host Configuration
4+
# Comma-separated list of allowed hostnames
5+
# Default: "gitingest.com, *.gitingest.com, localhost, 127.0.0.1"
6+
ALLOWED_HOSTS=gitingest.com,*.gitingest.com,localhost,127.0.0.1
7+
8+
# GitHub Authentication
9+
# Personal Access Token for accessing private repositories
10+
# Generate your token here: https://github.com/settings/tokens/new?description=gitingest&scopes=repo
11+
# GITHUB_TOKEN=your_github_token_here
12+
13+
# Metrics Configuration
14+
# Set to any value to enable the Prometheus metrics server
15+
# GITINGEST_METRICS_ENABLED=true
16+
# Host for the metrics server (default: "127.0.0.1")
17+
GITINGEST_METRICS_HOST=127.0.0.1
18+
# Port for the metrics server (default: "9090")
19+
GITINGEST_METRICS_PORT=9090
20+
21+
# Sentry Configuration
22+
# Set to any value to enable Sentry error tracking
23+
# GITINGEST_SENTRY_ENABLED=true
24+
# Sentry DSN (required if Sentry is enabled)
25+
# GITINGEST_SENTRY_DSN=your_sentry_dsn_here
26+
# Sampling rate for performance data (default: "1.0", range: 0.0-1.0)
27+
GITINGEST_SENTRY_TRACES_SAMPLE_RATE=1.0
28+
# Sampling rate for profile sessions (default: "1.0", range: 0.0-1.0)
29+
GITINGEST_SENTRY_PROFILE_SESSION_SAMPLE_RATE=1.0
30+
# Profile lifecycle mode (default: "trace")
31+
GITINGEST_SENTRY_PROFILE_LIFECYCLE=trace
32+
# Send default personally identifiable information (default: "true")
33+
GITINGEST_SENTRY_SEND_DEFAULT_PII=true
34+
# Environment name for Sentry (default: "")
35+
GITINGEST_SENTRY_ENVIRONMENT=development

README.md

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

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

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

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

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: 28 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,33 @@
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+
sentry_environment = os.getenv("GITINGEST_SENTRY_ENVIRONMENT", "")
37+
38+
sentry_sdk.init(
39+
dsn=sentry_dsn,
40+
# Add data like request headers and IP for users
41+
send_default_pii=send_default_pii,
42+
# Set traces_sample_rate to capture transactions for tracing
43+
traces_sample_rate=traces_sample_rate,
44+
# Set profile_session_sample_rate to profile sessions
45+
profile_session_sample_rate=profile_session_sample_rate,
46+
# Set profile_lifecycle to automatically run the profiler
47+
profile_lifecycle=profile_lifecycle,
48+
# Set environment name
49+
environment=sentry_environment,
50+
)
51+
2452
# Initialize the FastAPI application with lifespan
2553
app = FastAPI(lifespan=lifespan, docs_url=None, redoc_url=None)
2654
app.state.limiter = limiter

0 commit comments

Comments
 (0)