Skip to content

Commit

Permalink
Do not attempt to transmit if not active
Browse files Browse the repository at this point in the history
If AppSignal is not active, it's likely that there is no valid
configuration. Do not attempt to transmit heartbeats if AppSignal
is not active. Log a debug message about it.
  • Loading branch information
unflxw committed Apr 3, 2024
1 parent 5d73442 commit 207090a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 8 additions & 2 deletions lib/appsignal/heartbeat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ def event(kind)
end

def transmit_event(kind)
unless Appsignal.active?
Appsignal.internal_logger.debug("AppSignal not active, not transmitting heartbeat event")
end

response = self.class.transmitter.transmit(event(kind))

unless response.code.to_i >= 200 && response.code.to_i < 300
Appsignal.logger.warn("Failed to transmit heartbeat event: status code #{response.code}")
Appsignal.internal_logger.warn(
"Failed to transmit heartbeat event: status code was #{response.code}"
)
end
rescue => e
Appsignal.logger.warn("Failed to transmit heartbeat event: #{e}")
Appsignal.internal_logger.warn("Failed to transmit heartbeat event: #{e}")
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/lib/appsignal/heartbeat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it "should send a heartbeat start" do
expect(transmitter).to receive(:transmit).with(hash_including(
:name => "heartbeat-name",
:kind => "Start"
:kind => "start"
)).and_return(nil)

heartbeat.start
Expand All @@ -23,7 +23,7 @@
it "should send a heartbeat finish" do
expect(transmitter).to receive(:transmit).with(hash_including(
:name => "heartbeat-name",
:kind => "Finish"
:kind => "finish"
)).and_return(nil)

heartbeat.finish
Expand All @@ -34,12 +34,12 @@
describe "when a block is given" do
it "should send a heartbeat start and finish and return the block output" do
expect(transmitter).to receive(:transmit).with(hash_including(
:kind => "Start",
:kind => "start",
:name => "heartbeat-with-block"
)).and_return(nil)

expect(transmitter).to receive(:transmit).with(hash_including(
:kind => "Finish",
:kind => "finish",
:name => "heartbeat-with-block"
)).and_return(nil)

Expand All @@ -51,7 +51,7 @@
describe "when no block is given" do
it "should only send a heartbeat finish" do
expect(transmitter).to receive(:transmit).with(hash_including(
:kind => "Finish",
:kind => "finish",
:name => "heartbeat-without-block"
)).and_return(nil)

Expand Down

0 comments on commit 207090a

Please sign in to comment.