Initialize the Sentry SDK within an import executor job to not block event loop (#118830)

This commit is contained in:
Jan-Philipp Benecke 2024-06-04 20:47:06 +02:00 committed by GitHub
parent c8e7298556
commit c83aba0fd1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,6 +21,7 @@ from homeassistant.helpers import config_validation as cv, entity_platform, inst
from homeassistant.helpers.event import async_call_later from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.system_info import async_get_system_info from homeassistant.helpers.system_info import async_get_system_info
from homeassistant.loader import Integration, async_get_custom_components from homeassistant.loader import Integration, async_get_custom_components
from homeassistant.setup import SetupPhases, async_pause_setup
from .const import ( from .const import (
CONF_DSN, CONF_DSN,
@ -41,7 +42,6 @@ from .const import (
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False) CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
LOGGER_INFO_REGEX = re.compile(r"^(\w+)\.?(\w+)?\.?(\w+)?\.?(\w+)?(?:\..*)?$") LOGGER_INFO_REGEX = re.compile(r"^(\w+)\.?(\w+)?\.?(\w+)?\.?(\w+)?(?:\..*)?$")
@ -81,23 +81,33 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
), ),
} }
sentry_sdk.init( with async_pause_setup(hass, SetupPhases.WAIT_IMPORT_PACKAGES):
dsn=entry.data[CONF_DSN], # sentry_sdk.init imports modules based on the selected integrations
environment=entry.options.get(CONF_ENVIRONMENT), def _init_sdk():
integrations=[sentry_logging, AioHttpIntegration(), SqlalchemyIntegration()], """Initialize the Sentry SDK."""
release=current_version, sentry_sdk.init(
before_send=lambda event, hint: process_before_send( dsn=entry.data[CONF_DSN],
hass, environment=entry.options.get(CONF_ENVIRONMENT),
entry.options, integrations=[
channel, sentry_logging,
huuid, AioHttpIntegration(),
system_info, SqlalchemyIntegration(),
custom_components, ],
event, release=current_version,
hint, before_send=lambda event, hint: process_before_send(
), hass,
**tracing, entry.options,
) channel,
huuid,
system_info,
custom_components,
event,
hint,
),
**tracing,
)
await hass.async_add_import_executor_job(_init_sdk)
async def update_system_info(now): async def update_system_info(now):
nonlocal system_info nonlocal system_info