From 7562fe86bfc5779f5c62ae30fbc116e0d5f2ed7d Mon Sep 17 00:00:00 2001 From: mickael Date: Sun, 13 Jul 2025 16:48:07 +0200 Subject: [PATCH 1/3] feat: integrate Sentry for error tracking and performance monitoring --- README.md | 16 ++++++++++++++++ requirements.txt | 1 + src/server/main.py | 25 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/README.md b/README.md index 7cb4d537..dc89ca22 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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? diff --git a/requirements.txt b/requirements.txt index bfec694e..712360e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/src/server/main.py b/src/server/main.py index db209af3..e2f9aac3 100644 --- a/src/server/main.py +++ b/src/server/main.py @@ -6,6 +6,7 @@ import threading from pathlib import Path +import sentry_sdk from dotenv import load_dotenv from fastapi import FastAPI, Request from fastapi.responses import FileResponse, HTMLResponse, JSONResponse @@ -21,6 +22,30 @@ # 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") + + # 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_sdk.init( + 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, + ) + # Initialize the FastAPI application with lifespan app = FastAPI(lifespan=lifespan, docs_url=None, redoc_url=None) app.state.limiter = limiter From 0c8dbaff4e719126fdfe987ccb21ff5498b6fb0f Mon Sep 17 00:00:00 2001 From: mickael Date: Sun, 13 Jul 2025 16:54:27 +0200 Subject: [PATCH 2/3] feat: add environment configuration support for Sentry integration --- src/server/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/server/main.py b/src/server/main.py index e2f9aac3..24cc6b7e 100644 --- a/src/server/main.py +++ b/src/server/main.py @@ -33,6 +33,7 @@ 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", "") sentry_sdk.init( dsn=sentry_dsn, @@ -44,6 +45,8 @@ 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 From a01dc2d9e2985d0974e8840d81cf51150ed77d08 Mon Sep 17 00:00:00 2001 From: mickael Date: Sun, 13 Jul 2025 16:59:02 +0200 Subject: [PATCH 3/3] feat: add example .env file for environment configuration --- .env.example | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..8d98ebba --- /dev/null +++ b/.env.example @@ -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