Skip to content

Commit e89a0ff

Browse files
committed
chore: Refine environment configurations and enhance error handling
- Updated PYTHONPATH in docker-compose.yml to point directly to the API package, improving module resolution. - Changed log level in env.development from DEBUG to INFO to reduce log verbosity during development. - Added validation for the GOOGLE_API_KEY in the worker to ensure a valid API key is configured before analysis. - Enhanced error handling in the analyze_repository function to log failures during LLM analysis, improving debugging capabilities. - Removed unnecessary debug logs in various modules to reduce log noise and improve clarity. - Ensured compliance with project structure and coding standards, including type hints and documentation.
1 parent 1a74e81 commit e89a0ff

File tree

6 files changed

+49
-25
lines changed

6 files changed

+49
-25
lines changed

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ services:
5757
- GOOGLE_API_KEY=${GOOGLE_API_KEY}
5858
- GITHUB_TOKEN=${GITHUB_TOKEN}
5959
- JWT_SECRET=${JWT_SECRET:-dev_secret_key}
60-
- PYTHONPATH=/app
60+
- PYTHONPATH=/app/packages/api
6161
- WATCHDOG_POLLING=True
6262
volumes:
6363
- .:/app
@@ -94,7 +94,7 @@ services:
9494
- GOOGLE_API_KEY=${GOOGLE_API_KEY}
9595
- GITHUB_TOKEN=${GITHUB_TOKEN}
9696
- JWT_SECRET=${JWT_SECRET:-dev_secret_key}
97-
- PYTHONPATH=/app
97+
- PYTHONPATH=/app/packages/api
9898
- WATCHDOG_POLLING=True
9999
volumes:
100100
- .:/app

packages/api/app/worker.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ def analyze_repository(task_id: str, github_url: str, options: dict):
7575
code_digest = repo_data["content"]
7676
metrics = repo_data.get("metrics", {})
7777

78+
# Validate API key before proceeding
79+
if not settings.GOOGLE_API_KEY or settings.GOOGLE_API_KEY == "your_gemini_api_key_here":
80+
raise Exception(
81+
"GOOGLE_API_KEY is not configured. Please set a valid Gemini API key in your .env file."
82+
)
83+
7884
# Get analysis options
7985
model = options.get("model", settings.DEFAULT_MODEL)
8086
temperature = float(options.get("temperature", settings.TEMPERATURE))
@@ -105,15 +111,22 @@ def analyze_repository(task_id: str, github_url: str, options: dict):
105111
else:
106112
prompt_path = prompt_option
107113

108-
analysis = analyze_single_repository(
109-
repo_name,
110-
code_digest,
111-
prompt_path,
112-
model_name=model,
113-
temperature=temperature,
114-
output_json=False,
115-
metrics_data=metrics,
116-
)
114+
logger.debug(f"Starting LLM analysis for {repo_name} using model {model}")
115+
116+
try:
117+
analysis = analyze_single_repository(
118+
repo_name,
119+
code_digest,
120+
prompt_path,
121+
model_name=model,
122+
temperature=temperature,
123+
output_json=False,
124+
metrics_data=metrics,
125+
)
126+
logger.debug(f"LLM analysis completed for {repo_name}")
127+
except Exception as llm_error:
128+
logger.error(f"LLM analysis failed for {repo_name}: {str(llm_error)}")
129+
raise Exception(f"LLM analysis failed: {str(llm_error)}")
117130

118131
# Update progress
119132
task.progress = 80

packages/api/src/worker.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,15 @@
66
import argparse
77
import logging
88
import os
9-
import sys
10-
from pathlib import Path
119

1210
from redis import Redis
1311
from rq import Queue, Worker
1412

