Fix Sentry user context and system info (#39130)
This commit is contained in:
parent
cdb6161d3d
commit
3c1c6069da
2 changed files with 19 additions and 1 deletions
|
@ -8,7 +8,10 @@ from sentry_sdk.integrations.logging import LoggingIntegration
|
|||
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
||||
|
||||
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.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.loader import Integration, async_get_custom_components
|
||||
|
@ -96,6 +99,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
**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
|
||||
|
||||
|
||||
|
@ -186,6 +198,9 @@ def process_before_send(
|
|||
# Update event with the 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
|
||||
event.setdefault("contexts", {}).update(
|
||||
{
|
||||
|
|
|
@ -154,6 +154,9 @@ async def test_process_before_send(hass: HomeAssistant):
|
|||
assert tags["uuid"] == "12345"
|
||||
assert tags["installation_type"] == "pytest"
|
||||
|
||||
user = result["user"]
|
||||
assert user["id"] == "12345"
|
||||
|
||||
|
||||
async def test_event_with_platform_context(hass: HomeAssistant):
|
||||
"""Test extraction of platform context information during Sentry events."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue