@@ -462,30 +462,34 @@ def sentry_apply_entry(*args, **kwargs):
462
462
if match_regex_list (monitor_name , integration .exclude_beat_tasks ):
463
463
return original_apply_entry (* args , ** kwargs )
464
464
465
- monitor_config = _get_monitor_config (celery_schedule , app )
466
-
467
- is_supported_schedule = bool (monitor_config )
468
- if is_supported_schedule :
469
- headers = schedule_entry .options .pop ("headers" , {})
470
- headers .update (
471
- {
472
- "sentry-monitor-slug" : monitor_name ,
473
- "sentry-monitor-config" : monitor_config ,
474
- }
475
- )
465
+ with hub .configure_scope () as scope :
466
+ # When tasks are started from Celery Beat, make sure each task has its own trace.
467
+ scope .set_new_propagation_context ()
468
+
469
+ monitor_config = _get_monitor_config (celery_schedule , app )
470
+
471
+ is_supported_schedule = bool (monitor_config )
472
+ if is_supported_schedule :
473
+ headers = schedule_entry .options .pop ("headers" , {})
474
+ headers .update (
475
+ {
476
+ "sentry-monitor-slug" : monitor_name ,
477
+ "sentry-monitor-config" : monitor_config ,
478
+ }
479
+ )
476
480
477
- check_in_id = capture_checkin (
478
- monitor_slug = monitor_name ,
479
- monitor_config = monitor_config ,
480
- status = MonitorStatus .IN_PROGRESS ,
481
- )
482
- headers .update ({"sentry-monitor-check-in-id" : check_in_id })
481
+ check_in_id = capture_checkin (
482
+ monitor_slug = monitor_name ,
483
+ monitor_config = monitor_config ,
484
+ status = MonitorStatus .IN_PROGRESS ,
485
+ )
486
+ headers .update ({"sentry-monitor-check-in-id" : check_in_id })
483
487
484
- # Set the Sentry configuration in the options of the ScheduleEntry.
485
- # Those will be picked up in `apply_async` and added to the headers.
486
- schedule_entry .options ["headers" ] = headers
488
+ # Set the Sentry configuration in the options of the ScheduleEntry.
489
+ # Those will be picked up in `apply_async` and added to the headers.
490
+ schedule_entry .options ["headers" ] = headers
487
491
488
- return original_apply_entry (* args , ** kwargs )
492
+ return original_apply_entry (* args , ** kwargs )
489
493
490
494
Scheduler .apply_entry = sentry_apply_entry
491
495
0 commit comments