mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Fix Sentry user context and system info (#39130)
This commit is contained in:
parent
cdb6161d3d
commit
3c1c6069da
@ -8,7 +8,10 @@ from sentry_sdk.integrations.logging import LoggingIntegration
|
|||||||
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import __version__ as current_version
|
from homeassistant.const import (
|
||||||
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
|
__version__ as current_version,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||||
from homeassistant.loader import Integration, async_get_custom_components
|
from homeassistant.loader import Integration, async_get_custom_components
|
||||||
@ -96,6 +99,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
**tracing,
|
**tracing,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def update_system_info(now):
|
||||||
|
nonlocal system_info
|
||||||
|
system_info = await hass.helpers.system_info.async_get_system_info()
|
||||||
|
|
||||||
|
# Update system info every hour
|
||||||
|
hass.helpers.event.async_call_later(3600, update_system_info)
|
||||||
|
|
||||||
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, update_system_info)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -186,6 +198,9 @@ def process_before_send(
|
|||||||
# Update event with the additional tags
|
# Update event with the additional tags
|
||||||
event.setdefault("tags", {}).update(additional_tags)
|
event.setdefault("tags", {}).update(additional_tags)
|
||||||
|
|
||||||
|
# Set user context to the installation UUID
|
||||||
|
event.setdefault("user", {}).update({"id": huuid})
|
||||||
|
|
||||||
# Update event data with Home Assistant Context
|
# Update event data with Home Assistant Context
|
||||||
event.setdefault("contexts", {}).update(
|
event.setdefault("contexts", {}).update(
|
||||||
{
|
{
|
||||||
|
@ -154,6 +154,9 @@ async def test_process_before_send(hass: HomeAssistant):
|
|||||||
assert tags["uuid"] == "12345"
|
assert tags["uuid"] == "12345"
|
||||||
assert tags["installation_type"] == "pytest"
|
assert tags["installation_type"] == "pytest"
|
||||||
|
|
||||||
|
user = result["user"]
|
||||||
|
assert user["id"] == "12345"
|
||||||
|
|
||||||
|
|
||||||
async def test_event_with_platform_context(hass: HomeAssistant):
|
async def test_event_with_platform_context(hass: HomeAssistant):
|
||||||
"""Test extraction of platform context information during Sentry events."""
|
"""Test extraction of platform context information during Sentry events."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user