Add diagnostics feature#4652
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an always-on diagnostics facility that captures a bounded ring of WARNING+ logs and aggregates exception fingerprints, and exposes an admin-only API/HTTP download endpoint to generate a privacy-redacted diagnostics report on demand.
Changes:
- Introduces always-on capture + sanitization helpers, plus an on-demand diagnostics report builder/controller with pluggable sections.
- Adds
get_diagnostics()hooks on core controllers/providers and wires the diagnostics controller into startup, API command registration, and the webserver route table. - Adds comprehensive tests covering sanitization, bounded capture behavior, section isolation/timeouts, and authz/formatting for the download endpoint.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/core/test_diagnostics.py | Adds end-to-end and unit tests for capture, sanitization, section collection, and HTTP/API access control. |
| music_assistant/models/provider.py | Adds optional get_diagnostics() hook for providers. |
| music_assistant/models/core_controller.py | Adds optional get_diagnostics() hook for core controllers. |
| music_assistant/mass.py | Installs capture early, instantiates/sets up the diagnostics controller, and registers its API commands. |
| music_assistant/helpers/logging.py | Ensures the diagnostics capture handler stays on the root logger (not migrated into the queue handler). |
| music_assistant/helpers/diagnostics.py | Implements always-on bounded capture and sanitization primitives (stdlib-only). |
| music_assistant/controllers/webserver/controller.py | Registers authenticated /diagnostics download route. |
| music_assistant/controllers/streams/controller.py | Implements get_diagnostics() contribution for streams controller. |
| music_assistant/controllers/diagnostics/init.py | New diagnostics controller to assemble/redact reports and manage pluggable sections. |
| music_assistant/main.py | Installs diagnostics capture handler early during logger setup. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this implement/fix?
Users reporting issues often need multiple back-and-forth rounds before we have enough info to help. This adds an always-on diagnostics facility: one privacy-safe report you can download and attach to a GitHub issue.
diagnostics/getAPI command + authenticatedGET /diagnosticsdownload (JSON, or?format=mdfor pasting into issues), served with content-disposition so the frontend can add a "download diagnostics" button.get_diagnostics()to contribute a section;mass.diagnostics.register_section()for anything else (the upcoming profiler provider will plug in through this). Sections run with a 2s timeout and can't break the report.Follow-ups (separate PRs): frontend settings button, issue template line asking for the attachment, profiler provider.
Redacted sample (from a live server with a deliberately broken provider)
{ "type": "SetupFailedError", "fingerprint": "62c2b502e720", "count": 2, "logger": "music_assistant.webserver", "origin": "music_assistant/providers/filesystem_local/__init__.py:249 in handle_async_init", "message": "Error executing command config/providers/save: SetupFailedError: Music Directory /nonexistent/diag-test-library does not exist" }{"time": "2026-07-07T23:16:01+00:00", "level": "WARNING", "logger": "aiosendspin.server.connection.<mac-7f85b52c>", "message": "WebSocket closed, close_code=1006"} {"time": "2026-07-07T23:15:53+00:00", "level": "WARNING", "logger": "music_assistant.streams", "message": "...Starting streamserver on <redacted-ip>:8097..."}Related issue (if applicable):
Types of changes
bugfixnew-featureenhancementnew-providerbreaking-changerefactordocumentationmaintenancecidependenciesChecklist
pre-commit run --all-filespasses.pytestpasses, and tests have been added/updated undertests/where applicable.music-assistant/modelsis linked.music-assistant/frontendis linked.