def send(self) -> None: from sentry.notifications.notify import notify metrics.incr("mail_adapter.notify") logger.info( "mail.adapter.notify", extra={ "target_type": self.target_type.value, "target_identifier": self.target_identifier, "group": self.group.id, "project_id": self.project.id, }, ) participants_by_provider = self.get_participants() if not participants_by_provider: logger.info( "notifications.notification.rules.alertrulenotification.skip.no_participants", extra={ "target_type": self.target_type.value, "target_identifier": self.target_identifier, "group": self.group.id, "project_id": self.project.id, }, ) return # Only calculate shared context once. shared_context = self.get_context() for provider, participants in participants_by_provider.items(): notify(provider, self, participants, shared_context)
def send(self) -> None: if not self.should_email(): return participants_by_provider = self.get_participants() if not participants_by_provider: return # Only calculate shared context once. shared_context = self.get_context() for provider, participants in participants_by_provider.items(): notify(provider, self, participants, shared_context)
def send(self) -> None: if not self.should_email(): return # Only calculate shared context once. shared_context = self.get_context() if should_send_as_alert_notification(shared_context): return send_as_alert_notification(shared_context, self.target_type, self.target_identifier) participants_by_provider_by_event = get_participants_by_event( self.digest, self.project, self.target_type, self.target_identifier, ) # Get every actor ID for every provider as a set. actor_ids = set() combined_participants_by_provider = defaultdict(set) for participants_by_provider in participants_by_provider_by_event.values( ): for provider, participants in participants_by_provider.items(): for participant in participants: actor_ids.add(participant.actor_id) combined_participants_by_provider[provider].add( participant) if not actor_ids: return logger.info( "mail.adapter.notify_digest", extra={ "project_id": self.project.id, "target_type": self.target_type.value, "target_identifier": self.target_identifier, "actor_ids": actor_ids, }, ) # Calculate the per-participant context. extra_context: Mapping[int, Mapping[str, Any]] = {} if should_get_personalized_digests(self.target_type, self.project.id): extra_context = self.get_extra_context( participants_by_provider_by_event) for provider, participants in combined_participants_by_provider.items( ): notify(provider, self, participants, shared_context, extra_context)
def send(self) -> None: if not self.should_email(): return participants_by_provider = self.get_participants_with_group_subscription_reason() if not participants_by_provider: return # Only calculate shared context once. shared_context = self.get_context() for provider, participants_with_reasons in participants_by_provider.items(): participants, extra_context = split_participants_and_context(participants_with_reasons) notify(provider, self, participants, shared_context, extra_context)
def send_activity_notification( notification: ActivityNotification | UserReportNotification) -> None: if not notification.should_email(): return participants_by_provider = notification.get_participants_with_group_subscription_reason( ) if not participants_by_provider: return # Only calculate shared context once. shared_context = notification.get_context() for provider, participants_with_reasons in participants_by_provider.items( ): participants_, extra_context = split_participants_and_context( participants_with_reasons) notify(provider, notification, participants_, shared_context, extra_context)
def send(self) -> None: if not self.should_email(): return participants_by_provider = self.get_participants() if not participants_by_provider: return # Get every user ID for every provider as a set. user_ids = { user.id for users in participants_by_provider.values() for user in users } logger.info( "mail.adapter.notify_digest", extra={ "project_id": self.project.id, "target_type": self.target_type.value, "target_identifier": self.target_identifier, "user_ids": user_ids, }, ) # Only calculate shared context once. shared_context = self.get_context() if should_send_as_alert_notification(shared_context): return send_as_alert_notification(shared_context, self.target_type, self.target_identifier) # Calculate the per-user context. It's fine that we're doing extra work # to get personalized digests for the non-email users. extra_context: Mapping[int, Mapping[str, Any]] = {} if should_get_personalized_digests(self.target_type, self.project.id): extra_context = self.get_extra_context(user_ids) for provider, participants in participants_by_provider.items(): if provider in [ExternalProviders.EMAIL]: notify(provider, self, participants, shared_context, extra_context)