Skip to content

Commit

Permalink
Fix unnecessary meta_data being logged during breadcrumb validation (#…
Browse files Browse the repository at this point in the history
…530)

* Breadcrumbs/Validator-logging: Fix unnecessary meta_data being logged during breadcrumb validation

* Breadcrumbs/Validator-logging: Include value class in debug log

* Release v6.11.1: Updated changelog and version
  • Loading branch information
Cawllec authored Jan 22, 2019
1 parent ec92f17 commit bf0383a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## 6.11.1 (22 Jan 2019)

### Fixes

* Fix issue with unnecessary meta_data being logged during breadcrumb validation.
| [#530](https://github.com/bugsnag/bugsnag-ruby/pull/530)

## 6.11.0 (17 Jan 2019)

**Note**: this release alters the behaviour of the notifier to track sessions automatically.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.11.0
6.11.1
8 changes: 4 additions & 4 deletions lib/bugsnag/breadcrumbs/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(configuration)
def validate(breadcrumb)
# Check name length
if breadcrumb.name.size > Bugsnag::Breadcrumbs::MAX_NAME_LENGTH
@configuration.warn("Breadcrumb name trimmed to length #{Bugsnag::Breadcrumbs::MAX_NAME_LENGTH}. Original name: #{breadcrumb.name}")
@configuration.debug("Breadcrumb name trimmed to length #{Bugsnag::Breadcrumbs::MAX_NAME_LENGTH}. Original name: #{breadcrumb.name}")
breadcrumb.name = breadcrumb.name.slice(0...Bugsnag::Breadcrumbs::MAX_NAME_LENGTH)
end

Expand All @@ -26,21 +26,21 @@ def validate(breadcrumb)
if valid_meta_data_type?(v)
true
else
@configuration.warn("Breadcrumb #{breadcrumb.name} meta_data #{k}:#{v} has been dropped for having an invalid data type")
@configuration.debug("Breadcrumb #{breadcrumb.name} meta_data #{k}:#{v.class} has been dropped for having an invalid data type")
false
end
end

# Check type is valid, set to manual otherwise
unless Bugsnag::Breadcrumbs::VALID_BREADCRUMB_TYPES.include?(breadcrumb.type)
@configuration.warn("Invalid type: #{breadcrumb.type} for breadcrumb: #{breadcrumb.name}, defaulting to #{Bugsnag::Breadcrumbs::MANUAL_BREADCRUMB_TYPE}")
@configuration.debug("Invalid type: #{breadcrumb.type} for breadcrumb: #{breadcrumb.name}, defaulting to #{Bugsnag::Breadcrumbs::MANUAL_BREADCRUMB_TYPE}")
breadcrumb.type = Bugsnag::Breadcrumbs::MANUAL_BREADCRUMB_TYPE
end

# If auto is true, check type is in enabled_automatic_breadcrumb_types
return unless breadcrumb.auto && !@configuration.enabled_automatic_breadcrumb_types.include?(breadcrumb.type)

@configuration.warn("Automatic breadcrumb of type #{breadcrumb.type} ignored: #{breadcrumb.name}")
@configuration.debug("Automatic breadcrumb of type #{breadcrumb.type} ignored: #{breadcrumb.name}")
breadcrumb.ignore!
end

Expand Down
5 changes: 1 addition & 4 deletions lib/bugsnag/integrations/rails/rails_breadcrumbs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module Bugsnag::Rails
:message => "Read cache",
:type => Bugsnag::Breadcrumbs::PROCESS_BREADCRUMB_TYPE,
:allowed_data => [
:key,
:hit,
:super_operation
]
Expand All @@ -31,9 +30,7 @@ module Bugsnag::Rails
:id => "cache_fetch_hit.active_support",
:message => "Fetch cache hit",
:type => Bugsnag::Breadcrumbs::PROCESS_BREADCRUMB_TYPE,
:allowed_data => [
:key
]
:allowed_data => []
},
{
:id => "sql.active_record",
Expand Down
24 changes: 12 additions & 12 deletions spec/breadcrumbs/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
})

