Skip to content

Commit aefc4de

Browse files
committed
fix deploy
1 parent de4902a commit aefc4de

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎app/celery_app.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
import sentry_sdk
55
from celery import Celery
66

7+
from utils.sentry import integration_options as sentry_integration_options
8+
79
SENTRY_DSN = "https://[email protected]/4510944527515648"
810
DEVELOPMENT = os.getenv("DEVELOPMENT", 0)
911

12+
1013
if not DEVELOPMENT:
1114
sentry_sdk.init(
1215
dsn=SENTRY_DSN,
1316
send_default_pii=True,
17+
**sentry_integration_options(),
1418
)
1519

1620
REDIS_URL = os.getenv("REDIS_URL", "redis://redis:6379/0")

‎app/main.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from sqlalchemy import create_engine
66

77
from utils.consts import DATABASE_URL, DEVELOPMENT, APP_HOST
8+
from utils.sentry import integration_options as sentry_integration_options
89
from api import user, resources, item, item_lifecycle, benchmark, trip, category, pack, kit, hiker_profile, webhook
910

1011
ENGINE_KWARGS = dict(
@@ -26,6 +27,7 @@
2627
# Add data like request headers and IP for users,
2728
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
2829
send_default_pii=True,
30+
**sentry_integration_options(),
2931
)
3032

3133
app = FastAPI()

‎app/utils/sentry.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Sentry init options shared by the API process and the Celery worker."""
2+
3+
4+
def integration_options() -> dict:
5+
"""Keep Sentry's auto-enabled OpenAI integration from importing openai.
6+
7+
Auto-enabled integrations import their target library at startup. The API
8+
never uses openai, but an incompatible release on disk (3.x, which needs
9+
httpx2 and breaks under pydantic<2) took the whole process down through
10+
this hook. The integration module itself imports openai at import time,
11+
so if even that fails, fall back to disabling auto-enabling entirely
12+
rather than crash.
13+
"""
14+
try:
15+
from sentry_sdk.integrations.openai import OpenAIIntegration
16+
except Exception:
17+
return {"auto_enabling_integrations": False}
18+
return {"disabled_integrations": [OpenAIIntegration()]}

‎requirements.txt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ requests==2.31.0
33
passlib==1.7.2
44
google-auth
55
cryptography
6-
openai
6+
# 3.x switched to httpx2, which breaks under pydantic<2 at import time. Only
7+
# ai/sanitize.py uses this; the API itself never imports it.
8+
openai<3
79
python-dotenv==1.0.0
810

911
psycopg2-binary==2.9.9

0 commit comments

Comments
 (0)