Create a diagnostics bundle from local state files.
(
*,
limit: int = 50,
output_path: str | None = None,
)
| 217 | |
| 218 | |
| 219 | def build_support_bundle( |
| 220 | *, |
| 221 | limit: int = 50, |
| 222 | output_path: str | None = None, |
| 223 | ) -> Path: |
| 224 | """Create a diagnostics bundle from local state files.""" |
| 225 | |
| 226 | safe_limit = max(1, min(int(limit), 500)) |
| 227 | root = data_dir() |
| 228 | traces = _trace_store() |
| 229 | stats = RouteStats() |
| 230 | recent_traces = _recent_traces_payload(safe_limit) |
| 231 | recent_errors = _recent_errors_payload(safe_limit) |
| 232 | bundle_path = _output_path(output_path) |
| 233 | bundle_path.parent.mkdir(parents=True, exist_ok=True, mode=0o700) |
| 234 | telemetry_status = _telemetry_status_payload() |
| 235 | |
| 236 | diagnostics_overview = { |
| 237 | "recent_trace_count": len(recent_traces), |
| 238 | "recent_error_count": len(recent_errors), |
| 239 | "feedback_pending": _feedback_buffer_summary(root)["pending_count"], |
| 240 | "telemetry_enabled": bool(telemetry_status.get("enabled", False)), |
| 241 | } |
| 242 | model_experience = ModelExperienceStore().summary() |
| 243 | connections = _connections_payload() |
| 244 | routing_config = RoutingConfigStore().export() |
| 245 | providers = _providers_payload() |
| 246 | spending = _spending_payload() |
| 247 | feedback_summary = _feedback_buffer_summary(root) |
| 248 | stats_summary = _stats_summary_payload(stats) |
| 249 | trace_summary = _trace_summary_payload(traces) |
| 250 | logs_tail = _tail_text(root / "serve.log") |
| 251 | |
| 252 | manifest = _bundle_manifest(bundle_path, recent_traces=recent_traces) |
| 253 | |
| 254 | with zipfile.ZipFile(bundle_path, mode="w", compression=zipfile.ZIP_DEFLATED) as zf: |
| 255 | _write_json(zf, "manifest.json", manifest) |
| 256 | _write_json(zf, "diagnostics/overview.json", diagnostics_overview) |
| 257 | _write_json(zf, "diagnostics/stats_summary.json", stats_summary) |
| 258 | _write_json(zf, "diagnostics/trace_summary.json", trace_summary) |
| 259 | _write_json(zf, "diagnostics/recent_traces.json", recent_traces) |
| 260 | _write_json(zf, "diagnostics/recent_errors.json", recent_errors) |
| 261 | _write_json(zf, "state/connections.json", connections) |
| 262 | _write_json(zf, "state/providers.json", providers) |
| 263 | _write_json(zf, "state/routing_config.json", routing_config) |
| 264 | _write_json(zf, "state/spending.json", spending) |
| 265 | _write_json(zf, "state/model_experience.json", model_experience) |
| 266 | _write_json(zf, "state/telemetry.json", telemetry_status) |
| 267 | _write_json(zf, "state/feedback_buffer.json", feedback_summary) |
| 268 | if logs_tail: |
| 269 | zf.writestr("logs/serve.log.tail.txt", logs_tail) |
| 270 | |
| 271 | return bundle_path |
| 272 | |
| 273 | |
| 274 | def find_trace(request_id: str) -> dict[str, Any] | None: |
no test coverage detected