Skip to content

Adds logging to custom email services

Marc Saleiko requested to merge ms-sd-custom-email-logging into master

What does this MR do and why?

This MR adds logging (error and success logging) to ServiceDesk::CustomEmails::CreateService and ServiceDesk::CustomEmails::DestroyService.

Our goal is to make errors visible and to build a dashboard from the logs as a first iteration. Another MR will cover logs for the custom email verification.

Contributes to Follow-up: Add logging to custom email address ... (#415594 - closed)

Screenshots or screen recordings

🚫 backend only

How to set up and validate locally

To see one of these logs in action without the need to fully set up email ingestion or use valid SMTP credentials, you can create a custom email using invalid credentials. Run the following in the rails console:

# Only enable flag for project #7
project = Project.find(7)
Feature.enable(:service_desk_custom_email, project)

current_user = User.first
custom_email = 'support@example.com'

setting = ServiceDeskSetting.find_or_create_by!(project_id: project.id)

params = {
  custom_email: custom_email,
  smtp_address: 'smtp.gmail.com', # we need a valid smtp address
  smtp_port: 587,
  smtp_username: custom_email,
  smtp_password: 'supersecret'
}

# Create custom email using invalid credentials
response = ::ServiceDesk::CustomEmails::CreateService.new(
  project: project,
  current_user: current_user,
  params: params
).execute

# Destroy custom email again
::ServiceDesk::CustomEmails::DestroyService.new(
  project: project,
  current_user: current_user
).execute

# Disable feature again
Feature.disable(:service_desk_custom_email, project)

From the gitlab folder run tail log/application_json.log in the terminal and find the two custom email entries.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Marc Saleiko

Merge request reports