Skip to content
Merged
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
35 changes: 35 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Gitingest Environment Variables

# Host Configuration
# Comma-separated list of allowed hostnames
# Default: "gitingest.com, *.gitingest.com, localhost, 127.0.0.1"
ALLOWED_HOSTS=gitingest.com,*.gitingest.com,localhost,127.0.0.1

# GitHub Authentication
# Personal Access Token for accessing private repositories
# Generate your token here: https://github.com/settings/tokens/new?description=gitingest&scopes=repo
# GITHUB_TOKEN=your_github_token_here

# Metrics Configuration
# Set to any value to enable the Prometheus metrics server
# GITINGEST_METRICS_ENABLED=true
# Host for the metrics server (default: "127.0.0.1")
GITINGEST_METRICS_HOST=127.0.0.1
# Port for the metrics server (default: "9090")
GITINGEST_METRICS_PORT=9090

# Sentry Configuration
# Set to any value to enable Sentry error tracking
# GITINGEST_SENTRY_ENABLED=true
# Sentry DSN (required if Sentry is enabled)
# GITINGEST_SENTRY_DSN=your_sentry_dsn_here
# Sampling rate for performance data (default: "1.0", range: 0.0-1.0)
GITINGEST_SENTRY_TRACES_SAMPLE_RATE=1.0
# Sampling rate for profile sessions (default: "1.0", range: 0.0-1.0)
GITINGEST_SENTRY_PROFILE_SESSION_SAMPLE_RATE=1.0
# Profile lifecycle mode (default: "trace")
GITINGEST_SENTRY_PROFILE_LIFECYCLE=trace
# Send default personally identifiable information (default: "true")
GITINGEST_SENTRY_SEND_DEFAULT_PII=true
# Environment name for Sentry (default: "")
GITINGEST_SENTRY_ENVIRONMENT=development
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,21 @@ If you are hosting it on a domain, you can specify the allowed hostnames via env
ALLOWED_HOSTS="example.com, localhost, 127.0.0.1"
```

### Environment Variables

The application can be configured using the following environment variables:

- **ALLOWED_HOSTS**: Comma-separated list of allowed hostnames (default: "gitingest.com, *.gitingest.com, localhost, 127.0.0.1")
- **GITINGEST_METRICS_ENABLED**: Enable Prometheus metrics server (set to any value to enable)
- **GITINGEST_METRICS_HOST**: Host for the metrics server (default: "127.0.0.1")
- **GITINGEST_METRICS_PORT**: Port for the metrics server (default: "9090")
- **GITINGEST_SENTRY_ENABLED**: Enable Sentry error tracking (set to any value to enable)
- **GITINGEST_SENTRY_DSN**: Sentry DSN (required if Sentry is enabled)
- **GITINGEST_SENTRY_TRACES_SAMPLE_RATE**: Sampling rate for performance data (default: "1.0", range: 0.0-1.0)
- **GITINGEST_SENTRY_PROFILE_SESSION_SAMPLE_RATE**: Sampling rate for profile sessions (default: "1.0", range: 0.0-1.0)
- **GITINGEST_SENTRY_PROFILE_LIFECYCLE**: Profile lifecycle mode (default: "trace")
- **GITINGEST_SENTRY_SEND_DEFAULT_PII**: Send default personally identifiable information (default: "true")

## 🤝 Contributing

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

### Looking for a JavaScript/FileSystemNode package?

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pathspec>=0.12.1
prometheus-client
pydantic
python-dotenv
sentry-sdk[fastapi]
slowapi
starlette>=0.40.0 # Vulnerable to https://osv.dev/vulnerability/GHSA-f96h-pmfr-66vw
tiktoken>=0.7.0 # Support for o200k_base encoding
Expand Down
28 changes: 28 additions & 0 deletions src/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import threading
from pathlib import Path

import sentry_sdk

Check warning on line 9 in src/server/main.py

View check run for this annotation

Codecov / codecov/patch

src/server/main.py#L9

Added line #L9 was not covered by tests
from dotenv import load_dotenv
from fastapi import FastAPI, Request
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
Expand All @@ -21,6 +22,33 @@
# Load environment variables from .env file
load_dotenv()

# Initialize Sentry SDK if enabled
if os.getenv("GITINGEST_SENTRY_ENABLED") is not None:
sentry_dsn = os.getenv("GITINGEST_SENTRY_DSN")

Check warning on line 27 in src/server/main.py

View check run for this annotation

Codecov / codecov/patch

src/server/main.py#L27

Added line #L27 was not covered by tests

# Only initialize Sentry if DSN is provided
if sentry_dsn:
# Configure Sentry options from environment variables
traces_sample_rate = float(os.getenv("GITINGEST_SENTRY_TRACES_SAMPLE_RATE", "1.0"))
profile_session_sample_rate = float(os.getenv("GITINGEST_SENTRY_PROFILE_SESSION_SAMPLE_RATE", "1.0"))
profile_lifecycle = os.getenv("GITINGEST_SENTRY_PROFILE_LIFECYCLE", "trace")
send_default_pii = os.getenv("GITINGEST_SENTRY_SEND_DEFAULT_PII", "true").lower() == "true"
sentry_environment = os.getenv("GITINGEST_SENTRY_ENVIRONMENT", "")

Check warning on line 36 in src/server/main.py

View check run for this annotation

Codecov / codecov/patch

src/server/main.py#L32-L36

Added lines #L32 - L36 were not covered by tests

sentry_sdk.init(

Check warning on line 38 in src/server/main.py

View check run for this annotation

Codecov / codecov/patch

src/server/main.py#L38

Added line #L38 was not covered by tests
dsn=sentry_dsn,
# Add data like request headers and IP for users
send_default_pii=send_default_pii,
# Set traces_sample_rate to capture transactions for tracing
traces_sample_rate=traces_sample_rate,
# Set profile_session_sample_rate to profile sessions
profile_session_sample_rate=profile_session_sample_rate,
# Set profile_lifecycle to automatically run the profiler
profile_lifecycle=profile_lifecycle,
# Set environment name
environment=sentry_environment,
)

# Initialize the FastAPI application with lifespan
app = FastAPI(lifespan=lifespan, docs_url=None, redoc_url=None)
app.state.limiter = limiter
Expand Down
Loading