Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add logging durations for screenshot async service #30884

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading