Module: SentryLogging

Included in:
Accountable, ApplicationController, Apps::Client, BB::Client, BB::GenerateReportRequestForm, BGS::AwardsService, BGS::BenefitClaim, BGS::DependencyVerificationService, BGS::DependentService, BGS::Exceptions::BGSErrors, BGS::FlashUpdater, BGS::Form674, BGS::Form686c, BGS::PaymentService, BGS::People::Service, BGS::Service, BGS::ServiceException, BGS::SubmitForm674EncryptedJob, BGS::SubmitForm674Job, BGS::SubmitForm686cEncryptedJob, BGS::SubmitForm686cJob, BGS::UploadedDocumentService, BGS::VnpVeteran, BID::Service, BenefitsClaims::ServiceException, BenefitsIntakeService::Service, BenefitsReferenceData::Service, BenefitsReferenceData::ServiceException, Caseflow::Service, CentralMail::SubmitCareerCounselingJob, CentralMail::SubmitCentralForm686cJob, CentralMail::SubmitSavedClaimJob, Chip::Service, Chip::ServiceException, ClaimFastTracking::MaxCfiMetrics, Common::Client::Base, Common::Client::Concerns::MHVSessionBasedClient, Common::Client::Concerns::MhvLockedSessionClient, Common::Client::Middleware::Response::MHVXmlHtmlErrors, CopayNotifications::McpNotificationEmailJob, CopayNotifications::NewStatementNotificationJob, CypressViewportUpdater::GithubService, CypressViewportUpdater::GoogleAnalyticsReports, DebtManagementCenter::DebtLetterDownloader, DebtManagementCenter::PaymentsService, DebtManagementCenter::StatementIdentifierService, DebtManagementCenter::VANotifyEmailJob, DecisionReview::PdfValidation::Service, DecisionReview::Service, DecisionReview::ServiceException, DecisionReviewV1::Service, DecisionReviewV1::ServiceException, DeleteOldTransactionsJob, DirectDepositEmailJob, EVSS::BaseService, EVSS::DisabilityCompensationForm::ServiceException, EVSS::GiBillStatus::GiBillStatusResponse, EVSSClaimDocument, EVSSClaimService, EVSSClaimServiceAsync, EducationForm::Create10203ApplicantDecisionLetters, EducationForm::CreateDailySpoolFiles, EducationForm::Process10203Submissions, Facilities::AccessDataDownload, Facilities::DentalServiceReloadJob, Facilities::MentalHealthReloadJob, Facilities::PSSGDownload, Form1010Ezr::Service, Form1010cg::Service, Form1010cg::SubmissionJob, Form526ConfirmationEmailJob, Form526Submission, Form526SubmissionFailedEmailJob, FormAttachment, FormProfile, Forms::Client, HCA::EzrSubmissionJob, HCA::SOAPParser, HealthCareApplication, IAMUserIdentity, LGY::Service, Lighthouse::ServiceException, LighthouseDocument, MDOT::Exceptions::ServiceException, MPI::Responses::AddParser, MPI::Responses::ProfileParser, MPI::Services::AddPersonResponseCreator, MPI::Services::FindProfileResponseCreator, MPIData, OktaRedis::Model, PagerDuty::CacheGlobalDowntime, PagerDuty::PollMaintenanceWindows, Preneeds::Middleware::Response::EoasXmlErrors, Rx::Middleware::Response::RxFailedStation, SAML::PostURLService, SAML::User, SAML::UserAttributes::SSOe, SavedClaim::CoeClaim, SavedClaim::DependencyVerificationClaim, SavedClaim::EducationBenefits::VA10203, SavedClaim::EducationCareerCounselingClaim, SavedClaim::VeteranReadinessEmploymentClaim, Session, Sidekiq::Form526BackupSubmissionProcess::Submit, Sidekiq::Form526JobStatusTracker::JobTracker, SignIn::ApplicationController, SimpleFormsApiSubmission::Service, StructuredData::ProcessDataJob, UserSessionForm, V0::Post911GIBillStatusesController, V0::Preneeds::BurialFormsController, VANotifyDdEmailJob, VANotifyEmailJob, VAProfile::ContactInformation::TransactionResponse, VAProfileRedis::Cache, VBMS::SubmitDependentsPdfEncryptedJob, VBMS::SubmitDependentsPdfJob, VRE::Ch31Form
Defined in:
lib/sentry_logging.rb

Instance Method Summary collapse

Instance Method Details

#log_exception_to_sentry(exception, extra_context = {}, tags_context = {}, level = 'error') ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sentry_logging.rb', line 17

def log_exception_to_sentry(exception, extra_context = {}, tags_context = {}, level = 'error')
  level = normalize_level(level, exception)

  if Settings.sentry.dsn.present?
    (extra_context, tags_context)
    Raven.capture_exception(exception.cause.presence || exception, level:)
  end

  if exception.is_a? Common::Exceptions::BackendServiceException
    rails_logger(level, exception.message, exception.errors, exception.backtrace)
  else
    rails_logger(level, "#{exception.message}.")
  end
  rails_logger(level, exception.backtrace.join("\n")) unless exception.backtrace.nil?
end

#log_message_to_sentry(message, level, extra_context = {}, tags_context = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/sentry_logging.rb', line 6

def log_message_to_sentry(message, level, extra_context = {}, tags_context = {})
  level = normalize_level(level, nil)
  formatted_message = extra_context.empty? ? message : "#{message} : #{extra_context}"
  rails_logger(level, formatted_message)

  if Settings.sentry.dsn.present?
    (extra_context, tags_context)
    Raven.capture_message(message, level:)
  end
end

#non_nil_hash?(h) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/sentry_logging.rb', line 61

def non_nil_hash?(h)
  h.is_a?(Hash) && !h.empty?
end

#normalize_level(level, exception) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sentry_logging.rb', line 33

def normalize_level(level, exception)
  # https://docs.sentry.io/clients/ruby/usage/
  # valid raven levels: debug, info, warning, error, fatal
  level = case exception
          when Pundit::NotAuthorizedError
            'info'
          when Common::Exceptions::BaseError
            exception.sentry_type.to_s
          else
            level.to_s
          end

  return 'warning' if level == 'warn'

  level
end

#rails_logger(level, message, errors = nil, backtrace = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/sentry_logging.rb', line 50

def rails_logger(level, message, errors = nil, backtrace = nil)
  # rails logger uses 'warn' instead of 'warning'
  level = 'warn' if level == 'warning'
  if errors.present?
    error_details = errors.first.attributes.compact.reject { |_k, v| v.try(:empty?) }
    Rails.logger.send(level, message, error_details.merge(backtrace:))
  else
    Rails.logger.send(level, message)
  end
end