telemetry: use Cloud Run default, reject localhost overrides, add startup diagnostics, and normalize logging
- config: point telemetry_endpoint to Cloud Run default - telemetry: log effective endpoint/timeout; reject localhost endpoints - server: telemetry logger at normal level with rotating file; default timeout=5s when unsetmain
parent
9b5488dcaf
commit
33979d348b
|
|
@ -36,7 +36,8 @@ class ServerConfig:
|
|||
|
||||
# Telemetry settings
|
||||
telemetry_enabled: bool = True
|
||||
telemetry_endpoint: str = "https://unity-mcp-telemetry-a6uvvbgbsa-uc.a.run.app/telemetry/events"
|
||||
# Align with telemetry.py default Cloud Run endpoint
|
||||
telemetry_endpoint: str = "https://unity-mcp-telemetry-375728817078.us-central1.run.app/telemetry/events"
|
||||
|
||||
# Create a global config instance
|
||||
config = ServerConfig()
|
||||
|
|
@ -29,6 +29,14 @@ try:
|
|||
_fh.setFormatter(logging.Formatter(config.log_format))
|
||||
_fh.setLevel(getattr(logging, config.log_level))
|
||||
logger.addHandler(_fh)
|
||||
# Also route telemetry logger to the same rotating file and normal level
|
||||
try:
|
||||
tlog = logging.getLogger("unity-mcp-telemetry")
|
||||
tlog.setLevel(getattr(logging, config.log_level))
|
||||
tlog.addHandler(_fh)
|
||||
except Exception:
|
||||
# Never let logging setup break startup
|
||||
pass
|
||||
except Exception:
|
||||
# Never let logging setup break startup
|
||||
pass
|
||||
|
|
@ -40,6 +48,15 @@ for noisy in ("httpx", "urllib3"):
|
|||
pass
|
||||
|
||||
# Import telemetry only after logging is configured to ensure its logs use stderr and proper levels
|
||||
# Ensure a slightly higher telemetry timeout unless explicitly overridden by env
|
||||
try:
|
||||
|
||||
|
||||
# Ensure generous timeout unless explicitly overridden by env
|
||||
if not os.environ.get("UNITY_MCP_TELEMETRY_TIMEOUT"):
|
||||
os.environ["UNITY_MCP_TELEMETRY_TIMEOUT"] = "5.0"
|
||||
except Exception:
|
||||
pass
|
||||
from telemetry import record_telemetry, record_milestone, RecordType, MilestoneType
|
||||
|
||||
# Global connection state
|
||||
|
|
|
|||
|
|
@ -96,6 +96,15 @@ class TelemetryConfig:
|
|||
os.environ.get("UNITY_MCP_TELEMETRY_ENDPOINT", default_ep),
|
||||
default_ep,
|
||||
)
|
||||
try:
|
||||
logger.info(
|
||||
"Telemetry configured: endpoint=%s (default=%s), timeout_env=%s",
|
||||
self.endpoint,
|
||||
default_ep,
|
||||
os.environ.get("UNITY_MCP_TELEMETRY_TIMEOUT") or "<unset>"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Local storage for UUID and milestones
|
||||
self.data_dir = self._get_data_directory()
|
||||
|
|
@ -107,6 +116,10 @@ class TelemetryConfig:
|
|||
self.timeout = float(os.environ.get("UNITY_MCP_TELEMETRY_TIMEOUT", "1.5"))
|
||||
except Exception:
|
||||
self.timeout = 1.5
|
||||
try:
|
||||
logger.info("Telemetry timeout=%.2fs", self.timeout)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Session tracking
|
||||
self.session_id = str(uuid.uuid4())
|
||||
|
|
@ -151,6 +164,10 @@ class TelemetryConfig:
|
|||
# Basic sanity: require network location and path
|
||||
if not parsed.netloc:
|
||||
raise ValueError("Missing netloc in endpoint")
|
||||
# Reject localhost/loopback endpoints in production to avoid accidental local overrides
|
||||
host = parsed.hostname or ""
|
||||
if host in ("localhost", "127.0.0.1", "::1"):
|
||||
raise ValueError("Localhost endpoints are not allowed for telemetry")
|
||||
return candidate
|
||||
except Exception as e:
|
||||
logger.debug(
|
||||
|
|
|
|||
Loading…
Reference in New Issue