fix: dont call method on unitialized logger #50
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes an issue where the
error
method is called on a nil@logger
instance variable. Seefluent-plugin-datadog/lib/fluent/plugin/out_datadog.rb
Line 144 in 49f8e4e
The
@logger
instance variable is only set in theDatadogClient
class and its subclasses, but it is never initialized in the parentFluent::DatadogOutput
class. Instead, I believe the output plugin should be using thelog
method of the PluginLoggerMixin. At least this would match the example from the docs.Note that I tried to write tests for this, but (a) was unable to mock a failed method call in test-unit and (b) was unable to access the instance of the Fluent log object to assert anything. Let me know if I'm missing something, happy to take another swing at a unit test if this is doable.
Motivation
Any exception coming from the
write
method is lost. Right now it is very difficult to debug failures from the plugin. The only error message I'm getting isundefined method 'error' for nil:NilClass
. This has come up in previous issues like #41 as wellAdditional Notes
Anything else we should know when reviewing?
I appreciate your work on this Gem ❤️