Skip to content

Commit 84969ae

Browse files
authored
Deprecate monitor_and_stop helper (#1401)
Deprecate this helper. It causes confusion in use, so let's recommend using the new `enable_at_exit_hook` config option instead. Closes #1387
1 parent f4802bc commit 84969ae

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
bump: patch
3+
type: deprecate
4+
---
5+
6+
Deprecate the `Appsignal.monitor_and_stop` helper.
7+
8+
We instead recommend using the `Appsignal.monitor` helper and configuring the `enable_at_exit_hook` config option to `always`.

lib/appsignal/helpers/instrumentation.rb

+5
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ def monitor(action:, namespace: nil)
154154
#
155155
# @see monitor
156156
def monitor_and_stop(action:, namespace: nil, &block)
157+
Appsignal::Utils::StdoutAndLoggerMessage.warning \
158+
"The `Appsignal.monitor_and_stop` helper is deprecated. " \
159+
"Use the `Appsignal.monitor` along with our `enable_at_exit_hook` " \
160+
"option instead."
161+
157162
monitor(:namespace => namespace, :action => action, &block)
158163
ensure
159164
Appsignal.stop("monitor_and_stop")

spec/lib/appsignal_spec.rb

+13-2
Original file line numberDiff line numberDiff line change
@@ -1170,19 +1170,30 @@ def on_start
11701170
describe ".monitor_and_stop" do
11711171
it "calls Appsignal.stop after the block" do
11721172
allow(Appsignal).to receive(:stop)
1173-
Appsignal.monitor_and_stop(:namespace => "custom", :action => "My Action")
1173+
err_stream = std_stream
1174+
logs =
1175+
capture_logs do
1176+
capture_std_streams(std_stream, err_stream) do
1177+
Appsignal.monitor_and_stop(:namespace => "custom", :action => "My Action")
1178+
end
1179+
end
11741180

11751181
transaction = last_transaction
11761182
expect(transaction).to have_namespace("custom")
11771183
expect(transaction).to have_action("My Action")
11781184
expect(transaction).to be_completed
11791185

11801186
expect(Appsignal).to have_received(:stop).with("monitor_and_stop")
1187+
message = "The `Appsignal.monitor_and_stop` helper is deprecated."
1188+
expect(logs).to contains_log(:warn, message)
1189+
expect(err_stream.read).to include("appsignal WARNING: #{message}")
11811190
end
11821191

11831192
it "passes the block to Appsignal.monitor" do
11841193
expect do |blk|
1185-
Appsignal.monitor_and_stop(:action => "My action", &blk)
1194+
silence do
1195+
Appsignal.monitor_and_stop(:action => "My action", &blk)
1196+
end
11861197
end.to yield_control
11871198
end
11881199
end

0 commit comments

Comments
 (0)