Skip to content

Commit

Permalink
reduce amount of default logging on a failed request (#122)
Browse files Browse the repository at this point in the history
* hide headers, body and backtrace
* these are shown if log.level is debug
* bump version to 5.2.5
  • Loading branch information
jsvd authored May 26, 2021
1 parent cfcf57c commit 19810ea
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 5.2.5
- Reduce amount of default logging on a failed request [#122](https://github.com/logstash-plugins/logstash-output-http/pull/122)

## 5.2.4
- Relax dependency on http_client mixin since current major works on both

Expand Down
26 changes: 16 additions & 10 deletions lib/logstash/outputs/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,22 @@ def send_event(event, attempt)

rescue => exception
will_retry = retryable_exception?(exception)
log_failure("Could not fetch URL",
:url => url,
:method => @http_method,
:body => body,
:headers => headers,
:message => exception.message,
:class => exception.class.name,
:backtrace => exception.backtrace,
:will_retry => will_retry
)
log_params = {
:url => url,
:method => @http_method,
:message => exception.message,
:class => exception.class.name,
:will_retry => will_retry
}
if @logger.debug?
# backtraces are big
log_params[:backtrace] = exception.backtrace
# headers can have sensitive data
log_params[:headers] = headers
# body can be big and may have sensitive data
log_params[:body] = body
end
log_failure("Could not fetch URL", log_params)

if will_retry
return :retry, event, attempt
Expand Down
2 changes: 1 addition & 1 deletion logstash-output-http.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'logstash-output-http'
s.version = '5.2.4'
s.version = '5.2.5'
s.licenses = ['Apache License (2.0)']
s.summary = "Sends events to a generic HTTP or HTTPS endpoint"
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand Down
36 changes: 36 additions & 0 deletions spec/outputs/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,43 @@ def sinatra_run_wait(app, opts)
expect(subject).to have_received(:send_event).exactly(3).times
end
end
end

context "on exception" do
before :each do
allow(subject.client).to receive(:send).and_raise RuntimeError
subject.multi_receive([event])
end

it "should not log headers" do
expect(subject).to have_received(:log_failure).with(anything, hash_not_including(:headers))
end

it "should not log the body" do
expect(subject).to have_received(:log_failure).with(anything, hash_not_including(:body))
end

context "with debug log level" do
before :all do
@current_log_level = LogStash::Logging::Logger.get_logging_context.get_root_logger.get_level.to_s.downcase
LogStash::Logging::Logger.configure_logging "debug"
end
after :all do
LogStash::Logging::Logger.configure_logging @current_log_level
end

it "should log a failure" do
expect(subject).to have_received(:log_failure).with(any_args)
end

it "should not log headers" do
expect(subject).to have_received(:log_failure).with(anything, hash_including(:headers))
end

it "should not log the body" do
expect(subject).to have_received(:log_failure).with(anything, hash_including(:body))
end
end
end
end

Expand Down

0 comments on commit 19810ea

Please sign in to comment.