Skip to content

Commit 33979d3

Browse files
committed
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 unset
1 parent 9b5488d commit 33979d3

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

UnityMcpBridge/UnityMcpServer~/src/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class ServerConfig:
3636

3737
# Telemetry settings
3838
telemetry_enabled: bool = True
39-
telemetry_endpoint: str = "https://unity-mcp-telemetry-a6uvvbgbsa-uc.a.run.app/telemetry/events"
39+
# Align with telemetry.py default Cloud Run endpoint
40+
telemetry_endpoint: str = "https://unity-mcp-telemetry-375728817078.us-central1.run.app/telemetry/events"
4041

4142
# Create a global config instance
4243
config = ServerConfig()

UnityMcpBridge/UnityMcpServer~/src/server.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
_fh.setFormatter(logging.Formatter(config.log_format))
3030
_fh.setLevel(getattr(logging, config.log_level))
3131
logger.addHandler(_fh)
32+
# Also route telemetry logger to the same rotating file and normal level
33+
try:
34+
tlog = logging.getLogger("unity-mcp-telemetry")
35+
tlog.setLevel(getattr(logging, config.log_level))
36+
tlog.addHandler(_fh)
37+
except Exception:
38+
# Never let logging setup break startup
39+
pass
3240
except Exception:
3341
# Never let logging setup break startup
3442
pass
@@ -40,6 +48,15 @@
4048
pass
4149

4250
# Import telemetry only after logging is configured to ensure its logs use stderr and proper levels
51+
# Ensure a slightly higher telemetry timeout unless explicitly overridden by env
52+
try:
53+
54+
55+
# Ensure generous timeout unless explicitly overridden by env
56+
if not os.environ.get("UNITY_MCP_TELEMETRY_TIMEOUT"):
57+
os.environ["UNITY_MCP_TELEMETRY_TIMEOUT"] = "5.0"
58+
except Exception:
59+
pass
4360
from telemetry import record_telemetry, record_milestone, RecordType, MilestoneType
4461

4562
# Global connection state

UnityMcpBridge/UnityMcpServer~/src/telemetry.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ def __init__(self):
9696
os.environ.get("UNITY_MCP_TELEMETRY_ENDPOINT", default_ep),
9797
default_ep,
9898
)
99+
try:
100+
logger.info(
101+
"Telemetry configured: endpoint=%s (default=%s), timeout_env=%s",
102+
self.endpoint,
103+
default_ep,
104+
os.environ.get("UNITY_MCP_TELEMETRY_TIMEOUT") or "<unset>"
105+
)
106+
except Exception:
107+
pass
99108

100109
# Local storage for UUID and milestones
101110
self.data_dir = self._get_data_directory()
@@ -107,6 +116,10 @@ def __init__(self):
107116
self.timeout = float(os.environ.get("UNITY_MCP_TELEMETRY_TIMEOUT", "1.5"))
108117
except Exception:
109118
self.timeout = 1.5
119+
try:
120+
logger.info("Telemetry timeout=%.2fs", self.timeout)
121+
except Exception:
122+
pass
110123

111124
# Session tracking
112125
self.session_id = str(uuid.uuid4())
@@ -151,6 +164,10 @@ def _validated_endpoint(self, candidate: str, fallback: str) -> str:
151164
# Basic sanity: require network location and path
152165
if not parsed.netloc:
153166
raise ValueError("Missing netloc in endpoint")
167+
# Reject localhost/loopback endpoints in production to avoid accidental local overrides
168+
host = parsed.hostname or ""
169+
if host in ("localhost", "127.0.0.1", "::1"):
170+
raise ValueError("Localhost endpoints are not allowed for telemetry")
154171
return candidate
155172
except Exception as e:
156173
logger.debug(

0 commit comments

Comments
 (0)