Commit 6860271f12e84c963a945d52c6a7412ae1c18752

Authored by Arthur Nogueira Neves
2 parents c5044b3d 3473d360
Exists in master and in 1 other branch production

Merge pull request #680 from csaunders/md5_fingerprints

Adds legacy MD5 fingerprinting scheme
README.md
... ... @@ -409,6 +409,19 @@ end
409 409  
410 410 Then get the `notifier.js` from `errbit/public/javascript/notifier.js` and add to `application.js` on your rails app or include `http://YOUR-ERRBIT-HOST/javascripts/notifier.js` on your `application.html.erb.`
411 411  
  412 +Using custom fingerprinting methods
  413 +-----------------------------------
  414 +
  415 +Errbit now allows you to easily use your own Fingerprint Strategy if that's what you'd like to do. If you are upgrading from a very old version of errbit, you can use the `LegacyFingerprint` to provide yourself
  416 +with compatibility. The fingerprint strategy can be changed by adding an initializer to errbit:
  417 +
  418 +```ruby
  419 +# config/fingerprint.rb
  420 +ErrorReport.fingerprint_strategy = LegacyFingerprint
  421 +```
  422 +
  423 +The easiest way to add custom fingerprint methods is to simply subclass `Fingerprint`
  424 +
412 425 Issue Trackers
413 426 --------------
414 427  
... ...
app/models/fingerprints/legacy_fingerprint.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +require 'digest/md5'
  2 +
  3 +class LegacyFingerprint < Fingerprint
  4 + def to_s
  5 + Digest::MD5.hexdigest(fingerprint_source)
  6 + end
  7 +
  8 + def fingerprint_source
  9 + location['method'] &&= sanitized_method_signature
  10 + end
  11 +
  12 + private
  13 + def sanitized_method_signature
  14 + location['method'].gsub(/[0-9]+|FRAGMENT/, '#').gsub(/_+#/, '_#')
  15 + end
  16 +
  17 + def location
  18 + notice.backtrace.lines.first
  19 + end
  20 +end
... ...
spec/models/fingerprints/legacy_fingerprint_spec.rb 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +require 'spec_helper'
  2 +
  3 +describe LegacyFingerprint do
  4 + context 'being created' do
  5 + let(:backtrace) do
  6 + Backtrace.create(:raw => [
  7 + {
  8 + "number"=>"17",
  9 + "file"=>"[GEM_ROOT]/gems/activesupport/lib/active_support/callbacks.rb",
  10 + "method"=>"_run__2497084960985961383__process_action__2062871603614456254__callbacks"
  11 + }
  12 + ])
  13 + end
  14 + let(:notice1) { Fabricate.build(:notice, :backtrace => backtrace) }
  15 + let(:notice2) { Fabricate.build(:notice, :backtrace => backtrace_2) }
  16 +
  17 + context "with same backtrace" do
  18 + let(:backtrace_2) do
  19 + backtrace
  20 + backtrace.lines.last.method = '_run__FRAGMENT__process_action__FRAGMENT__callbacks'
  21 + backtrace.save
  22 + backtrace
  23 + end
  24 +
  25 + it "normalizes the fingerprint of generated methods" do
  26 + expect(LegacyFingerprint.generate(notice1, "api key")).to eql LegacyFingerprint.generate(notice2, "api key")
  27 + end
  28 + end
  29 +
  30 + context "with same backtrace where FRAGMENT has not been extracted" do
  31 + let(:backtrace_2) do
  32 + backtrace
  33 + backtrace.lines.last.method = '_run__998857585768765__process_action__1231231312321313__callbacks'
  34 + backtrace.save
  35 + backtrace
  36 + end
  37 +
  38 + it "normalizes the fingerprint of generated methods" do
  39 + expect(LegacyFingerprint.generate(notice1, "api key")).to eql LegacyFingerprint.generate(notice2, "api key")
  40 + end
  41 + end
  42 + end
  43 +end
... ...