The Sentry integration allows Nectr to pull production error data during PR reviews. When reviewing a PR, Nectr checks Sentry for recent errors related to the files being changed, helping reviewers understand:
Does this PR fix a known production issue?
Are the changed files causing errors in production?
Should this PR include additional error handling based on real incidents?
This is an inbound MCP integration — Nectr acts as an MCP client connecting to a Sentry MCP server.
# Sentry MCP server base URLSENTRY_MCP_URL=https://your-sentry-mcp-server.railway.app# Sentry auth token (passed to MCP server via Authorization header)SENTRY_AUTH_TOKEN=sntrys_...
Both SENTRY_MCP_URL and SENTRY_AUTH_TOKEN must be set for the integration to work. If either is missing, Sentry context will be silently skipped.
from app.mcp.client import mcp_client# During PR reviewchanged_files = ["app/services/auth.py", "app/api/login.py"]# Check Sentry for errors in the first changed fileif changed_files: errors = await mcp_client.get_sentry_errors( project="backend", filename=changed_files[0], ) if errors: print(f"Found {len(errors)} recent errors in {changed_files[0]}") for error in errors: print(f" - {error['title']} ({error['count']} occurrences)") print(f" Last seen: {error['last_seen']}") print(f" URL: {error['permalink']}")
The Sentry MCP client has a 10-second timeout to prevent slow external services from blocking PR reviews.
_MCP_TIMEOUT = 10.0 # secondstry: async with httpx.AsyncClient(timeout=_MCP_TIMEOUT) as client: response = await client.post(...) response.raise_for_status()except httpx.TimeoutException: logger.warning( f"MCP call timed out: {settings.SENTRY_MCP_URL} tool=search_errors" ) return [] # Empty list - review continues without Sentry contextexcept httpx.HTTPStatusError as exc: logger.warning(f"Sentry MCP returned HTTP {exc.response.status_code}") return []except Exception as exc: logger.warning(f"Sentry MCP query failed: {exc}") return []
Sentry integration is best-effort. If the MCP server is down or slow, PR reviews continue without Sentry context. External context should enhance reviews, not block them.
Here’s how Sentry context is pulled during a review:
# 1. Extract changed files from PRchanged_files = [f["filename"] for f in pr_files]# 2. Filter to critical files (skip tests, docs, config)critical_files = [ f for f in changed_files if not f.startswith(("tests/", "docs/", ".github/")) and f.endswith((".py", ".js", ".ts", ".tsx", ".go", ".rb"))]# 3. Pull Sentry errors for the most critical file (avoid rate limits)sentry_errors = []if critical_files: sentry_errors = await mcp_client.get_sentry_errors( project="backend", # TODO: Make this configurable per repo filename=critical_files[0], )# 4. Format Sentry context for AI review promptsentry_context = ""if sentry_errors: sentry_context = "\n\nSENTRY ERRORS:\n" for error in sentry_errors: sentry_context += f"""- {error['title']} File: {critical_files[0]} Culprit: {error['culprit']} Count: {error['count']} occurrences Last seen: {error['last_seen']} Status: {error['status']} URL: {error['permalink']}"""# 5. Include in AI reviewreview_prompt = f"""Review this pull request:PR Title: {pr_data['title']}Changed Files: {changed_files}{sentry_context}Diff:{pr_diff}Provide a structured review. If Sentry errors are present, verify:1. Does this PR fix the reported errors?2. Should additional error handling be added based on production incidents?3. Could these changes introduce similar error patterns?"""
Here’s how Sentry context appears in an AI-generated review:
# PR Review: Fix authentication token validation## Production Errors🚨 **Sentry found 47 errors in changed file** `app/services/auth.py`:- **ValueError: Invalid token format** (last seen 2 hours ago) - Culprit: `get_user_token()` line 145 - 47 occurrences in last 7 days - [View in Sentry](https://sentry.io/organizations/org/issues/123456789/)## Analysis✅ **This PR directly addresses the Sentry error!**The changes add validation for token format before attempting to decode:```python+ if not token or len(token.split(".")) != 3:+ raise ValueError("Invalid token format")
This should resolve the 47 occurrences reported by Sentry.
For PRs changing multiple files, query Sentry for each:
import asyncio# Query Sentry for all changed files (limit to avoid rate limits)changed_files = [f["filename"] for f in pr_files[:5]] # Max 5 fileserrors_by_file = await asyncio.gather( *[ mcp_client.get_sentry_errors(project="backend", filename=f) for f in changed_files ], return_exceptions=True,)# Combine resultsall_errors = []for filename, errors in zip(changed_files, errors_by_file): if isinstance(errors, Exception): logger.warning(f"Sentry query failed for {filename}: {errors}") continue for error in errors: error["filename"] = filename # Track which file caused the error all_errors.append(error)# Sort by error count (most frequent first)all_errors.sort(key=lambda e: e["count"], reverse=True)
Should return JSON with errors (or empty array if no errors).
3
Check Nectr logs
grep -i "sentry" /var/log/nectr/app.log
Look for warnings like “SENTRY_MCP_URL not configured”.
4
Verify file paths match Sentry
Sentry tracks file paths from stack traces. Ensure your MCP server
query matches Sentry’s file path format (e.g., app/services/auth.py
vs services/auth.py).