73
73
from superset .utils .celery import session_scope
74
74
from superset .utils .core import HeaderDataType , override_user
75
75
from superset .utils .csv import get_chart_csv_data , get_chart_dataframe
76
+ from superset .utils .decorators import context
76
77
from superset .utils .screenshots import ChartScreenshot , DashboardScreenshot
77
78
from superset .utils .urls import get_url_path
78
79
@@ -83,6 +84,7 @@ class BaseReportState:
83
84
current_states : list [ReportState ] = []
84
85
initial : bool = False
85
86
87
+ @context ()
86
88
def __init__ (
87
89
self ,
88
90
session : Session ,
@@ -234,7 +236,12 @@ def _get_screenshots(self) -> list[bytes]:
234
236
try :
235
237
image = screenshot .get_screenshot (user = user )
236
238
except SoftTimeLimitExceeded as ex :
237
- logger .warning ("A timeout occurred while taking a screenshot." )
239
+ logger .warning (
240
+ "A timeout occurred while taking a screenshot." ,
241
+ extra = {
242
+ "execution_id" : self ._execution_id ,
243
+ },
244
+ )
238
245
raise ReportScheduleScreenshotTimeout () from ex
239
246
except Exception as ex :
240
247
raise ReportScheduleScreenshotFailedError (
@@ -254,11 +261,23 @@ def _get_csv_data(self) -> bytes:
254
261
auth_cookies = machine_auth_provider_factory .instance .get_auth_cookies (user )
255
262
256
263
if self ._report_schedule .chart .query_context is None :
257
- logger .warning ("No query context found, taking a screenshot to generate it" )
264
+ logger .warning (
265
+ "No query context found, taking a screenshot to generate it" ,
266
+ extra = {
267
+ "execution_id" : self ._execution_id ,
268
+ },
269
+ )
258
270
self ._update_query_context ()
259
271
260
272
try :
261
- logger .info ("Getting chart from %s as user %s" , url , user .username )
273
+ logger .info (
274
+ "Getting chart from %s as user %s" ,
275
+ url ,
276
+ user .username ,
277
+ extra = {
278
+ "execution_id" : self ._execution_id ,
279
+ },
280
+ )
262
281
csv_data = get_chart_csv_data (chart_url = url , auth_cookies = auth_cookies )
263
282
except SoftTimeLimitExceeded as ex :
264
283
raise ReportScheduleCsvTimeout () from ex
@@ -283,11 +302,23 @@ def _get_embedded_data(self) -> pd.DataFrame:
283
302
auth_cookies = machine_auth_provider_factory .instance .get_auth_cookies (user )
284
303
285
304
if self ._report_schedule .chart .query_context is None :
286
- logger .warning ("No query context found, taking a screenshot to generate it" )
305
+ logger .warning (
306
+ "No query context found, taking a screenshot to generate it" ,
307
+ extra = {
308
+ "execution_id" : self ._execution_id ,
309
+ },
310
+ )
287
311
self ._update_query_context ()
288
312
289
313
try :
290
- logger .info ("Getting chart from %s as user %s" , url , user .username )
314
+ logger .info (
315
+ "Getting chart from %s as user %s" ,
316
+ url ,
317
+ user .username ,
318
+ extra = {
319
+ "execution_id" : self ._execution_id ,
320
+ },
321
+ )
291
322
dataframe = get_chart_dataframe (url , auth_cookies )
292
323
except SoftTimeLimitExceeded as ex :
293
324
raise ReportScheduleDataFrameTimeout () from ex
@@ -440,7 +471,12 @@ def _send(
440
471
if notification_errors :
441
472
# log all errors but raise based on the most severe
442
473
for error in notification_errors :
443
- logger .warning (str (error ))
474
+ logger .warning (
475
+ str (error ),
476
+ extra = {
477
+ "execution_id" : self ._execution_id ,
478
+ },
479
+ )
444
480
445
481
if any (error .level == ErrorLevel .ERROR for error in notification_errors ):
446
482
raise ReportScheduleSystemErrorsException (errors = notification_errors )
@@ -466,7 +502,9 @@ def send_error(self, name: str, message: str) -> None:
466
502
logger .info (
467
503
"header_data in notifications for alerts and reports %s, taskid, %s" ,
468
504
header_data ,
469
- self ._execution_id ,
505
+ extra = {
506
+ "execution_id" : self ._execution_id ,
507
+ },
470
508
)
471
509
notification_content = NotificationContent (
472
510
name = name , text = message , header_data = header_data
@@ -725,6 +763,9 @@ def run(self) -> None:
725
763
"Running report schedule %s as user %s" ,
726
764
self ._execution_id ,
727
765
username ,
766
+ extra = {
767
+ "execution_id" : self ._execution_id ,
768
+ },
728
769
)
729
770
ReportScheduleStateMachine (
730
771
session , self ._execution_id , self ._model , self ._scheduled_dttm
@@ -740,6 +781,9 @@ def validate(self, session: Session = None) -> None:
740
781
"session is validated: id %s, executionid: %s" ,
741
782
self ._model_id ,
742
783
self ._execution_id ,
784
+ extra = {
785
+ "execution_id" : self ._execution_id ,
786
+ },
743
787
)
744
788
self ._model = (
745
789
session .query (ReportSchedule ).filter_by (id = self ._model_id ).one_or_none ()
0 commit comments