appsignal 3.12.5 → 3.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +73 -0
- data/lib/appsignal/check_in/cron.rb +80 -0
- data/lib/appsignal/check_in.rb +46 -0
- data/lib/appsignal/cli/install.rb +75 -45
- data/lib/appsignal/config.rb +7 -3
- data/lib/appsignal/helpers/heartbeat.rb +20 -0
- data/lib/appsignal/helpers/instrumentation.rb +8 -0
- data/lib/appsignal/integrations/http.rb +2 -7
- data/lib/appsignal/version.rb +1 -1
- data/lib/appsignal.rb +20 -6
- data/spec/lib/appsignal/check_in_spec.rb +342 -0
- data/spec/lib/appsignal/cli/install_spec.rb +114 -41
- data/spec/lib/appsignal/config_spec.rb +24 -0
- data/spec/lib/appsignal/integrations/http_spec.rb +0 -21
- data/spec/lib/appsignal_spec.rb +52 -0
- metadata +6 -5
- data/lib/appsignal/heartbeat.rb +0 -59
- data/lib/appsignal/helpers/heartbeats.rb +0 -44
- data/spec/lib/appsignal/heartbeat_spec.rb +0 -127
data/spec/lib/appsignal_spec.rb
CHANGED
@@ -125,6 +125,28 @@ describe Appsignal do
|
|
125
125
|
expect(Appsignal.config[:push_api_key]).to eq("key")
|
126
126
|
end
|
127
127
|
|
128
|
+
it "loads a new config if the path is not the same" do
|
129
|
+
Appsignal._config = Appsignal::Config.new(
|
130
|
+
"/some/path",
|
131
|
+
:my_env,
|
132
|
+
:name => "Some name",
|
133
|
+
:push_api_key => "Some key",
|
134
|
+
:ignore_actions => ["My action"]
|
135
|
+
)
|
136
|
+
|
137
|
+
Appsignal.configure(:my_env, :root_path => project_fixture_path) do |config|
|
138
|
+
expect(config.ignore_actions).to be_empty
|
139
|
+
config.active = true
|
140
|
+
config.name = "My app"
|
141
|
+
config.push_api_key = "key"
|
142
|
+
end
|
143
|
+
expect(Appsignal.config.valid?).to be(true)
|
144
|
+
expect(Appsignal.config.env).to eq("my_env")
|
145
|
+
expect(Appsignal.config[:active]).to be(true)
|
146
|
+
expect(Appsignal.config[:name]).to eq("My app")
|
147
|
+
expect(Appsignal.config[:push_api_key]).to eq("key")
|
148
|
+
end
|
149
|
+
|
128
150
|
it "calls configure if not started yet" do
|
129
151
|
Appsignal.configure(:my_env) do |config|
|
130
152
|
config.active = false
|
@@ -165,6 +187,16 @@ describe Appsignal do
|
|
165
187
|
expect(Appsignal.config.env).to eq("env_arg")
|
166
188
|
end
|
167
189
|
|
190
|
+
it "uses the given root path to read the config file" do
|
191
|
+
Appsignal.configure(:test, :root_path => project_fixture_path)
|
192
|
+
|
193
|
+
Appsignal.start
|
194
|
+
expect(Appsignal.config.env).to eq("test")
|
195
|
+
expect(Appsignal.config[:push_api_key]).to eq("abc")
|
196
|
+
# Ensure it loads from the config file in the given path
|
197
|
+
expect(Appsignal.config.file_config).to_not be_empty
|
198
|
+
end
|
199
|
+
|
168
200
|
it "loads the config without a block being given" do
|
169
201
|
Dir.chdir project_fixture_path do
|
170
202
|
Appsignal.configure(:test)
|
@@ -172,6 +204,8 @@ describe Appsignal do
|
|
172
204
|
|
173
205
|
expect(Appsignal.config.env).to eq("test")
|
174
206
|
expect(Appsignal.config[:push_api_key]).to eq("abc")
|
207
|
+
# Ensure it loads from the config file in the current working directory
|
208
|
+
expect(Appsignal.config.file_config).to_not be_empty
|
175
209
|
end
|
176
210
|
|
177
211
|
it "allows customization of config in the block" do
|
@@ -1571,6 +1605,24 @@ describe Appsignal do
|
|
1571
1605
|
describe ".listen_for_error" do
|
1572
1606
|
around { |example| keep_transactions { example.run } }
|
1573
1607
|
|
1608
|
+
it "prints and logs a deprecation warning" do
|
1609
|
+
err_stream = std_stream
|
1610
|
+
logs =
|
1611
|
+
capture_logs do
|
1612
|
+
capture_std_streams(std_stream, err_stream) do
|
1613
|
+
Appsignal.listen_for_error do
|
1614
|
+
# Do nothing
|
1615
|
+
end
|
1616
|
+
end
|
1617
|
+
end
|
1618
|
+
expect(err_stream.read)
|
1619
|
+
.to include("appsignal WARNING: The `Appsignal.listen_for_error` helper is deprecated.")
|
1620
|
+
expect(logs).to contains_log(
|
1621
|
+
:warn,
|
1622
|
+
"The `Appsignal.listen_for_error` helper is deprecated."
|
1623
|
+
)
|
1624
|
+
end
|
1625
|
+
|
1574
1626
|
it "records the error and re-raise it" do
|
1575
1627
|
expect do
|
1576
1628
|
expect do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appsignal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Beekman
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-08-
|
13
|
+
date: 2024-08-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rack
|
@@ -186,6 +186,8 @@ files:
|
|
186
186
|
- lib/appsignal.rb
|
187
187
|
- lib/appsignal/auth_check.rb
|
188
188
|
- lib/appsignal/capistrano.rb
|
189
|
+
- lib/appsignal/check_in.rb
|
190
|
+
- lib/appsignal/check_in/cron.rb
|
189
191
|
- lib/appsignal/cli.rb
|
190
192
|
- lib/appsignal/cli/demo.rb
|
191
193
|
- lib/appsignal/cli/diagnose.rb
|
@@ -209,8 +211,7 @@ files:
|
|
209
211
|
- lib/appsignal/extension.rb
|
210
212
|
- lib/appsignal/extension/jruby.rb
|
211
213
|
- lib/appsignal/garbage_collection.rb
|
212
|
-
- lib/appsignal/heartbeat.rb
|
213
|
-
- lib/appsignal/helpers/heartbeats.rb
|
214
|
+
- lib/appsignal/helpers/heartbeat.rb
|
214
215
|
- lib/appsignal/helpers/instrumentation.rb
|
215
216
|
- lib/appsignal/helpers/metrics.rb
|
216
217
|
- lib/appsignal/hooks.rb
|
@@ -312,6 +313,7 @@ files:
|
|
312
313
|
- spec/lib/appsignal/auth_check_spec.rb
|
313
314
|
- spec/lib/appsignal/capistrano2_spec.rb
|
314
315
|
- spec/lib/appsignal/capistrano3_spec.rb
|
316
|
+
- spec/lib/appsignal/check_in_spec.rb
|
315
317
|
- spec/lib/appsignal/cli/demo_spec.rb
|
316
318
|
- spec/lib/appsignal/cli/diagnose/paths_spec.rb
|
317
319
|
- spec/lib/appsignal/cli/diagnose/utils_spec.rb
|
@@ -336,7 +338,6 @@ files:
|
|
336
338
|
- spec/lib/appsignal/extension_install_failure_spec.rb
|
337
339
|
- spec/lib/appsignal/extension_spec.rb
|
338
340
|
- spec/lib/appsignal/garbage_collection_spec.rb
|
339
|
-
- spec/lib/appsignal/heartbeat_spec.rb
|
340
341
|
- spec/lib/appsignal/hooks/action_cable_spec.rb
|
341
342
|
- spec/lib/appsignal/hooks/action_mailer_spec.rb
|
342
343
|
- spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb
|
data/lib/appsignal/heartbeat.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Appsignal
|
4
|
-
class Heartbeat
|
5
|
-
class << self
|
6
|
-
# @api private
|
7
|
-
def transmitter
|
8
|
-
@transmitter ||= Appsignal::Transmitter.new(
|
9
|
-
"#{Appsignal.config[:logging_endpoint]}/heartbeats/json"
|
10
|
-
)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_reader :name, :id
|
15
|
-
|
16
|
-
def initialize(name:)
|
17
|
-
@name = name
|
18
|
-
@id = SecureRandom.hex(8)
|
19
|
-
end
|
20
|
-
|
21
|
-
def start
|
22
|
-
transmit_event("start")
|
23
|
-
end
|
24
|
-
|
25
|
-
def finish
|
26
|
-
transmit_event("finish")
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def event(kind)
|
32
|
-
{
|
33
|
-
:name => name,
|
34
|
-
:id => @id,
|
35
|
-
:kind => kind,
|
36
|
-
:timestamp => Time.now.utc.to_i
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
def transmit_event(kind)
|
41
|
-
unless Appsignal.active?
|
42
|
-
Appsignal.internal_logger.debug("AppSignal not active, not transmitting heartbeat event")
|
43
|
-
return
|
44
|
-
end
|
45
|
-
|
46
|
-
response = self.class.transmitter.transmit(event(kind))
|
47
|
-
|
48
|
-
if response.code.to_i >= 200 && response.code.to_i < 300
|
49
|
-
Appsignal.internal_logger.debug("Transmitted heartbeat `#{name}` (#{id}) #{kind} event")
|
50
|
-
else
|
51
|
-
Appsignal.internal_logger.error(
|
52
|
-
"Failed to transmit heartbeat event: status code was #{response.code}"
|
53
|
-
)
|
54
|
-
end
|
55
|
-
rescue => e
|
56
|
-
Appsignal.internal_logger.error("Failed to transmit heartbeat event: #{e}")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Appsignal
|
4
|
-
module Helpers
|
5
|
-
module Heartbeats
|
6
|
-
# Track heartbeats
|
7
|
-
#
|
8
|
-
# Track the execution of certain processes by sending a hearbeat.
|
9
|
-
#
|
10
|
-
# To track the duration of a piece of code, pass a block to {.heartbeat}
|
11
|
-
# to report both when the process starts, and when it finishes.
|
12
|
-
#
|
13
|
-
# If an exception is raised within the block, the finish event will not
|
14
|
-
# be reported, triggering a notification about the missing heartbeat. The
|
15
|
-
# exception will bubble outside of the heartbeat block.
|
16
|
-
#
|
17
|
-
# @example Send a heartbeat
|
18
|
-
# Appsignal.heartbeat("send_invoices")
|
19
|
-
#
|
20
|
-
# @example Send a heartbeat with duration
|
21
|
-
# Appsignal.heartbeat("send_invoices") do
|
22
|
-
# # your code
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# @param name [String] name of the heartbeat to report.
|
26
|
-
# @yield the block to monitor.
|
27
|
-
# @return [void]
|
28
|
-
# @since 3.7.0
|
29
|
-
# @see https://docs.appsignal.com/heartbeats
|
30
|
-
def heartbeat(name)
|
31
|
-
heartbeat = Appsignal::Heartbeat.new(:name => name)
|
32
|
-
output = nil
|
33
|
-
|
34
|
-
if block_given?
|
35
|
-
heartbeat.start
|
36
|
-
output = yield
|
37
|
-
end
|
38
|
-
|
39
|
-
heartbeat.finish
|
40
|
-
output
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
describe Appsignal::Heartbeat do
|
2
|
-
let(:config) { project_fixture_config }
|
3
|
-
let(:heartbeat) { described_class.new(:name => "heartbeat-name") }
|
4
|
-
let(:transmitter) { Appsignal::Transmitter.new("http://heartbeats/", config) }
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
allow(Appsignal).to receive(:active?).and_return(true)
|
8
|
-
config.logger = Logger.new(StringIO.new)
|
9
|
-
allow(Appsignal::Heartbeat).to receive(:transmitter).and_return(transmitter)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "when Appsignal is not active" do
|
13
|
-
it "should not transmit any events" do
|
14
|
-
allow(Appsignal).to receive(:active?).and_return(false)
|
15
|
-
expect(transmitter).not_to receive(:transmit)
|
16
|
-
|
17
|
-
heartbeat.start
|
18
|
-
heartbeat.finish
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#start" do
|
23
|
-
it "should send a heartbeat start" do
|
24
|
-
expect(transmitter).to receive(:transmit).with(hash_including(
|
25
|
-
:name => "heartbeat-name",
|
26
|
-
:kind => "start"
|
27
|
-
)).and_return(Net::HTTPResponse.new(nil, "200", nil))
|
28
|
-
|
29
|
-
expect(Appsignal.internal_logger).to receive(:debug).with(
|
30
|
-
"Transmitted heartbeat `heartbeat-name` (#{heartbeat.id}) start event"
|
31
|
-
)
|
32
|
-
expect(Appsignal.internal_logger).not_to receive(:error)
|
33
|
-
|
34
|
-
heartbeat.start
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should log an error if it fails" do
|
38
|
-
expect(transmitter).to receive(:transmit).with(hash_including(
|
39
|
-
:name => "heartbeat-name",
|
40
|
-
:kind => "start"
|
41
|
-
)).and_return(Net::HTTPResponse.new(nil, "499", nil))
|
42
|
-
|
43
|
-
expect(Appsignal.internal_logger).not_to receive(:debug)
|
44
|
-
expect(Appsignal.internal_logger).to receive(:error).with(
|
45
|
-
"Failed to transmit heartbeat event: status code was 499"
|
46
|
-
)
|
47
|
-
|
48
|
-
heartbeat.start
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "#finish" do
|
53
|
-
it "should send a heartbeat finish" do
|
54
|
-
expect(transmitter).to receive(:transmit).with(hash_including(
|
55
|
-
:name => "heartbeat-name",
|
56
|
-
:kind => "finish"
|
57
|
-
)).and_return(Net::HTTPResponse.new(nil, "200", nil))
|
58
|
-
|
59
|
-
expect(Appsignal.internal_logger).to receive(:debug).with(
|
60
|
-
"Transmitted heartbeat `heartbeat-name` (#{heartbeat.id}) finish event"
|
61
|
-
)
|
62
|
-
expect(Appsignal.internal_logger).not_to receive(:error)
|
63
|
-
|
64
|
-
heartbeat.finish
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should log an error if it fails" do
|
68
|
-
expect(transmitter).to receive(:transmit).with(hash_including(
|
69
|
-
:name => "heartbeat-name",
|
70
|
-
:kind => "finish"
|
71
|
-
)).and_return(Net::HTTPResponse.new(nil, "499", nil))
|
72
|
-
|
73
|
-
expect(Appsignal.internal_logger).not_to receive(:debug)
|
74
|
-
expect(Appsignal.internal_logger).to receive(:error).with(
|
75
|
-
"Failed to transmit heartbeat event: status code was 499"
|
76
|
-
)
|
77
|
-
|
78
|
-
heartbeat.finish
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe ".heartbeat" do
|
83
|
-
describe "when a block is given" do
|
84
|
-
it "should send a heartbeat start and finish and return the block output" do
|
85
|
-
expect(transmitter).to receive(:transmit).with(hash_including(
|
86
|
-
:kind => "start",
|
87
|
-
:name => "heartbeat-with-block"
|
88
|
-
)).and_return(nil)
|
89
|
-
|
90
|
-
expect(transmitter).to receive(:transmit).with(hash_including(
|
91
|
-
:kind => "finish",
|
92
|
-
:name => "heartbeat-with-block"
|
93
|
-
)).and_return(nil)
|
94
|
-
|
95
|
-
output = Appsignal.heartbeat("heartbeat-with-block") { "output" }
|
96
|
-
expect(output).to eq("output")
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should not send a heartbeat finish event when an error is raised" do
|
100
|
-
expect(transmitter).to receive(:transmit).with(hash_including(
|
101
|
-
:kind => "start",
|
102
|
-
:name => "heartbeat-with-block"
|
103
|
-
)).and_return(nil)
|
104
|
-
|
105
|
-
expect(transmitter).not_to receive(:transmit).with(hash_including(
|
106
|
-
:kind => "finish",
|
107
|
-
:name => "heartbeat-with-block"
|
108
|
-
))
|
109
|
-
|
110
|
-
expect do
|
111
|
-
Appsignal.heartbeat("heartbeat-with-block") { raise "error" }
|
112
|
-
end.to raise_error(RuntimeError, "error")
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "when no block is given" do
|
117
|
-
it "should only send a heartbeat finish event" do
|
118
|
-
expect(transmitter).to receive(:transmit).with(hash_including(
|
119
|
-
:kind => "finish",
|
120
|
-
:name => "heartbeat-without-block"
|
121
|
-
)).and_return(nil)
|
122
|
-
|
123
|
-
Appsignal.heartbeat("heartbeat-without-block")
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|