Skip to content

Commit

Permalink
feat: add logging durations for screenshot async service (#30884)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch authored Nov 12, 2024
1 parent ac3a10d commit 4e8eba8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions superset/utils/screenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from superset import feature_flag_manager
from superset.dashboards.permalink.types import DashboardPermalinkState
from superset.extensions import event_logger
from superset.utils.hashing import md5_sha_from_dict
from superset.utils.urls import modify_url_query
from superset.utils.webdriver import (
Expand Down Expand Up @@ -91,7 +92,8 @@ def get_screenshot(
self, user: User, window_size: WindowSize | None = None
) -> bytes | None:
driver = self.driver(window_size)
self.screenshot = driver.get_screenshot(self.url, self.element, user)
with event_logger.log_context("screenshot", screenshot_url=self.url):
self.screenshot = driver.get_screenshot(self.url, self.element, user)
return self.screenshot

def get(
Expand Down Expand Up @@ -169,7 +171,10 @@ def compute_and_cache( # pylint: disable=too-many-arguments

# Assuming all sorts of things can go wrong with Selenium
try:
payload = self.get_screenshot(user=user, window_size=window_size)
with event_logger.log_context(
f"screenshot.compute.{self.thumbnail_type}", force=force
):
payload = self.get_screenshot(user=user, window_size=window_size)
except Exception as ex: # pylint: disable=broad-except
logger.warning("Failed at generating thumbnail %s", ex, exc_info=True)

Expand All @@ -182,7 +187,10 @@ def compute_and_cache( # pylint: disable=too-many-arguments

if payload:
logger.info("Caching thumbnail: %s", cache_key)
cache.set(cache_key, payload)
with event_logger.log_context(
f"screenshot.cache.{self.thumbnail_type}", force=force
):
cache.set(cache_key, payload)
logger.info("Done caching thumbnail")
return payload

Expand Down

0 comments on commit 4e8eba8

Please sign in to comment.