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.

refactor(observability): make Sentry deployment-owned

cyha70c53cf1020
diff --git a/config/v2_config.py b/config/v2_config.py
index 5d9571438..b923a94e2 100644
--- a/config/v2_config.py
+++ b/config/v2_config.py
@@ -101,22 +101,6 @@ class RuntimeConfig:
log_level: str = "INFO"
-@dataclass
-class SentryConfig:
- dsn: Optional[str] = None
- environment: Optional[str] = None
- traces_sample_rate: float = 0.0
- profiles_sample_rate: float = 0.0
- send_default_pii: bool = False
-
- def validate(self) -> None:
- for field_name in ("traces_sample_rate", "profiles_sample_rate"):
- value = getattr(self, field_name)
- if not isinstance(value, (int, float)) or not 0.0 <= float(value) <= 1.0:
- raise ValueError(f"Config 'sentry.{field_name}' must be a number between 0 and 1")
- setattr(self, field_name, float(value))
-
-
@dataclass
class OpenCodeConfig:
enabled: bool = True
@@ -207,7 +191,6 @@ class V2Config:
lark: Optional[LarkConfig] = None
wechat: Optional[WeChatConfig] = None
gateway: Optional[GatewayConfig] = None
- sentry: Optional[SentryConfig] = None
ui: UiConfig = field(default_factory=UiConfig)
update: UpdateConfig = field(default_factory=UpdateConfig)
ack_mode: str = "typing"
@@ -311,14 +294,6 @@ class V2Config:
raise ValueError("Config 'gateway' must be an object")
gateway = GatewayConfig(**_filter_dataclass_fields(GatewayConfig, gateway_payload)) if gateway_payload else None
- sentry_payload = payload.get("sentry")
- if sentry_payload is not None and not isinstance(sentry_payload, dict):
- raise ValueError("Config 'sentry' must be an object")
- sentry = None
- if sentry_payload is not None:
- sentry = SentryConfig(**_filter_dataclass_fields(SentryConfig, sentry_payload))
- sentry.validate()
-
runtime_payload = payload.get("runtime")
if not isinstance(runtime_payload, dict):
raise ValueError("Config 'runtime' must be an object")
@@ -398,7 +373,6 @@ class V2Config:
runtime=runtime,
agents=agents,
gateway=gateway,
- sentry=sentry,
ui=ui,
update=update,
ack_mode=ack_mode,
@@ -436,7 +410,6 @@ class V2Config:
"codex": self.agents.codex.__dict__,
},
"gateway": self.gateway.__dict__ if self.gateway else None,
- "sentry": self.sentry.__dict__ if self.sentry else None,
"ui": self.ui.__dict__,
"update": self.update.__dict__,
"ack_mode": self.ack_mode,
diff --git a/docker-compose.three-regression.yml b/docker-compose.three-regression.yml
index 9d587e568..dbc38e67e 100644
--- a/docker-compose.three-regression.yml
+++ b/docker-compose.three-regression.yml
@@ -8,6 +8,7 @@ services:
command: ["full"]
environment:
VIBE_REMOTE_HOME: /data/vibe_remote
+ VIBE_DEPLOYMENT_ENV: regression
VIBE_UI_PORT: 5123
PYTHONUNBUFFERED: "1"
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
diff --git a/docs/CLI.md b/docs/CLI.md
index 9f6ea3dd2..74929159d 100644
--- a/docs/CLI.md
+++ b/docs/CLI.md
@@ -244,10 +244,6 @@ The web UI (`http://127.0.0.1:5123`) provides the same controls:
| Variable | Description |
|----------|-------------|
| `OPENCODE_PORT` | Override OpenCode server port (default: 4096) |
-| `VIBE_SENTRY_DSN` / `SENTRY_DSN` | Enable Sentry error reporting for the main service and Web UI |
-| `VIBE_SENTRY_ENVIRONMENT` / `SENTRY_ENVIRONMENT` | Override the Sentry environment tag |
-| `VIBE_SENTRY_TRACES_SAMPLE_RATE` | Override Sentry traces sample rate (0.0-1.0) |
-| `VIBE_SENTRY_PROFILES_SAMPLE_RATE` | Override Sentry profiles sample rate (0.0-1.0) |
## See Also
diff --git a/docs/CLI_ZH.md b/docs/CLI_ZH.md
index 753f9079f..af10d5161 100644
--- a/docs/CLI_ZH.md
+++ b/docs/CLI_ZH.md
@@ -244,10 +244,6 @@ Web UI (`http://127.0.0.1:5123`) 提供相同的控制功能:
| 变量 | 说明 |
|------|------|
| `OPENCODE_PORT` | 覆盖 OpenCode 服务器端口(默认:4096) |
-| `VIBE_SENTRY_DSN` / `SENTRY_DSN` | 为主服务和 Web UI 启用 Sentry 错误上报 |
-| `VIBE_SENTRY_ENVIRONMENT` / `SENTRY_ENVIRONMENT` | 覆盖 Sentry 的 environment 标签 |
-| `VIBE_SENTRY_TRACES_SAMPLE_RATE` | 覆盖 Sentry traces 采样率(0.0-1.0) |
-| `VIBE_SENTRY_PROFILES_SAMPLE_RATE` | 覆盖 Sentry profiles 采样率(0.0-1.0) |
## 另请参阅
diff --git a/tests/test_api_save_config_merge.py b/tests/test_api_save_config_merge.py
index 0f6d688a2..8341273ee 100644
--- a/tests/test_api_save_config_merge.py
+++ b/tests/test_api_save_config_merge.py
@@ -62,13 +62,6 @@ def _full_config_payload() -> dict:
},
},
"gateway": None,
- "sentry": {
- "dsn": "https://[email protected]/1",
- "environment": "test",
- "traces_sample_rate": 0.0,
- "profiles_sample_rate": 0.0,
- "send_default_pii": False,
- },
"ui": {
"setup_host": "127.0.0.1",
"setup_port": 5123,
@@ -103,8 +96,6 @@ def test_save_config_merges_partial_payload(monkeypatch, tmp_path):
assert updated.discord is not None
assert updated.discord.bot_token == "discord-token-1234567890"
assert updated.runtime.default_cwd == "/tmp/workdir"
- assert updated.sentry is not None
- assert updated.sentry.dsn == "https://[email protected]/1"
def test_save_config_accepts_typing_ack_mode(monkeypatch, tmp_path):
@@ -162,18 +153,6 @@ def test_save_config_rejects_enabled_platform_without_credentials(monkeypatch, t
}
)
-
-def test_save_config_round_trips_sentry_config(monkeypatch, tmp_path):
- monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
-
- updated = api.save_config(_full_config_payload())
- payload = api.config_to_payload(updated)
-
- assert payload["sentry"]["dsn"] == "https://[email protected]/1"
- assert payload["sentry"]["environment"] == "test"
- assert payload["sentry"]["traces_sample_rate"] == 0.0
-
-
def test_init_sessions_is_noop_when_sessions_file_exists(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
diff --git a/tests/test_sentry_integration.py b/tests/test_sentry_integration.py
index dd58b5a4e..c545cd7ec 100644
--- a/tests/test_sentry_integration.py
+++ b/tests/test_sentry_integration.py
@@ -1,41 +1,25 @@
from __future__ import annotations
-import os
+from config.v2_config import AgentsConfig, RuntimeConfig, SlackConfig, V2Config
+from vibe import sentry_integration
-from config.v2_config import (
- AgentsConfig,
- RuntimeConfig,
- SentryConfig,
- SlackConfig,
- V2Config,
-)
-from vibe.sentry_integration import resolve_sentry_options, scrub_data
-
-def _config_with_sentry() -> V2Config:
+def _config() -> V2Config:
return V2Config(
mode="self_host",
version="v2",
slack=SlackConfig(bot_token=""),
runtime=RuntimeConfig(default_cwd="/tmp/workdir", log_level="INFO"),
agents=AgentsConfig(),
- sentry=SentryConfig(
- dsn="https://[email protected]/1",
- environment="config-env",
- traces_sample_rate=0.0,
- profiles_sample_rate=0.0,
- send_default_pii=False,
- ),
)
def test_resolve_sentry_options_prefers_environment(monkeypatch):
monkeypatch.setenv("VIBE_SENTRY_DSN", "https://[email protected]/2")
- monkeypatch.setenv("VIBE_SENTRY_ENVIRONMENT", "regression")
+ monkeypatch.setenv("VIBE_DEPLOYMENT_ENV", "regression")
monkeypatch.setenv("VIBE_SENTRY_TRACES_SAMPLE_RATE", "0.25")
- config = _config_with_sentry()
- options = resolve_sentry_options(config)
+ options = sentry_integration.resolve_sentry_options()
assert options is not None
assert options["dsn"] == "https://[email protected]/2"
@@ -46,10 +30,31 @@ def test_resolve_sentry_options_prefers_environment(monkeypatch):
def test_resolve_sentry_options_returns_none_without_dsn(monkeypatch):
monkeypatch.delenv("VIBE_SENTRY_DSN", raising=False)
monkeypatch.delenv("SENTRY_DSN", raising=False)
- config = _config_with_sentry()
- config.sentry = SentryConfig()
+ monkeypatch.setattr(sentry_integration, "DEFAULT_SENTRY_DSN", "")
+
+ assert sentry_integration.resolve_sentry_options() is None
+
+
+def test_detect_sentry_environment_defaults_to_development(monkeypatch):
+ monkeypatch.delenv("VIBE_SENTRY_ENVIRONMENT", raising=False)
+ monkeypatch.delenv("SENTRY_ENVIRONMENT", raising=False)
+ monkeypatch.delenv("VIBE_DEPLOYMENT_ENV", raising=False)
+ monkeypatch.setenv("VIBE_REMOTE_HOME", "/tmp/vibe-remote-home")
+ monkeypatch.setattr(sentry_integration, "Path", lambda _: type("P", (), {"exists": staticmethod(lambda: False)})())
+
+ assert sentry_integration.detect_sentry_environment() == "development"
+
+
+def test_build_sentry_contexts_contains_debug_metadata(monkeypatch):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", "/tmp/vibe-remote-home")
+
+ contexts = sentry_integration.build_sentry_contexts(_config(), component="service", environment="regression")
- assert resolve_sentry_options(config) is None
+ assert contexts["deployment"]["environment"] == "regression"
+ assert contexts["deployment"]["component"] == "service"
+ assert contexts["deployment"]["default_backend"] == "opencode"
+ assert contexts["runtime"]["python_version"]
+ assert "hostname" in contexts["host"]
def test_scrub_data_redacts_sensitive_values():
@@ -61,7 +66,7 @@ def test_scrub_data_redacts_sensitive_values():
"message": "token=abc123 and xapp-123456",
}
- scrubbed = scrub_data(event)
+ scrubbed = sentry_integration.scrub_data(event)
assert scrubbed["request"]["headers"]["Authorization"] == "[Filtered]"
assert scrubbed["request"]["headers"]["Cookie"] == "[Filtered]"
diff --git a/ui/src/components/Dashboard.tsx b/ui/src/components/Dashboard.tsx
index 1b6fbc6c6..e314c1252 100644
--- a/ui/src/components/Dashboard.tsx
+++ b/ui/src/components/Dashboard.tsx
@@ -94,21 +94,11 @@ export const Dashboard: React.FC = () => {
setDiagnosticsSaving(true);
setDiagnosticsMessage(null);
try {
- const sentryDsn = (config.sentry?.dsn || '').trim();
- const sentryEnvironment = (config.sentry?.environment || '').trim();
- const sentryPayload = sentryDsn || sentryEnvironment || config.sentry?.traces_sample_rate || config.sentry?.profiles_sample_rate || config.sentry?.send_default_pii
- ? {
- ...(config.sentry || {}),
- dsn: sentryDsn || null,
- environment: sentryEnvironment || null,
- }
- : null;
const runtimePayload = {
log_level: config.runtime?.log_level || 'INFO',
};
const configPayload = {
runtime: runtimePayload,
- sentry: sentryPayload,
};
await fetch('/config', {
method: 'POST',
@@ -531,43 +521,6 @@ export const Dashboard: React.FC = () => {
))}
</select>
</div>
- <div className="flex justify-between items-center">
- <span className="text-muted">{t('dashboard.sentryDsn')}</span>
- <input
- type="password"
- value={config.sentry?.dsn || ''}
- onChange={(e) => {
- const dsn = e.target.value;
- setDiagnosticsMessage(null);
- setConfig((prev: any) => ({
- ...prev,
- sentry: { ...(prev.sentry || {}), dsn },
- }));
- }}
- placeholder="https://..."
- className="w-64 bg-neutral-100 border border-border rounded px-2 py-1 text-xs font-mono"
- />
- </div>
- <div className="flex justify-between items-center">
- <span className="text-muted">{t('dashboard.sentryEnvironment')}</span>
- <input
- type="text"
- value={config.sentry?.environment || ''}
- onChange={(e) => {
- const environment = e.target.value;
- setDiagnosticsMessage(null);
- setConfig((prev: any) => ({
- ...prev,
- sentry: { ...(prev.sentry || {}), environment },
- }));
- }}
- placeholder="production"
- className="w-40 bg-neutral-100 border border-border rounded px-2 py-1 text-xs font-mono"
- />
- </div>
- <div className="text-xs text-muted">
- {t('dashboard.sentryHint')}
- </div>
<div className="flex justify-between items-center">
<span className="text-muted">{t('dashboard.configFile')}</span>
<code className="font-mono text-xs bg-neutral-100 px-2 py-1 rounded text-text">~/.vibe_remote/config/config.json</code>
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 24f7f82aa..6829d2bd2 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -414,9 +414,6 @@
"port": "Port",
"diagnostics": "Diagnostics",
"logLevel": "Log Level",
- "sentryDsn": "Sentry DSN",
- "sentryEnvironment": "Sentry Environment",
- "sentryHint": "Leave DSN empty to disable. Advanced sample-rate overrides remain available via env vars or config JSON.",
"configFile": "Config File",
"logs": "Logs",
"uiRestartMessage": "Saved. Restarting UI server...",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 765b1ad63..bd0d38286 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -414,9 +414,6 @@
"port": "端口",
"diagnostics": "诊断",
"logLevel": "日志级别",
- "sentryDsn": "Sentry DSN",
- "sentryEnvironment": "Sentry 环境",
- "sentryHint": "DSN 留空即禁用。更高级的采样率覆盖仍可通过环境变量或 config JSON 设置。",
"configFile": "配置文件",
"logs": "日志",
"uiRestartMessage": "已保存,正在重启 UI 服务器...",
diff --git a/vibe/api.py b/vibe/api.py
index 4417e9f1a..9b6cc7fc7 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -267,7 +267,6 @@ def config_to_payload(config: V2Config) -> dict:
"codex": config.agents.codex.__dict__,
},
"gateway": config.gateway.__dict__ if config.gateway else None,
- "sentry": config.sentry.__dict__ if config.sentry else None,
"ui": config.ui.__dict__,
"update": config.update.__dict__,
"ack_mode": config.ack_mode,
diff --git a/vibe/sentry_integration.py b/vibe/sentry_integration.py
index 7871dba49..ccc56cc14 100644
--- a/vibe/sentry_integration.py
+++ b/vibe/sentry_integration.py
@@ -2,13 +2,23 @@ from __future__ import annotations
import logging
import os
+import platform
import re
+import socket
+import sys
+from pathlib import Path
from typing import Any, Optional
from config.v2_config import V2Config
logger = logging.getLogger(__name__)
+# Fill this with the real project DSN to make Sentry default-on in production.
+DEFAULT_SENTRY_DSN = ""
+DEFAULT_TRACES_SAMPLE_RATE = 0.0
+DEFAULT_PROFILES_SAMPLE_RATE = 0.0
+DEPLOYMENT_ENV_VAR = "VIBE_DEPLOYMENT_ENV"
+
_SENSITIVE_KEY_PARTS = (
"access_key",
"api_key",
@@ -79,33 +89,71 @@ def _safe_float(raw: Optional[str], fallback: float) -> float:
return fallback
-def resolve_sentry_options(config: V2Config) -> Optional[dict[str, Any]]:
- sentry_config = getattr(config, "sentry", None)
- env_dsn = os.environ.get("VIBE_SENTRY_DSN") or os.environ.get("SENTRY_DSN")
- dsn = env_dsn or (sentry_config.dsn if sentry_config else None)
+def detect_sentry_environment() -> str:
+ explicit = os.environ.get("VIBE_SENTRY_ENVIRONMENT") or os.environ.get("SENTRY_ENVIRONMENT")
+ if explicit:
+ return explicit.strip()
+
+ deployment = os.environ.get(DEPLOYMENT_ENV_VAR)
+ if deployment:
+ return deployment.strip()
+
+ vibe_home = os.environ.get("VIBE_REMOTE_HOME", "")
+ if "three-regression" in vibe_home:
+ return "regression"
+
+ if Path("/.dockerenv").exists():
+ return "production"
+
+ return "development"
+
+
+def resolve_sentry_options() -> Optional[dict[str, Any]]:
+ dsn = os.environ.get("VIBE_SENTRY_DSN") or os.environ.get("SENTRY_DSN") or DEFAULT_SENTRY_DSN
if not dsn:
return None
- environment = (
- os.environ.get("VIBE_SENTRY_ENVIRONMENT")
- or os.environ.get("SENTRY_ENVIRONMENT")
- or (sentry_config.environment if sentry_config else None)
- or config.mode
- )
- traces_sample_rate = _safe_float(
- os.environ.get("VIBE_SENTRY_TRACES_SAMPLE_RATE"),
- sentry_config.traces_sample_rate if sentry_config else 0.0,
- )
- profiles_sample_rate = _safe_float(
- os.environ.get("VIBE_SENTRY_PROFILES_SAMPLE_RATE"),
- sentry_config.profiles_sample_rate if sentry_config else 0.0,
- )
return {
"dsn": dsn,
- "environment": environment,
- "traces_sample_rate": traces_sample_rate,
- "profiles_sample_rate": profiles_sample_rate,
- "send_default_pii": bool(sentry_config.send_default_pii) if sentry_config else False,
+ "environment": detect_sentry_environment(),
+ "traces_sample_rate": _safe_float(
+ os.environ.get("VIBE_SENTRY_TRACES_SAMPLE_RATE"),
+ DEFAULT_TRACES_SAMPLE_RATE,
+ ),
+ "profiles_sample_rate": _safe_float(
+ os.environ.get("VIBE_SENTRY_PROFILES_SAMPLE_RATE"),
+ DEFAULT_PROFILES_SAMPLE_RATE,
+ ),
+ }
+
+
+def build_sentry_contexts(config: V2Config, component: str, environment: str) -> dict[str, dict[str, Any]]:
+ vibe_home = os.environ.get("VIBE_REMOTE_HOME") or str(Path.home() / ".vibe_remote")
+ return {
+ "runtime": {
+ "python_version": platform.python_version(),
+ "python_implementation": platform.python_implementation(),
+ "platform": sys.platform,
+ },
+ "host": {
+ "hostname": socket.gethostname(),
+ "system": platform.system(),
+ "release": platform.release(),
+ "version": platform.version(),
+ "machine": platform.machine(),
+ "processor": platform.processor() or None,
+ "docker": Path("/.dockerenv").exists(),
+ },
+ "deployment": {
+ "component": component,
+ "environment": environment,
+ "mode": config.mode,
+ "primary_platform": config.platforms.primary,
+ "enabled_platforms": config.platforms.enabled,
+ "default_backend": config.agents.default_backend,
+ "cwd": config.runtime.default_cwd,
+ "vibe_home": vibe_home,
+ },
}
@@ -120,7 +168,7 @@ def before_breadcrumb(crumb: dict[str, Any], hint: dict[str, Any]) -> dict[str,
def init_sentry(config: V2Config, component: str, enable_flask: bool = False) -> bool:
- options = resolve_sentry_options(config)
+ options = resolve_sentry_options()
if not options:
return False
@@ -157,20 +205,18 @@ def init_sentry(config: V2Config, component: str, enable_flask: bool = False) ->
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=options["send_default_pii"],
+ send_default_pii=False,
+ 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_context(
- "vibe_remote",
- {
- "enabled_platforms": config.platforms.enabled,
- "default_backend": config.agents.default_backend,
- },
- )
+ 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)
logger.info("Sentry initialized for %s (environment=%s)", component, options["environment"])
return True