Seth McKnight commited on
Commit
d14a473
·
1 Parent(s): 74e758d

feat: Add specific error handling for LLM configuration in health checks (#55)

Browse files
Files changed (1) hide show
  1. app.py +31 -7
app.py CHANGED
@@ -9,17 +9,41 @@ from flask import Flask, jsonify, render_template, request
9
  # Load environment variables from .env file
10
  load_dotenv()
11
 
12
- # Disable ChromaDB anonymized telemetry for local development so the
13
- # library doesn't attempt to call external PostHog telemetry endpoints.
14
- # This avoids noisy errors in server logs and respects developer privacy.
 
 
 
 
 
 
 
 
15
  try:
16
  import chromadb
17
 
18
- # Turn off anonymized telemetry (the chromadb package defaults this to True)
19
- # Using Any type to avoid issues with unknown parameters
20
- chromadb.configure(anonymized_telemetry=False) # type: ignore
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  except Exception:
22
- # If chromadb isn't installed in this environment yet, ignore silently.
23
  pass
24
 
25
  app = Flask(__name__)
 
9
  # Load environment variables from .env file
10
  load_dotenv()
11
 
12
+ # Proactively disable ChromaDB telemetry via environment variables so
13
+ # the library doesn't attempt to call external PostHog telemetry endpoints.
14
+ # This helps avoid noisy errors in server logs (Render may not expose
15
+ # the expected device files or telemetry endpoints).
16
+ os.environ.setdefault("ANONYMIZED_TELEMETRY", "False")
17
+ os.environ.setdefault("CHROMA_TELEMETRY", "False")
18
+
19
+ # Attempt to configure chromadb and monkeypatch any telemetry capture
20
+ # functions to be no-ops. Some chromadb versions call posthog.capture
21
+ # with a different signature which can raise exceptions during runtime
22
+ # (observed on Render as: capture() takes 1 positional argument but 3 were given).
23
  try:
24
  import chromadb
25
 
26
+ try:
27
+ chromadb.configure(anonymized_telemetry=False) # type: ignore
28
+ except Exception:
29
+ # Non-fatal: continue and still try to neutralize telemetry functions
30
+ pass
31
+
32
+ # Defensive monkeypatch: if the telemetry client exists, replace capture
33
+ # with a safe no-op that accepts any args/kwargs to avoid signature issues.
34
+ try:
35
+ from chromadb.telemetry.product import posthog as _posthog # type: ignore
36
+
37
+ # Replace module-level capture and Posthog.capture if present
38
+ if hasattr(_posthog, "capture"):
39
+ setattr(_posthog, "capture", lambda *args, **kwargs: None)
40
+ if hasattr(_posthog, "Posthog") and hasattr(_posthog.Posthog, "capture"):
41
+ setattr(_posthog.Posthog, "capture", lambda *args, **kwargs: None)
42
+ except Exception:
43
+ # If telemetry internals aren't present or change across versions, ignore
44
+ pass
45
  except Exception:
46
+ # chromadb not installed or import failed; continue without telemetry
47
  pass
48
 
49
  app = Flask(__name__)