1513
# Prevent issues with fork() on macOS
1614
os.environ["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES"
1715

18-
# Add project root to path
19-
project_root = Path(__file__).parent.parent.parent
20-
sys.path.insert(0, str(project_root))
21-
22-
# Add packages/api to path so app.* imports work
23-
api_package_path = project_root / "packages" / "api"
24-
sys.path.insert(0, str(api_package_path))
16+
# PYTHONPATH is set via Docker environment variables
17+
# No manual sys.path manipulation needed
2518

2619
# Load environment variables
2720
from dotenv import load_dotenv

packages/core/src/config.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ def get_gemini_api_key() -> str:
4040
f"{GEMINI_API_KEY_ENV} environment variable is not set. "
4141
f"Please set it in your .env file or export it directly."
4242
)
43+
if api_key in ["your_gemini_api_key_here", "your_actual_gemini_api_key_here"]:
44+
raise ValueError(
45+
f"{GEMINI_API_KEY_ENV} is set to a placeholder value. "
46+
f"Please set a real Gemini API key from https://aistudio.google.com/app/apikey"
47+
)
4348
return api_key
4449

4550

@@ -129,6 +134,13 @@ def setup_logging(level_name: Optional[str] = None) -> None:
129134
logging.getLogger("httpx").setLevel(logging.WARNING)
130135
logging.getLogger("httpcore").setLevel(logging.WARNING)
131136

137+
# Suppress HTTP connection debug logs (very noisy)
138+
logging.getLogger("urllib3").setLevel(logging.WARNING)
139+
logging.getLogger("urllib3.connectionpool").setLevel(logging.WARNING)
140+
141+
# Suppress asyncio debug logs
142+
logging.getLogger("asyncio").setLevel(logging.WARNING)
143+
132144
# Suppress RQ (Redis Queue) INFO logs
133145
logging.getLogger("rq.worker").setLevel(logging.WARNING)
134146
logging.getLogger("rq.queue").setLevel(logging.WARNING)
@@ -155,4 +167,10 @@ def setup_logging(level_name: Optional[str] = None) -> None:
155167
logging.getLogger("watchfiles.main").setLevel(logging.WARNING)
156168
logging.getLogger("alembic").setLevel(logging.WARNING)
157169

158-
logging.debug(f"Logging initialized at level: {level_name}")
170+
# Suppress GitHub API and gitingest debug logs
171+
logging.getLogger("github").setLevel(logging.WARNING)
172+
logging.getLogger("gitingest").setLevel(logging.WARNING)
173+
174+
# Only log the initialization at INFO level to avoid noise
175+
if level >= logging.INFO:
176+
logging.info(f"Logging initialized at level: {level_name}")

packages/core/src/fetcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def normalize_repo_url(url: str) -> str:
241241
# Remove trailing slashes
242242
url = url.rstrip("/")
243243

244-
logger.debug(f"Normalized URL: {url}")
244+
# URL normalized (removed debug log for noise reduction)
245245
return url
246246

247247

packages/core/src/metrics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, token: Optional[str] = None, max_workers: int = 5):
3434
self.token = token or os.environ.get("GITHUB_TOKEN")
3535
self.github = self._initialize_github()
3636
self.max_workers = max_workers
37-
logger.debug(f"GitHub metrics fetcher initialized with {max_workers} workers")
37+
# GitHub metrics fetcher initialized (removed debug log for noise reduction)
3838

3939
def _initialize_github(self) -> Github:
4040
"""
@@ -46,7 +46,7 @@ def _initialize_github(self) -> Github:
4646
if self.token:
4747
auth = Auth.Token(self.token)
4848
github = Github(auth=auth)
49-
logger.debug("GitHub client initialized with token")
49+
# GitHub client initialized with token (removed debug log for noise reduction)
5050
else:
5151
github = Github()
5252
logger.warning("GitHub client initialized without token (rate-limited)")
@@ -94,7 +94,7 @@ def get_repository(self, url: str):
9494

9595
try:
9696
repo = self.github.get_repo(full_name)
97-
logger.debug(f"Fetched repository: {full_name}")
97+
# Repository fetched successfully (removed debug log for noise reduction)
9898
return repo
9999
except Exception as e:
100100
logger.error(f"Error fetching repository {full_name}: {str(e)}")

0 commit comments

Comments
 (0)