Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(observability): fail open on Sentry startup errors

cyh7a171dfa5208
diff --git a/tests/test_sentry_integration.py b/tests/test_sentry_integration.py
index 3e238c597..19287459c 100644
--- a/tests/test_sentry_integration.py
+++ b/tests/test_sentry_integration.py
@@ -1,6 +1,8 @@
from __future__ import annotations
import sys
+import types
+import importlib
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
@@ -62,6 +64,83 @@ def test_build_sentry_contexts_contains_debug_metadata(monkeypatch):
assert "hostname" in contexts["host"]
+def test_init_sentry_returns_false_when_sdk_init_raises(monkeypatch):
+ monkeypatch.setenv("VIBE_SENTRY_DSN", "https://[email protected]/2")
+
+ sentry_sdk = types.ModuleType("sentry_sdk")
+ sentry_sdk.init = lambda **kwargs: (_ for _ in ()).throw(ValueError("bad dsn"))
+ sentry_sdk.set_tag = lambda *args, **kwargs: None
+ sentry_sdk.set_context = lambda *args, **kwargs: None
+
+ logging_integration_module = types.ModuleType("sentry_sdk.integrations.logging")
+
+ class FakeLoggingIntegration:
+ def __init__(self, *args, **kwargs):
+ self.args = args
+ self.kwargs = kwargs
+
+ logging_integration_module.LoggingIntegration = FakeLoggingIntegration
+
+ monkeypatch.setitem(sys.modules, "sentry_sdk", sentry_sdk)
+ monkeypatch.setitem(sys.modules, "sentry_sdk.integrations.logging", logging_integration_module)
+
+ assert sentry_integration.init_sentry(_config(), component="service") is False
+
+
+def test_run_ui_server_skips_sentry_when_config_load_fails(monkeypatch):
+ fake_flask = types.ModuleType("flask")
+
+ class FakeFlask:
+ def __init__(self, *args, **kwargs):
+ self.args = args
+ self.kwargs = kwargs
+
+ def route(self, *args, **kwargs):
+ def decorator(func):
+ return func
+
+ return decorator
+
+ def errorhandler(self, *args, **kwargs):
+ def decorator(func):
+ return func
+
+ return decorator
+
+ fake_flask.Flask = FakeFlask
+ fake_flask.request = types.SimpleNamespace(json=None, args={})
+ fake_flask.jsonify = lambda *args, **kwargs: {"args": args, "kwargs": kwargs}
+ fake_flask.send_file = lambda *args, **kwargs: None
+ fake_flask.Response = object
+ monkeypatch.setitem(sys.modules, "flask", fake_flask)
+
+ fake_werkzeug = types.ModuleType("werkzeug")
+ fake_werkzeug_serving = types.ModuleType("werkzeug.serving")
+
+ ui_server = importlib.import_module("vibe.ui_server")
+
+ class DummyServer:
+ def serve_forever(self):
+ return None
+
+ fake_werkzeug_serving.make_server = lambda *args, **kwargs: DummyServer()
+ monkeypatch.setitem(sys.modules, "werkzeug", fake_werkzeug)
+ monkeypatch.setitem(sys.modules, "werkzeug.serving", fake_werkzeug_serving)
+
+ monkeypatch.setattr(ui_server.paths, "ensure_data_dirs", lambda: None)
+ monkeypatch.setattr(
+ ui_server.V2Config,
+ "load",
+ lambda *args, **kwargs: (_ for _ in ()).throw(ValueError("bad config")),
+ )
+ sentry_calls = []
+ monkeypatch.setattr(ui_server, "init_sentry", lambda *args, **kwargs: sentry_calls.append((args, kwargs)))
+
+ ui_server.run_ui_server("127.0.0.1", 0)
+
+ assert sentry_calls == []
+
+
def test_scrub_data_redacts_sensitive_values():
event = {
"request": {
diff --git a/vibe/sentry_integration.py b/vibe/sentry_integration.py
index f73dc9306..1d8ceb83a 100644
--- a/vibe/sentry_integration.py
+++ b/vibe/sentry_integration.py
@@ -195,28 +195,32 @@ def init_sentry(config: V2Config, component: str, enable_flask: bool = False) ->
from vibe import __version__
- sentry_sdk.init(
- dsn=options["dsn"],
- environment=options["environment"],
- release=f"vibe-remote@{__version__}",
- integrations=integrations,
- before_send=before_send,
- before_breadcrumb=before_breadcrumb,
- attach_stacktrace=True,
- ignore_errors=[KeyboardInterrupt, SystemExit],
- max_breadcrumbs=50,
- sample_rate=1.0,
- traces_sample_rate=options["traces_sample_rate"],
- profiles_sample_rate=options["profiles_sample_rate"],
- send_default_pii=True,
- server_name=socket.gethostname(),
- )
- sentry_sdk.set_tag("component", component)
- sentry_sdk.set_tag("mode", config.mode)
- sentry_sdk.set_tag("primary_platform", config.platforms.primary)
- sentry_sdk.set_tag("deployment_environment", options["environment"])
- for name, context in build_sentry_contexts(config, component, options["environment"]).items():
- sentry_sdk.set_context(name, context)
+ try:
+ sentry_sdk.init(
+ dsn=options["dsn"],
+ environment=options["environment"],
+ release=f"vibe-remote@{__version__}",
+ integrations=integrations,
+ before_send=before_send,
+ before_breadcrumb=before_breadcrumb,
+ attach_stacktrace=True,
+ ignore_errors=[KeyboardInterrupt, SystemExit],
+ max_breadcrumbs=50,
+ sample_rate=1.0,
+ traces_sample_rate=options["traces_sample_rate"],
+ profiles_sample_rate=options["profiles_sample_rate"],
+ send_default_pii=True,
+ server_name=socket.gethostname(),
+ )
+ sentry_sdk.set_tag("component", component)
+ sentry_sdk.set_tag("mode", config.mode)
+ sentry_sdk.set_tag("primary_platform", config.platforms.primary)
+ sentry_sdk.set_tag("deployment_environment", options["environment"])
+ for name, context in build_sentry_contexts(config, component, options["environment"]).items():
+ sentry_sdk.set_context(name, context)
+ except Exception as exc:
+ logger.warning("Sentry initialization failed for %s: %s", component, exc)
+ return False
logger.info("Sentry initialized for %s (environment=%s)", component, options["environment"])
return True
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 88090b6f7..bd5a4835e 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -854,6 +854,9 @@ def run_ui_server(host: str, port: int) -> None:
config = V2Config.load()
except FileNotFoundError:
config = None
+ except Exception as exc:
+ logger.warning("Skipping UI Sentry init because config load failed: %s", exc)
+ config = None
if config is not None:
init_sentry(config, component="ui", enable_flask=True)
print(f"UI Server running at http://{host}:{port}")