Class: RailsErrorDashboard::Services::EnvironmentSnapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_error_dashboard/services/environment_snapshot.rb

Overview

Pure algorithm: Capture runtime environment info at boot time

Snapshots Ruby version, Rails version, loaded gem versions, web server, and database adapter. Memoized — computed once per process lifetime. Stored as JSON on each error so historical errors show the environment that was running when they occurred (not the current environment).

Constant Summary collapse

TRACKED_GEMS =
%w[
  activerecord actionpack sidekiq solid_queue puma unicorn
  passenger redis pg mysql2 sqlite3 good_job
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.reset!Object

Clear cached snapshot (for testing)



24
25
26
# File 'lib/rails_error_dashboard/services/environment_snapshot.rb', line 24

def self.reset!
  @cached_snapshot = nil
end

.snapshotHash

Return cached environment snapshot (frozen hash)

Returns:

  • (Hash)

    Environment info



19
20
21
# File 'lib/rails_error_dashboard/services/environment_snapshot.rb', line 19

def self.snapshot
  @cached_snapshot ||= new.capture.freeze
end

Instance Method Details

#captureHash

Capture current environment info

Returns:

  • (Hash)

    Environment snapshot



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rails_error_dashboard/services/environment_snapshot.rb', line 30

def capture
  {
    ruby_version: RUBY_VERSION,
    ruby_engine: RUBY_ENGINE,
    ruby_platform: RUBY_PLATFORM,
    rails_version: rails_version,
    rails_env: rails_env,
    gem_versions: detect_gem_versions,
    server: detect_server,
    database_adapter: detect_database_adapter
  }
rescue => e
  RailsErrorDashboard::Logger.debug("[RailsErrorDashboard] EnvironmentSnapshot.capture failed: #{e.message}")
  { ruby_version: RUBY_VERSION, ruby_engine: RUBY_ENGINE }
end