Class: DeprecationCollector::Deprecation
- Inherits:
-
Object
- Object
- DeprecationCollector::Deprecation
- Defined in:
- lib/deprecation_collector/deprecation.rb
Overview
:nodoc:
Constant Summary collapse
- CLEANUP_REGEXES =
{ # rails views generated methods names are unique per-worker /_app_views_(\w+)__(\d+)_(\d+)/ => "_app_views_\\1__", # repl line numbers are not important, may be ignore all repl at all /\A\((pry|irb)\):\d+/ => '(\1)' }.freeze
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#app_traceline ⇒ Object
readonly
Returns the value of attribute app_traceline.
-
#context ⇒ Object
Returns the value of attribute context.
-
#custom_fingerprint ⇒ Object
Returns the value of attribute custom_fingerprint.
-
#first_timestamp ⇒ Object
readonly
Returns the value of attribute first_timestamp.
-
#full_backtrace ⇒ Object
readonly
Returns the value of attribute full_backtrace.
-
#gem_traceline ⇒ Object
readonly
Returns the value of attribute gem_traceline.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#occurences ⇒ Object
readonly
Returns the value of attribute occurences.
-
#realm ⇒ Object
readonly
Returns the value of attribute realm.
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
- #digest ⇒ Object
- #digest_base ⇒ Object
- #ignored? ⇒ Boolean
-
#initialize(message, realm = nil, backtrace = [], cleanup_prefixes = []) ⇒ Deprecation
constructor
A new instance of Deprecation.
- #message_for_digest ⇒ Object
- #to_json(_options = {}) ⇒ Object
- #touch ⇒ Object
Constructor Details
#initialize(message, realm = nil, backtrace = [], cleanup_prefixes = []) ⇒ Deprecation
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/deprecation_collector/deprecation.rb', line 17 def initialize(, realm = nil, backtrace = [], cleanup_prefixes = []) # backtrace is Thread::Backtrace::Location or array of strings for other realms = .dup @realm = realm @occurences = 0 @gem_traceline = find_gem_traceline(backtrace) @app_traceline = find_app_traceline(backtrace) = Time.now.to_i cleanup_prefixes.each do |path| @gem_traceline.delete_prefix!(path) .gsub!(path, "") end CLEANUP_REGEXES.each_pair do |regex, replace| @gem_traceline&.gsub!(regex, replace) @app_traceline&.gsub!(regex, replace) end @full_backtrace = backtrace.map(&:to_s) if DeprecationCollector.instance.save_full_backtrace end |
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
7 8 9 |
# File 'lib/deprecation_collector/deprecation.rb', line 7 def app_name @app_name end |
#app_traceline ⇒ Object (readonly)
Returns the value of attribute app_traceline.
6 7 8 |
# File 'lib/deprecation_collector/deprecation.rb', line 6 def app_traceline @app_traceline end |
#context ⇒ Object
Returns the value of attribute context.
7 8 9 |
# File 'lib/deprecation_collector/deprecation.rb', line 7 def context @context end |
#custom_fingerprint ⇒ Object
Returns the value of attribute custom_fingerprint.
7 8 9 |
# File 'lib/deprecation_collector/deprecation.rb', line 7 def custom_fingerprint @custom_fingerprint end |
#first_timestamp ⇒ Object (readonly)
Returns the value of attribute first_timestamp.
6 7 8 |
# File 'lib/deprecation_collector/deprecation.rb', line 6 def end |
#full_backtrace ⇒ Object (readonly)
Returns the value of attribute full_backtrace.
6 7 8 |
# File 'lib/deprecation_collector/deprecation.rb', line 6 def full_backtrace @full_backtrace end |
#gem_traceline ⇒ Object (readonly)
Returns the value of attribute gem_traceline.
6 7 8 |
# File 'lib/deprecation_collector/deprecation.rb', line 6 def gem_traceline @gem_traceline end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/deprecation_collector/deprecation.rb', line 6 def end |
#occurences ⇒ Object (readonly)
Returns the value of attribute occurences.
6 7 8 |
# File 'lib/deprecation_collector/deprecation.rb', line 6 def occurences @occurences end |
#realm ⇒ Object (readonly)
Returns the value of attribute realm.
6 7 8 |
# File 'lib/deprecation_collector/deprecation.rb', line 6 def realm @realm end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/deprecation_collector/deprecation.rb', line 62 def as_json( = {}) { app: app_name, message: , realm: realm, app_traceline: app_traceline, gem_traceline: (gem_traceline != app_traceline && gem_traceline) || nil, full_backtrace: full_backtrace, ruby_version: RUBY_VERSION, rails_version: (defined?(Rails) && Rails.version), hostname: Socket.gethostname, revision: DeprecationCollector.instance.app_revision, count: @occurences, # output anyway for frequency estimation (during write_interval inside single process) first_timestamp: , # this may not be accurate, a worker with later timestamp may dump earlier digest_base: digest_base, # for debug purposes context: context }.compact end |
#digest ⇒ Object
53 54 55 |
# File 'lib/deprecation_collector/deprecation.rb', line 53 def digest @digest ||= Digest::MD5.hexdigest(digest_base) end |
#digest_base ⇒ Object
57 58 59 60 |
# File 'lib/deprecation_collector/deprecation.rb', line 57 def digest_base "1:#{RUBY_VERSION}:#{defined?(Rails) && Rails.version}:#{message_for_digest}:#{gem_traceline}:#{app_traceline}" \ "#{":#{custom_fingerprint}" if custom_fingerprint}" end |
#ignored? ⇒ Boolean
43 44 45 |
# File 'lib/deprecation_collector/deprecation.rb', line 43 def ignored? false end |
#message_for_digest ⇒ Object
47 48 49 50 51 |
# File 'lib/deprecation_collector/deprecation.rb', line 47 def # some gems like rest-client put data in warnings, need to aggregate # + some bactrace per-worker unique method names may be there .gsub(/"(?:[^"\\]|\\.)*"/, '""').gsub(/__\d+_\d+/, "___").gsub(/\((pry|irb)\):\d+/, '(\1)') end |
#to_json(_options = {}) ⇒ Object
81 82 83 |
# File 'lib/deprecation_collector/deprecation.rb', line 81 def to_json( = {}) as_json.to_json end |
#touch ⇒ Object
39 40 41 |
# File 'lib/deprecation_collector/deprecation.rb', line 39 def touch @occurences += 1 end |