expect(breadcrumb).to_not receive(:ignore!)
expect(config).to_not receive(:warn)
expect(config).to_not receive(:debug)

validator.validate(breadcrumb)
end
Expand All @@ -49,7 +49,7 @@
expect(breadcrumb).to_not receive(:ignore!)
expect(breadcrumb).to receive(:name=).with("123456789012345678901234567890")
expected_string = "Breadcrumb name trimmed to length 30. Original name: #{name}"
expect(config).to receive(:warn).with(expected_string)
expect(config).to receive(:debug).with(expected_string)

validator.validate(breadcrumb)
# Check the original message has not been modified
Expand Down Expand Up @@ -80,7 +80,7 @@
})

expect(breadcrumb).to_not receive(:ignore!)
expect(config).to_not receive(:warn)
expect(config).to_not receive(:debug)

validator.validate(breadcrumb)
end
Expand Down Expand Up @@ -110,12 +110,12 @@ class TestClass
})

expect(breadcrumb).to_not receive(:ignore!)
expected_string_1 = "Breadcrumb #{breadcrumb.name} meta_data array:#{meta_data[:array]} has been dropped for having an invalid data type"
expected_string_2 = "Breadcrumb #{breadcrumb.name} meta_data hash:#{meta_data[:hash]} has been dropped for having an invalid data type"
expected_string_3 = "Breadcrumb #{breadcrumb.name} meta_data object:#{ meta_data[:object]} has been dropped for having an invalid data type"
expect(config).to receive(:warn).with(expected_string_1)
expect(config).to receive(:warn).with(expected_string_2)
expect(config).to receive(:warn).with(expected_string_3)
expected_string_1 = "Breadcrumb #{breadcrumb.name} meta_data array:Array has been dropped for having an invalid data type"
expected_string_2 = "Breadcrumb #{breadcrumb.name} meta_data hash:Hash has been dropped for having an invalid data type"
expected_string_3 = "Breadcrumb #{breadcrumb.name} meta_data object:TestClass has been dropped for having an invalid data type"
expect(config).to receive(:debug).with(expected_string_1)
expect(config).to receive(:debug).with(expected_string_2)
expect(config).to receive(:debug).with(expected_string_3)

# Confirms that the meta_data is being filtered
expect(breadcrumb).to receive(:meta_data=).with({
Expand Down Expand Up @@ -144,7 +144,7 @@ class TestClass
expect(breadcrumb).to receive(:type=).with(Bugsnag::Breadcrumbs::MANUAL_BREADCRUMB_TYPE)
expect(breadcrumb).to_not receive(:ignore!)
expected_string = "Invalid type: #{type} for breadcrumb: #{breadcrumb.name}, defaulting to #{Bugsnag::Breadcrumbs::MANUAL_BREADCRUMB_TYPE}"
expect(config).to receive(:warn).with(expected_string)
expect(config).to receive(:debug).with(expected_string)

validator.validate(breadcrumb)
end
Expand All @@ -169,7 +169,7 @@ class TestClass

expect(breadcrumb).to receive(:ignore!)
expected_string = "Automatic breadcrumb of type #{Bugsnag::Breadcrumbs::ERROR_BREADCRUMB_TYPE} ignored: #{breadcrumb.name}"
expect(config).to receive(:warn).with(expected_string)
expect(config).to receive(:debug).with(expected_string)

validator.validate(breadcrumb)
end
Expand All @@ -191,7 +191,7 @@ class TestClass
})

expect(breadcrumb).to_not receive(:ignore!)
expect(config).to_not receive(:warn)
expect(config).to_not receive(:debug)

validator.validate(breadcrumb)
end
Expand Down

0 comments on commit bf0383a

Please sign in to comment.