appsignal 2.3.0.beta.1 → 2.3.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/appsignal.rb +5 -2
- data/lib/appsignal/cli/diagnose.rb +20 -3
- data/lib/appsignal/cli/helpers.rb +1 -1
- data/lib/appsignal/cli/install.rb +13 -3
- data/lib/appsignal/config.rb +16 -5
- data/lib/appsignal/integrations/delayed_job_plugin.rb +1 -1
- data/lib/appsignal/version.rb +1 -1
- data/spec/lib/appsignal/cli/diagnose_spec.rb +44 -1
- data/spec/lib/appsignal/cli/install_spec.rb +6 -3
- data/spec/lib/appsignal/config_spec.rb +28 -1
- data/spec/lib/appsignal/hooks/delayed_job_spec.rb +41 -10
- data/spec/lib/appsignal_spec.rb +97 -36
- data/spec/spec_helper.rb +8 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8993e01c5974b60000801e1e46ea7742d928bd7
|
4
|
+
data.tar.gz: 3da3e926724a76fac40d950810663eeacea9d9d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 547b5cb15977cbca5cfba66f6559101f0ef8763e0e2a5db530a696e631929dabd361c658bd0f47e8fd59d1fda46aa8b4c91a69fa80abcf6e349f79658c2c2e28
|
7
|
+
data.tar.gz: 7760ba42ef65a3f1915aa3e5d149f6f07d95591e8a16d18598cfa1a771733dac53ecccb4300aa6b7763a0452b38f1230da9329b2338913ea12c58ed6c9b38668
|
data/CHANGELOG.md
CHANGED
@@ -6,12 +6,15 @@
|
|
6
6
|
* Improve log messages for transactions. PR #293
|
7
7
|
* Remove thread_safe dependency. PR #294
|
8
8
|
* Add `Transaction#params` attribute for custom parameters. PR #295
|
9
|
+
* Fix queue time on DelayedJob integration. PR #297
|
9
10
|
* Add ActionCable support. PR #309
|
10
11
|
* Finish ActiveSupport notifications events when they would encounter a `raise`
|
11
12
|
or a `throw`. PR #310
|
12
13
|
* Add `ignore_namespaces` option. PR #312
|
13
14
|
* Truncate lengthy parameter values to 2000 characters.
|
14
15
|
Commit 65de1382f5f453b624781cde6e0544c89fdf89ef
|
16
|
+
* Disable gracefully on Microsoft Windows. PR #313
|
17
|
+
* Add tags and namespace arguments to `Appsignal.set_error`. PR #317
|
15
18
|
|
16
19
|
# 2.2.1
|
17
20
|
* Fix support for Rails 5.1. PR #286
|
data/lib/appsignal.rb
CHANGED
@@ -315,11 +315,14 @@ module Appsignal
|
|
315
315
|
# @see http://docs.appsignal.com/ruby/instrumentation/exception-handling.html
|
316
316
|
# Exception handling guide
|
317
317
|
# @since 0.6.6
|
318
|
-
def set_error(exception)
|
318
|
+
def set_error(exception, tags = nil, namespace = nil)
|
319
319
|
return if !active? ||
|
320
320
|
Appsignal::Transaction.current.nil? ||
|
321
321
|
exception.nil?
|
322
|
-
Appsignal::Transaction.current
|
322
|
+
transaction = Appsignal::Transaction.current
|
323
|
+
transaction.set_error(exception)
|
324
|
+
transaction.set_tags(tags) if tags
|
325
|
+
transaction.set_namespace(namespace) if namespace
|
323
326
|
end
|
324
327
|
alias :set_exception :set_error
|
325
328
|
alias :add_exception :set_error
|
@@ -69,6 +69,7 @@ module Appsignal
|
|
69
69
|
# @return [void]
|
70
70
|
# @api private
|
71
71
|
def run(options = {})
|
72
|
+
$stdout.sync = true
|
72
73
|
header
|
73
74
|
empty_line
|
74
75
|
|
@@ -171,6 +172,11 @@ module Appsignal
|
|
171
172
|
|
172
173
|
def run_agent_diagnose_mode
|
173
174
|
puts "Agent diagnostics"
|
175
|
+
unless Appsignal.extension_loaded?
|
176
|
+
puts " Extension is not loaded. No agent report created."
|
177
|
+
return
|
178
|
+
end
|
179
|
+
|
174
180
|
ENV["_APPSIGNAL_DIAGNOSE"] = "true"
|
175
181
|
diagnostics_report_string = Appsignal::Extension.diagnose
|
176
182
|
ENV.delete("_APPSIGNAL_DIAGNOSE")
|
@@ -288,7 +294,12 @@ module Appsignal
|
|
288
294
|
puts "Host information"
|
289
295
|
data_section :host do
|
290
296
|
puts_and_save :architecture, "Architecture", rbconfig["host_cpu"]
|
291
|
-
|
297
|
+
|
298
|
+
os_label = os = rbconfig["host_os"]
|
299
|
+
os_label = "#{os_label} (Microsoft Windows is not supported.)" if Gem.win_platform?
|
300
|
+
save :os, os
|
301
|
+
puts_value "Operating System", os_label
|
302
|
+
|
292
303
|
puts_and_save :language_version, "Ruby version",
|
293
304
|
"#{rbconfig["ruby_version"]}-p#{rbconfig["PATCHLEVEL"]}"
|
294
305
|
|
@@ -370,7 +381,7 @@ module Appsignal
|
|
370
381
|
file_uid = File.stat(path).uid
|
371
382
|
{
|
372
383
|
:uid => file_uid,
|
373
|
-
:user =>
|
384
|
+
:user => username_for_uid(file_uid)
|
374
385
|
}
|
375
386
|
end
|
376
387
|
|
@@ -380,7 +391,7 @@ module Appsignal
|
|
380
391
|
process_uid = Process.uid
|
381
392
|
@process_user = {
|
382
393
|
:uid => process_uid,
|
383
|
-
:user =>
|
394
|
+
:user => username_for_uid(process_uid)
|
384
395
|
}
|
385
396
|
end
|
386
397
|
|
@@ -458,6 +469,12 @@ module Appsignal
|
|
458
469
|
end
|
459
470
|
end
|
460
471
|
|
472
|
+
def username_for_uid(uid)
|
473
|
+
passwd_struct = Etc.getpwuid(uid)
|
474
|
+
return unless passwd_struct
|
475
|
+
passwd_struct.name
|
476
|
+
end
|
477
|
+
|
461
478
|
def empty_line
|
462
479
|
puts "\n"
|
463
480
|
end
|
@@ -12,6 +12,8 @@ module Appsignal
|
|
12
12
|
|
13
13
|
class << self
|
14
14
|
def run(push_api_key)
|
15
|
+
$stdout.sync = true
|
16
|
+
|
15
17
|
puts
|
16
18
|
puts colorize "#######################################", :green
|
17
19
|
puts colorize "## Starting AppSignal Installer ##", :green
|
@@ -24,7 +26,7 @@ module Appsignal
|
|
24
26
|
puts colorize "Problem encountered:", :red
|
25
27
|
puts " No push API key entered."
|
26
28
|
puts " - Sign up for AppSignal and follow the instructions"
|
27
|
-
puts " - Already signed up? Click '
|
29
|
+
puts " - Already signed up? Click 'Add app' on the account overview page"
|
28
30
|
puts
|
29
31
|
puts colorize "Exiting installer...", :red
|
30
32
|
return
|
@@ -59,7 +61,12 @@ module Appsignal
|
|
59
61
|
elsif installed_frameworks.include?(:sinatra)
|
60
62
|
install_for_sinatra(config)
|
61
63
|
else
|
62
|
-
|
64
|
+
print colorize "Warning:", :red
|
65
|
+
puts " We could not detect which framework you are using. "\
|
66
|
+
"We'd be very grateful if you email us on support@appsignal.com "\
|
67
|
+
"with information about your setup."
|
68
|
+
puts
|
69
|
+
done_notice
|
63
70
|
end
|
64
71
|
end
|
65
72
|
|
@@ -199,7 +206,10 @@ module Appsignal
|
|
199
206
|
sleep 0.3
|
200
207
|
puts
|
201
208
|
if Gem.win_platform?
|
202
|
-
puts "The AppSignal agent currently does not work on
|
209
|
+
puts "The AppSignal agent currently does not work on Microsoft " \
|
210
|
+
"Windows. Please push these changes to your staging/production " \
|
211
|
+
"environment and make sure some actions are performed. " \
|
212
|
+
"AppSignal should pick up your app after a few minutes."
|
203
213
|
else
|
204
214
|
puts " Sending example data to AppSignal..."
|
205
215
|
if Appsignal::Demo.transmit
|
data/lib/appsignal/config.rb
CHANGED
@@ -2,10 +2,10 @@ require "erb"
|
|
2
2
|
require "yaml"
|
3
3
|
require "uri"
|
4
4
|
require "socket"
|
5
|
+
require "tmpdir"
|
5
6
|
|
6
7
|
module Appsignal
|
7
8
|
class Config
|
8
|
-
SYSTEM_TMP_DIR = File.realpath("/tmp")
|
9
9
|
DEFAULT_CONFIG = {
|
10
10
|
:debug => false,
|
11
11
|
:log => "file",
|
@@ -84,6 +84,16 @@ module Appsignal
|
|
84
84
|
validate
|
85
85
|
end
|
86
86
|
|
87
|
+
# @api private
|
88
|
+
# @return [String] System's tmp directory.
|
89
|
+
def self.system_tmp_dir
|
90
|
+
if Gem.win_platform?
|
91
|
+
Dir.tmpdir
|
92
|
+
else
|
93
|
+
File.realpath("/tmp")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
87
97
|
def [](key)
|
88
98
|
config_hash[key]
|
89
99
|
end
|
@@ -98,14 +108,15 @@ module Appsignal
|
|
98
108
|
return File.join(File.realpath(path), "appsignal.log")
|
99
109
|
end
|
100
110
|
|
101
|
-
|
111
|
+
system_tmp_dir = self.class.system_tmp_dir
|
112
|
+
if File.writable? system_tmp_dir
|
102
113
|
$stdout.puts "appsignal: Unable to log to '#{path}'. Logging to "\
|
103
|
-
"'#{
|
114
|
+
"'#{system_tmp_dir}' instead. Please check the "\
|
104
115
|
"permissions for the application's (log) directory."
|
105
|
-
File.join(
|
116
|
+
File.join(system_tmp_dir, "appsignal.log")
|
106
117
|
else
|
107
118
|
$stdout.puts "appsignal: Unable to log to '#{path}' or the "\
|
108
|
-
"'#{
|
119
|
+
"'#{system_tmp_dir}' fallback. Please check the permissions "\
|
109
120
|
"for the application's (log) directory."
|
110
121
|
end
|
111
122
|
end
|
data/lib/appsignal/version.rb
CHANGED
@@ -29,7 +29,15 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :report => true do
|
|
29
29
|
let(:process_user) { Etc.getpwuid(Process.uid).name }
|
30
30
|
before(:context) { Appsignal.stop }
|
31
31
|
before do
|
32
|
+
# Clear previous reports
|
32
33
|
DiagnosticsReportEndpoint.clear_report!
|
34
|
+
if cli.instance_variable_defined? :@data
|
35
|
+
# Because this is saved on the class rather than an instance of the
|
36
|
+
# class we need to clear it like this in case a certain test doesn't
|
37
|
+
# generate a report.
|
38
|
+
cli.remove_instance_variable :@data
|
39
|
+
end
|
40
|
+
|
33
41
|
if DependencyHelper.rails_present?
|
34
42
|
allow(Rails).to receive(:root).and_return(Pathname.new(config.root_path))
|
35
43
|
end
|
@@ -260,6 +268,24 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :report => true do
|
|
260
268
|
end
|
261
269
|
end
|
262
270
|
|
271
|
+
context "when the extension is not loaded" do
|
272
|
+
before do
|
273
|
+
DiagnosticsReportEndpoint.clear_report!
|
274
|
+
expect(Appsignal).to receive(:extension_loaded?).and_return(false)
|
275
|
+
run
|
276
|
+
end
|
277
|
+
|
278
|
+
it "prints a warning" do
|
279
|
+
expect(output).to include \
|
280
|
+
"Agent diagnostics",
|
281
|
+
" Extension is not loaded. No agent report created."
|
282
|
+
end
|
283
|
+
|
284
|
+
it "adds the output to the report" do
|
285
|
+
expect(received_report["agent"]).to be_nil
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
263
289
|
context "when the report contains an error" do
|
264
290
|
let(:agent_report) do
|
265
291
|
{ "error" => "fatal error" }
|
@@ -373,6 +399,23 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :report => true do
|
|
373
399
|
"Ruby version: #{language_version}"
|
374
400
|
end
|
375
401
|
|
402
|
+
context "when on Microsoft Windows" do
|
403
|
+
before do
|
404
|
+
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return("mingw32")
|
405
|
+
expect(RbConfig::CONFIG).to receive(:[]).at_least(:once).and_call_original
|
406
|
+
expect(Gem).to receive(:win_platform?).and_return(true)
|
407
|
+
run
|
408
|
+
end
|
409
|
+
|
410
|
+
it "adds the arch to the report" do
|
411
|
+
expect(received_report["host"]["os"]).to eq("mingw32")
|
412
|
+
end
|
413
|
+
|
414
|
+
it "prints warning that Microsoft Windows is not supported" do
|
415
|
+
expect(output).to match(/Operating System: .+ \(Microsoft Windows is not supported\.\)/)
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
376
419
|
it "transmits host information in report" do
|
377
420
|
run
|
378
421
|
host_report = received_report["host"]
|
@@ -594,7 +637,7 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :report => true do
|
|
594
637
|
end
|
595
638
|
|
596
639
|
describe "paths" do
|
597
|
-
let(:system_tmp_dir) { Appsignal::Config
|
640
|
+
let(:system_tmp_dir) { Appsignal::Config.system_tmp_dir }
|
598
641
|
before do
|
599
642
|
FileUtils.mkdir_p(root_path)
|
600
643
|
FileUtils.mkdir_p(system_tmp_dir)
|
@@ -210,8 +210,8 @@ describe Appsignal::CLI::Install do
|
|
210
210
|
end
|
211
211
|
|
212
212
|
it "prints a warning for windows" do
|
213
|
-
expect(output).to include("The AppSignal agent currently does not work on Windows")
|
214
|
-
expect(output).to include("
|
213
|
+
expect(output).to include("The AppSignal agent currently does not work on Microsoft Windows")
|
214
|
+
expect(output).to include("staging/production environment")
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
@@ -614,12 +614,15 @@ describe Appsignal::CLI::Install do
|
|
614
614
|
context "with unknown framework" do
|
615
615
|
let(:push_api_key) { "my_key" }
|
616
616
|
|
617
|
+
it_behaves_like "windows installation"
|
617
618
|
it_behaves_like "push_api_key validation"
|
619
|
+
it_behaves_like "demo data"
|
618
620
|
|
619
621
|
it "prints a message about unknown framework" do
|
620
622
|
run
|
621
623
|
|
622
|
-
expect(output).to include
|
624
|
+
expect(output).to include \
|
625
|
+
"\e[31mWarning:\e[0m We could not detect which framework you are using."
|
623
626
|
expect(output).to_not include_env_push_api_key
|
624
627
|
expect(output).to_not include_env_app_name
|
625
628
|
expect(File.exist?(config_file_path)).to be_falsy
|
@@ -444,7 +444,7 @@ describe Appsignal::Config do
|
|
444
444
|
end
|
445
445
|
|
446
446
|
shared_examples "#log_file_path: tmp path" do
|
447
|
-
let(:system_tmp_dir) { described_class
|
447
|
+
let(:system_tmp_dir) { described_class.system_tmp_dir }
|
448
448
|
before { FileUtils.mkdir_p(system_tmp_dir) }
|
449
449
|
after { FileUtils.rm_rf(system_tmp_dir) }
|
450
450
|
|
@@ -558,4 +558,31 @@ describe Appsignal::Config do
|
|
558
558
|
end
|
559
559
|
end
|
560
560
|
end
|
561
|
+
|
562
|
+
describe ".system_tmp_dir" do
|
563
|
+
before do
|
564
|
+
# To counteract the stub in spec_helper
|
565
|
+
expect(Appsignal::Config).to receive(:system_tmp_dir).and_call_original
|
566
|
+
end
|
567
|
+
|
568
|
+
context "when on a *NIX OS" do
|
569
|
+
before do
|
570
|
+
expect(Gem).to receive(:win_platform?).and_return(false)
|
571
|
+
end
|
572
|
+
|
573
|
+
it "returns the system's tmp dir" do
|
574
|
+
expect(described_class.system_tmp_dir).to eq(File.realpath("/tmp"))
|
575
|
+
end
|
576
|
+
end
|
577
|
+
|
578
|
+
context "when on Microsoft Windows" do
|
579
|
+
before do
|
580
|
+
expect(Gem).to receive(:win_platform?).and_return(true)
|
581
|
+
end
|
582
|
+
|
583
|
+
it "returns the system's tmp dir" do
|
584
|
+
expect(described_class.system_tmp_dir).to eq(Dir.tmpdir)
|
585
|
+
end
|
586
|
+
end
|
587
|
+
end
|
561
588
|
end
|
@@ -34,6 +34,8 @@ describe Appsignal::Hooks::DelayedJobHook do
|
|
34
34
|
describe ".invoke_with_instrumentation" do
|
35
35
|
let(:plugin) { Appsignal::Hooks::DelayedJobPlugin }
|
36
36
|
let(:time) { Time.parse("01-01-2001 10:01:00UTC") }
|
37
|
+
let(:created_at) { time - 3600 }
|
38
|
+
let(:run_at) { time - 3600 }
|
37
39
|
let(:job_data) do
|
38
40
|
{
|
39
41
|
:id => 123,
|
@@ -41,7 +43,8 @@ describe Appsignal::Hooks::DelayedJobHook do
|
|
41
43
|
:priority => 1,
|
42
44
|
:attempts => 1,
|
43
45
|
:queue => "default",
|
44
|
-
:created_at =>
|
46
|
+
:created_at => created_at,
|
47
|
+
:run_at => run_at,
|
45
48
|
:payload_object => double(:args => args)
|
46
49
|
}
|
47
50
|
end
|
@@ -60,7 +63,8 @@ describe Appsignal::Hooks::DelayedJobHook do
|
|
60
63
|
:queue => "default",
|
61
64
|
:id => "123"
|
62
65
|
},
|
63
|
-
:
|
66
|
+
:params => args,
|
67
|
+
:queue_start => run_at
|
64
68
|
}
|
65
69
|
end
|
66
70
|
after do
|
@@ -116,6 +120,17 @@ describe Appsignal::Hooks::DelayedJobHook do
|
|
116
120
|
end
|
117
121
|
end
|
118
122
|
|
123
|
+
context "with run_at in the future" do
|
124
|
+
let(:run_at) { Time.parse("2017-01-01 10:01:00UTC") }
|
125
|
+
|
126
|
+
it "reports queue_start with run_at time" do
|
127
|
+
expect(Appsignal).to receive(:monitor_transaction).with(
|
128
|
+
"perform_job.delayed_job",
|
129
|
+
default_params.merge(:queue_start => run_at)
|
130
|
+
)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
119
134
|
context "with custom name call" do
|
120
135
|
let(:job_data) do
|
121
136
|
{
|
@@ -128,7 +143,8 @@ describe Appsignal::Hooks::DelayedJobHook do
|
|
128
143
|
:priority => 1,
|
129
144
|
:attempts => 1,
|
130
145
|
:queue => "default",
|
131
|
-
:created_at =>
|
146
|
+
:created_at => created_at,
|
147
|
+
:run_at => run_at
|
132
148
|
}
|
133
149
|
end
|
134
150
|
let(:default_params) do
|
@@ -141,7 +157,7 @@ describe Appsignal::Hooks::DelayedJobHook do
|
|
141
157
|
:queue => "default",
|
142
158
|
:id => "123"
|
143
159
|
},
|
144
|
-
:queue_start =>
|
160
|
+
:queue_start => run_at
|
145
161
|
}
|
146
162
|
end
|
147
163
|
|
@@ -210,16 +226,20 @@ describe Appsignal::Hooks::DelayedJobHook do
|
|
210
226
|
:queue => "default",
|
211
227
|
:id => "123"
|
212
228
|
},
|
213
|
-
:queue_start =>
|
229
|
+
:queue_start => run_at,
|
230
|
+
:params => args
|
214
231
|
}
|
215
232
|
end
|
233
|
+
let(:args) { ["activejob_argument"] }
|
216
234
|
before { job_data[:args] = args }
|
217
235
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
236
|
+
context "with simple params" do
|
237
|
+
it "wraps it in a transaction with the correct params" do
|
238
|
+
expect(Appsignal).to receive(:monitor_transaction).with(
|
239
|
+
"perform_job.delayed_job",
|
240
|
+
default_params.merge(:params => ["activejob_argument"])
|
241
|
+
)
|
242
|
+
end
|
223
243
|
end
|
224
244
|
|
225
245
|
context "with more complex params" do
|
@@ -261,6 +281,17 @@ describe Appsignal::Hooks::DelayedJobHook do
|
|
261
281
|
end
|
262
282
|
end
|
263
283
|
end
|
284
|
+
|
285
|
+
context "with run_at in the future" do
|
286
|
+
let(:run_at) { Time.parse("2017-01-01 10:01:00UTC") }
|
287
|
+
|
288
|
+
it "reports queue_start with run_at time" do
|
289
|
+
expect(Appsignal).to receive(:monitor_transaction).with(
|
290
|
+
"perform_job.delayed_job",
|
291
|
+
default_params.merge(:queue_start => run_at)
|
292
|
+
)
|
293
|
+
end
|
294
|
+
end
|
264
295
|
end
|
265
296
|
end
|
266
297
|
end
|
data/spec/lib/appsignal_spec.rb
CHANGED
@@ -605,7 +605,7 @@ describe Appsignal do
|
|
605
605
|
context "when the log path and fallback path are not writable" do
|
606
606
|
before do
|
607
607
|
FileUtils.chmod 0o444, log_path
|
608
|
-
FileUtils.chmod 0o444, Appsignal::Config
|
608
|
+
FileUtils.chmod 0o444, Appsignal::Config.system_tmp_dir
|
609
609
|
|
610
610
|
capture_stdout(out_stream) do
|
611
611
|
Appsignal.start_logger
|
@@ -613,7 +613,7 @@ describe Appsignal do
|
|
613
613
|
end
|
614
614
|
end
|
615
615
|
after do
|
616
|
-
FileUtils.chmod 0o755, Appsignal::Config
|
616
|
+
FileUtils.chmod 0o755, Appsignal::Config.system_tmp_dir
|
617
617
|
end
|
618
618
|
|
619
619
|
it "logs to stdout" do
|
@@ -628,7 +628,7 @@ describe Appsignal do
|
|
628
628
|
it "outputs a warning" do
|
629
629
|
expect(output).to include \
|
630
630
|
"appsignal: Unable to log to '#{log_path}' "\
|
631
|
-
"or the '#{Appsignal::Config
|
631
|
+
"or the '#{Appsignal::Config.system_tmp_dir}' fallback."
|
632
632
|
end
|
633
633
|
end
|
634
634
|
|
@@ -712,42 +712,69 @@ describe Appsignal do
|
|
712
712
|
end
|
713
713
|
|
714
714
|
describe ".send_error" do
|
715
|
-
let(:
|
715
|
+
let(:transaction) do
|
716
|
+
Appsignal::Transaction.new(
|
717
|
+
SecureRandom.uuid,
|
718
|
+
Appsignal::Transaction::HTTP_REQUEST,
|
719
|
+
Appsignal::Transaction::GenericRequest.new({})
|
720
|
+
)
|
721
|
+
end
|
716
722
|
let(:error) { VerySpecificError.new }
|
717
723
|
|
718
|
-
it "
|
719
|
-
expect(Appsignal::Transaction).to receive(:new).
|
724
|
+
it "sends the error to AppSignal" do
|
725
|
+
expect(Appsignal::Transaction).to receive(:new).with(
|
726
|
+
kind_of(String),
|
727
|
+
Appsignal::Transaction::HTTP_REQUEST,
|
728
|
+
kind_of(Appsignal::Transaction::GenericRequest)
|
729
|
+
).and_return(transaction)
|
730
|
+
expect(transaction).to receive(:set_error).with(error)
|
731
|
+
expect(transaction).to_not receive(:set_tags)
|
732
|
+
expect(transaction).to receive(:complete)
|
733
|
+
|
734
|
+
Appsignal.send_error(error)
|
735
|
+
end
|
736
|
+
|
737
|
+
context "when given error is not an Exception" do
|
738
|
+
let(:error) { double }
|
739
|
+
|
740
|
+
it "logs an error message" do
|
741
|
+
expect(Appsignal.logger).to receive(:error)
|
742
|
+
.with("Can't send error, given value is not an exception")
|
743
|
+
end
|
744
|
+
|
745
|
+
it "does not send the error" do
|
746
|
+
expect(Appsignal::Transaction).to_not receive(:create)
|
747
|
+
end
|
748
|
+
|
749
|
+
after { Appsignal.send_error(error) }
|
720
750
|
end
|
721
751
|
|
722
752
|
context "with tags" do
|
723
753
|
let(:tags) { { :a => "a", :b => "b" } }
|
724
|
-
|
725
|
-
it "should tag the request before sending" do
|
726
|
-
transaction = Appsignal::Transaction.new(
|
727
|
-
SecureRandom.uuid,
|
728
|
-
Appsignal::Transaction::HTTP_REQUEST,
|
729
|
-
Appsignal::Transaction::GenericRequest.new({})
|
730
|
-
)
|
754
|
+
before do
|
731
755
|
allow(Appsignal::Transaction).to receive(:new).and_return(transaction)
|
732
|
-
|
756
|
+
end
|
757
|
+
|
758
|
+
it "tags the request before sending it" do
|
759
|
+
expect(transaction).to receive(:set_tags).with(tags).and_call_original
|
733
760
|
expect(transaction).to receive(:complete)
|
761
|
+
|
762
|
+
Appsignal.send_error(error, tags)
|
734
763
|
end
|
735
764
|
end
|
736
765
|
|
737
|
-
context "
|
738
|
-
let(:
|
766
|
+
context "with namespace" do
|
767
|
+
let(:namespace) { "admin" }
|
739
768
|
|
740
|
-
it "
|
741
|
-
expect(Appsignal
|
769
|
+
it "sets the namespace on the transaction" do
|
770
|
+
expect(Appsignal::Transaction).to receive(:new).with(
|
771
|
+
kind_of(String),
|
772
|
+
"admin",
|
773
|
+
kind_of(Appsignal::Transaction::GenericRequest)
|
774
|
+
).and_call_original
|
742
775
|
end
|
743
776
|
|
744
|
-
|
745
|
-
expect(Appsignal::Transaction).to_not receive(:create)
|
746
|
-
end
|
747
|
-
end
|
748
|
-
|
749
|
-
after do
|
750
|
-
Appsignal.send_error(error, tags)
|
777
|
+
after { Appsignal.send_error(error, nil, namespace) }
|
751
778
|
end
|
752
779
|
end
|
753
780
|
|
@@ -766,24 +793,58 @@ describe Appsignal do
|
|
766
793
|
before { allow(Appsignal::Transaction).to receive(:current).and_return(transaction) }
|
767
794
|
let(:error) { RuntimeError.new("I am an exception") }
|
768
795
|
|
769
|
-
|
770
|
-
|
796
|
+
context "when there is an active transaction" do
|
797
|
+
it "adds the error to the active transaction" do
|
798
|
+
expect(transaction).to receive(:set_error).with(error)
|
799
|
+
expect(transaction).to_not receive(:set_tags)
|
800
|
+
expect(transaction).to_not receive(:set_namespace)
|
771
801
|
|
772
|
-
|
773
|
-
|
802
|
+
Appsignal.set_error(error)
|
803
|
+
end
|
774
804
|
|
775
|
-
|
776
|
-
|
805
|
+
context "when the error is nil" do
|
806
|
+
it "does nothing" do
|
807
|
+
expect(transaction).to_not receive(:set_error)
|
808
|
+
expect(transaction).to_not receive(:set_tags)
|
809
|
+
expect(transaction).to_not receive(:set_namespace)
|
810
|
+
|
811
|
+
Appsignal.set_error(nil)
|
812
|
+
end
|
813
|
+
end
|
814
|
+
|
815
|
+
context "with tags" do
|
816
|
+
let(:tags) { { "foo" => "bar" } }
|
777
817
|
|
778
|
-
|
818
|
+
it "sets the tags on the transaction" do
|
819
|
+
expect(transaction).to receive(:set_error).with(error)
|
820
|
+
expect(transaction).to receive(:set_tags).with(tags)
|
821
|
+
expect(transaction).to_not receive(:set_namespace)
|
779
822
|
|
780
|
-
|
823
|
+
Appsignal.set_error(error, tags)
|
824
|
+
end
|
825
|
+
end
|
826
|
+
|
827
|
+
context "with namespace" do
|
828
|
+
let(:namespace) { "admin" }
|
829
|
+
|
830
|
+
it "sets the namespace on the transaction" do
|
831
|
+
expect(transaction).to receive(:set_error).with(error)
|
832
|
+
expect(transaction).to_not receive(:set_tags)
|
833
|
+
expect(transaction).to receive(:set_namespace).with(namespace)
|
834
|
+
|
835
|
+
Appsignal.set_error(error, nil, namespace)
|
836
|
+
end
|
837
|
+
end
|
781
838
|
end
|
782
839
|
|
783
|
-
|
784
|
-
|
840
|
+
context "when there is no active transaction" do
|
841
|
+
it "does nothing" do
|
842
|
+
allow(Appsignal::Transaction).to receive(:current).and_return(nil)
|
785
843
|
|
786
|
-
|
844
|
+
expect(transaction).to_not receive(:set_error)
|
845
|
+
|
846
|
+
Appsignal.set_error(error)
|
847
|
+
end
|
787
848
|
end
|
788
849
|
end
|
789
850
|
|
data/spec/spec_helper.rb
CHANGED
@@ -60,14 +60,13 @@ RSpec.configure do |config|
|
|
60
60
|
|
61
61
|
config.fail_if_no_examples = true
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
Appsignal::Config.send :const_set, :SYSTEM_TMP_DIR,
|
67
|
-
File.join(tmp_dir, "system-tmp")
|
63
|
+
def spec_system_tmp_dir
|
64
|
+
File.join(tmp_dir, "system-tmp")
|
65
|
+
end
|
68
66
|
|
67
|
+
config.before :context do
|
69
68
|
FileUtils.rm_rf(tmp_dir)
|
70
|
-
FileUtils.mkdir_p(
|
69
|
+
FileUtils.mkdir_p(spec_system_tmp_dir)
|
71
70
|
end
|
72
71
|
|
73
72
|
config.before do
|
@@ -79,6 +78,9 @@ RSpec.configure do |config|
|
|
79
78
|
appsignal_key_prefixes = %w(APPSIGNAL_ _APPSIGNAL_)
|
80
79
|
env_keys = ENV.keys.select { |key| key.start_with?(*appsignal_key_prefixes) }
|
81
80
|
env_keys.each { |key| ENV.delete(key) }
|
81
|
+
|
82
|
+
# Stub system_tmp_dir to something in the project dir for specs
|
83
|
+
allow(Appsignal::Config).to receive(:system_tmp_dir).and_return(spec_system_tmp_dir)
|
82
84
|
end
|
83
85
|
|
84
86
|
config.after 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: 2.3.0.beta.
|
4
|
+
version: 2.3.0.beta.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Beekman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-06-
|
12
|
+
date: 2017-06-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|