Send issues with sentry report (#2246)

This commit is contained in:
Pascal Vizeli 2020-11-12 14:57:04 +01:00 committed by GitHub
parent ced72e1273
commit cd34a40dd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import os
import re
from aiohttp import hdrs
import attr
from ..const import HEADER_TOKEN_OLD, CoreState
from ..coresys import CoreSys
@ -73,6 +74,7 @@ def filter_data(coresys: CoreSys, event: dict, hint: dict) -> dict:
"os": coresys.hassos.version,
"supervisor": coresys.supervisor.version,
},
"issues": [attr.asdict(issue) for issue in coresys.resolution.issues],
}
)
event.setdefault("tags", []).extend(

View File

@ -7,7 +7,7 @@ import pytest
from supervisor.const import SUPERVISOR_VERSION, CoreState
from supervisor.exceptions import AddonConfigurationError
from supervisor.misc.filter import filter_data
from supervisor.resolution.const import UnsupportedReason
from supervisor.resolution.const import ContextType, IssueType, UnsupportedReason
SAMPLE_EVENT = {"sample": "event", "extra": {"Test": "123"}}
@ -101,3 +101,19 @@ def test_sanitize(coresys):
]["headers"]
assert ["X-Forwarded-Host", "example.com"] in filtered["request"]["headers"]
assert ["X-Hassio-Key", "XXXXXXXXXXXXXXXXXXX"] in filtered["request"]["headers"]
def test_issues_on_report(coresys):
"""Attach issue to report."""
coresys.resolution.create_issue(IssueType.FATAL_ERROR, ContextType.SYSTEM)
coresys.config.diagnostics = True
coresys.core.state = CoreState.RUNNING
with patch("shutil.disk_usage", return_value=(42, 42, 2 * (1024.0 ** 3))):
event = filter_data(coresys, SAMPLE_EVENT, {})
assert "issues" in event["contexts"]
assert event["contexts"]["issues"][0]["type"] == IssueType.FATAL_ERROR
assert event["contexts"]["issues"][0]["context"] == ContextType.SYSTEM