feat(backend): Add Sentry performance integrations for better tracing#11969
feat(backend): Add Sentry performance integrations for better tracing#11969
Conversation
…erformance tracing Adds FastApiIntegration and HttpxIntegration to Sentry SDK initialization to enable: - Detailed span tracking for FastAPI request handling - Automatic tracing of outgoing HTTP calls (OpenAI, external APIs, etc.) This improves visibility in Sentry Performance for debugging slow requests and identifying bottlenecks in external API calls.
WalkthroughThe pull request adds Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@claude update this to follow the pr template |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@autogpt_platform/backend/backend/util/metrics.py`:
- Around line 41-44: The sentry-sdk extras in pyproject.toml are missing
"httpx", which prevents HttpxIntegration from working; update the sentry-sdk
dependency entry to include "httpx" in its extras list (so it contains
"anthropic", "fastapi", "httpx", "launchdarkly", "openai", "sqlalchemy") to
ensure HttpxIntegration used in metrics.py (HttpxIntegration) is properly
enabled.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
autogpt_platform/backend/backend/util/metrics.py
🧰 Additional context used
📓 Path-based instructions (4)
autogpt_platform/backend/**/*.py
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
autogpt_platform/backend/**/*.py: Use Python 3.11 (required; managed by Poetry via pyproject.toml) for backend development
Always run 'poetry run format' (Black + isort) before linting in backend development
Always run 'poetry run lint' (ruff) after formatting in backend development
Files:
autogpt_platform/backend/backend/util/metrics.py
autogpt_platform/backend/**/*.{py,txt}
📄 CodeRabbit inference engine (autogpt_platform/backend/CLAUDE.md)
Use
poetry runprefix for all Python commands, including testing, linting, formatting, and migrations
Files:
autogpt_platform/backend/backend/util/metrics.py
autogpt_platform/backend/backend/**/*.py
📄 CodeRabbit inference engine (autogpt_platform/backend/CLAUDE.md)
Use Prisma ORM for database operations in PostgreSQL with pgvector for embeddings
Files:
autogpt_platform/backend/backend/util/metrics.py
autogpt_platform/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
Format Python code with
poetry run format
Files:
autogpt_platform/backend/backend/util/metrics.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: types
- GitHub Check: Seer Code Review
- GitHub Check: test (3.12)
- GitHub Check: test (3.13)
- GitHub Check: test (3.11)
- GitHub Check: Check PR Status
🔇 Additional comments (1)
autogpt_platform/backend/backend/util/metrics.py (1)
9-10: LGTM for the added Sentry integration imports.They’re used below and look consistent with the intended integrations.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| AsyncioIntegration(), | ||
| FastApiIntegration(), # Traces FastAPI requests with detailed spans | ||
| HttpxIntegration(), # Traces outgoing HTTP calls (OpenAI, external APIs) | ||
| LoggingIntegration(sentry_logs_level=logging.INFO), |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check sentry-sdk and httpx in project configuration files
echo "=== sentry-sdk in pyproject.toml ==="
rg -A 2 -B 2 "sentry-sdk" pyproject.toml
echo -e "\n=== httpx in pyproject.toml ==="
rg -A 2 -B 2 "httpx" pyproject.toml
echo -e "\n=== sentry-sdk version in poetry.lock ==="
rg -A 5 'name = "sentry-sdk"' poetry.lock | head -20
echo -e "\n=== httpx version in poetry.lock ==="
rg -A 5 'name = "httpx"' poetry.lock | head -20Repository: Significant-Gravitas/AutoGPT
Length of output: 453
🏁 Script executed:
#!/bin/bash
# Find pyproject.toml and poetry.lock files
echo "=== Locating pyproject.toml ==="
find . -name "pyproject.toml" -type f 2>/dev/null
echo -e "\n=== Locating poetry.lock ==="
find . -name "poetry.lock" -type f 2>/dev/nullRepository: Significant-Gravitas/AutoGPT
Length of output: 512
🏁 Script executed:
#!/bin/bash
cd autogpt_platform/backend
echo "=== sentry-sdk in pyproject.toml ==="
rg -A 2 -B 2 "sentry-sdk" pyproject.toml
echo -e "\n=== httpx in pyproject.toml ==="
rg -A 2 -B 2 "httpx" pyproject.toml
echo -e "\n=== sentry-sdk version in poetry.lock ==="
rg -A 5 'name = "sentry-sdk"' poetry.lock | head -20
echo -e "\n=== httpx version in poetry.lock ==="
rg -A 5 'name = "httpx"' poetry.lock | head -20Repository: Significant-Gravitas/AutoGPT
Length of output: 824
🏁 Script executed:
#!/bin/bash
# Check the actual integrations being imported in metrics.py
echo "=== Imports in metrics.py ==="
cd autogpt_platform/backend
head -50 backend/util/metrics.py | rg -A 20 "import\|from"Repository: Significant-Gravitas/AutoGPT
Length of output: 101
🌐 Web query:
sentry-sdk 2.44.0 FastApiIntegration HttpxIntegration availability
💡 Result:
In sentry-sdk 2.44.0 (released Nov 11, 2025), both integrations are available:
- FastAPI:
from sentry_sdk.integrations.fastapi import FastApiIntegration(installable via thefastapiextra) [1][2][3] - httpx:
from sentry_sdk.integrations.httpx import HttpxIntegration(installable via thehttpxextra; also used for automatic outgoing HTTP tracing/headers when enabled) [2][4][5]
Install examples:
pip install "sentry-sdk[fastapi]==2.44.0"[2]pip install "sentry-sdk[httpx]==2.44.0"[2]
Sources: [1] https://github.com/getsentry/sentry-python/releases (2.44.0), [2] https://pypi.org/project/sentry-sdk/ (extras list includes fastapi, httpx), [3] https://gitlab.donnees.incubateur.anct.gouv.fr/infrastructure/insitu/-/merge_requests/1374 (FastApiIntegration import snippet), [4] https://www.mail-archive.com/[email protected]/msg22390.html (shows __all__ = ["HttpxIntegration"] and class), [5] https://docs.sentry.io/platforms/python/tracing/configure-sampling__v3.x (mentions httpx auto-instrumentation/headers).
Add httpx to sentry-sdk extras in pyproject.toml.
sentry-sdk 2.44.0 supports both FastApiIntegration and HttpxIntegration, and the fastapi extra is installed. However, the httpx extra is missing from the sentry-sdk extras list. To ensure HttpxIntegration functions properly, update the sentry-sdk dependency to include httpx in its extras:
sentry-sdk = {extras = ["anthropic", "fastapi", "httpx", "launchdarkly", "openai", "sqlalchemy"], version = "^2.44.0"}🤖 Prompt for AI Agents
In `@autogpt_platform/backend/backend/util/metrics.py` around lines 41 - 44, The
sentry-sdk extras in pyproject.toml are missing "httpx", which prevents
HttpxIntegration from working; update the sentry-sdk dependency entry to include
"httpx" in its extras list (so it contains "anthropic", "fastapi", "httpx",
"launchdarkly", "openai", "sqlalchemy") to ensure HttpxIntegration used in
metrics.py (HttpxIntegration) is properly enabled.
|
Claude finished @ntindle's task in 51s —— View job Updated PR to follow template
Updated the PR description to match |
Changes 🏗️
FastApiIntegration()tosentry_sdk.init()— traces FastAPI request handling with detailed spans (middleware, route handlers, dependencies)HttpxIntegration()tosentry_sdk.init()— traces outgoing HTTP calls (OpenAI, Anthropic, external APIs)sentry_sdk.integrations.fastapiandsentry_sdk.integrations.httpxChecklist 📋
For code changes:
Example test plan
For configuration changes:
.env.defaultis updated or already compatible with my changesdocker-compose.ymlis updated or already compatible with my changesExamples of configuration changes