Sha256: 65245467c8deb86e765d2f799e04c234166d0a2f6185dc16c8d95dca02c3d5dc
Contents?: true
Size: 1.97 KB
Versions: 2
Compression:
Stored size: 1.97 KB
Contents
# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/components/logger' module Contrast module Agent # This module adds an at_exit hook for us to send messages that may be lost at process exit module AtExitHook extend Contrast::Components::Logger::InstanceMethods def self.exit_hook @_exit_hook ||= begin at_exit do on_exit end true end end # Actions to take when a process exits. Typically called from our # exit_hook, but exposed here for other process terminations, like those # in Kernel#exec def self.on_exit logger.debug('at_exit invoked, host application terminating', p_id: @pid, pp_id: @ppid, process_pid: Process.pid, process_pp_id: Process.ppid) $stdout.puts('[Contrast Agent] Graceful shutdown...') report_traces context = Contrast::Agent::REQUEST_TRACKER.current return unless context [ Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.generate_library_usage, context.observed_route ].compact.each do |event| Contrast::Agent.reporter&.send_event_immediately(event) end Contrast::Agent.reporter&.send_event_immediately(context.activity) end def self.report_traces return unless Contrast::ASSESS.enabled? return if ENV.fetch('CONTRAST__PIPELINE__RUN', nil) == 'true' collection = Contrast::Agent::Reporting::ReportingStorage.collection # report gathered traces: return if collection.empty? collection.each do |_id, finding| preflight = Contrast::Agent::Reporting::BuildPreflight.generate(finding) Contrast::Agent.reporter&.send_event_immediately(preflight) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
contrast-agent-7.6.1 | lib/contrast/agent/hooks/at_exit_hook.rb |
contrast-agent-7.6.0 | lib/contrast/agent/hooks/at_exit_hook.rb |