appsignal 2.10.2 → 2.10.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42efa30283b2ef38c0913d3314137b6d94b5aabd2c9268e1a624231dbc346990
4
- data.tar.gz: b274b63c33323611103a14cb64d861190406ae84fa5790741f14185ba8607af8
3
+ metadata.gz: 79d4435bb752fd9bf7c142cbfd998e39f3ed5e076e3cbab2b495d3a67ad43ada
4
+ data.tar.gz: ecaa124c56de18417510e0f9798c02888a68ccabc8187e6412739f4669a664e2
5
5
  SHA512:
6
- metadata.gz: e8a41276531fa0c5e94d629a0d6dd6cb8cd3d9cba14dbda18fe865677f75a960e4e9ae741a5782074526de8ebcd55a39d8c029569caa078df07245791f0fdacf
7
- data.tar.gz: '099aa78863b122a0733b1c733cd27c8d80e95ce6092658e4e14b64924644dd4ad6f235f550f20f6006f33e6b4d6ebcfd370f5d5e20ad42916739d92202b21459'
6
+ metadata.gz: 44d8db3ff5eeee9e20062db3a706b4826a34cf5af03c0faf74d5b2a060176a2e4b6a9c187297cf5f071e43a45e0141d253f316f04ca65a6a44d56ce8e4a4d87d
7
+ data.tar.gz: 0f723ad1d12acef218607e83e7f06639c85969e3dda91c700f285d540a875f89d098e0cdac7a7ea2860d1d736815b106a86977967b497eec56dc361d31b6173a
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.10.3
4
+ - Only warn about reused transactions once. Repeated occurrences are logged as
5
+ debug messages. PR #585
6
+
3
7
  ## 2.10.2
4
8
  - Fix wait_for test suite helper. PR #581
5
9
  - Fix exception handling of config file issues. PR #582
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
- require "logger"
5
4
  require "securerandom"
6
5
 
6
+ require "appsignal/logger"
7
7
  require "appsignal/helpers/instrumentation"
8
8
  require "appsignal/helpers/metrics"
9
9
 
@@ -195,7 +195,7 @@ module Appsignal
195
195
  end
196
196
 
197
197
  def logger
198
- @logger ||= Logger.new(in_memory_log).tap do |l|
198
+ @logger ||= Appsignal::Logger.new(in_memory_log).tap do |l|
199
199
  l.level = Logger::INFO
200
200
  l.formatter = log_formatter("appsignal")
201
201
  end
@@ -294,12 +294,12 @@ module Appsignal
294
294
  private
295
295
 
296
296
  def start_stdout_logger
297
- @logger = Logger.new($stdout)
297
+ @logger = Appsignal::Logger.new($stdout)
298
298
  logger.formatter = log_formatter("appsignal")
299
299
  end
300
300
 
301
301
  def start_file_logger(path)
302
- @logger = Logger.new(path)
302
+ @logger = Appsignal::Logger.new(path)
303
303
  logger.formatter = log_formatter
304
304
  rescue SystemCallError => error
305
305
  start_stdout_logger
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "logger"
4
+ require "set"
5
+
6
+ # Subclass of logger with method to only log a warning once
7
+ # prevents the log from filling up with repeated messages.
8
+ module Appsignal
9
+ class Logger < ::Logger
10
+ def seen_keys
11
+ @seen_keys ||= Set.new
12
+ end
13
+
14
+ def warn_once_then_debug(key, message)
15
+ if !seen_keys.add?(key).nil?
16
+ warn message
17
+ else
18
+ debug message
19
+ end
20
+ end
21
+ end
22
+ end
@@ -25,7 +25,7 @@ module Appsignal
25
25
  Thread.current[:appsignal_transaction] = Appsignal::Transaction.new(id, namespace, request, options)
26
26
  else
27
27
  # Otherwise, log the issue about trying to start another transaction
28
- Appsignal.logger.warn "Trying to start new transaction with id " \
28
+ Appsignal.logger.warn_once_then_debug :transaction_id, "Trying to start new transaction with id " \
29
29
  "'#{id}', but a transaction with id '#{current.transaction_id}' " \
30
30
  "is already running. Using transaction '#{current.transaction_id}'."
31
31
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Appsignal
4
- VERSION = "2.10.2".freeze
4
+ VERSION = "2.10.3".freeze
5
5
  end
@@ -0,0 +1,25 @@
1
+ describe Appsignal::Logger do
2
+ let(:log) { std_stream }
3
+ let(:logger) do
4
+ Appsignal::Logger.new(log).tap do |l|
5
+ l.formatter = logger_formatter
6
+ end
7
+ end
8
+
9
+ describe "#seen_keys" do
10
+ it "returns a Set" do
11
+ expect(logger.seen_keys).to be_a(Set)
12
+ end
13
+ end
14
+
15
+ describe "#warn_once_then_debug" do
16
+ it "only warns once, then uses debug" do
17
+ message = "This is a log line"
18
+ 3.times { logger.warn_once_then_debug(:key, message) }
19
+
20
+ logs = log_contents(log)
21
+ expect(logs.scan(/#{Regexp.escape(log_line(:WARN, message))}/).count).to eql(1)
22
+ expect(logs.scan(/#{Regexp.escape(log_line(:DEBUG, message))}/).count).to eql(2)
23
+ end
24
+ end
25
+ end
@@ -1021,6 +1021,7 @@ describe Appsignal do
1021
1021
  Appsignal.start_logger
1022
1022
  Appsignal.logger.error("Log to file")
1023
1023
  end
1024
+ expect(Appsignal.logger).to be_a(Appsignal::Logger)
1024
1025
  end
1025
1026
 
1026
1027
  it "logs to file" do
@@ -1043,6 +1044,7 @@ describe Appsignal do
1043
1044
  initialize_config
1044
1045
  Appsignal.start_logger
1045
1046
  Appsignal.logger.error("Log to not writable log file")
1047
+ expect(Appsignal.logger).to be_a(Appsignal::Logger)
1046
1048
  end
1047
1049
  end
1048
1050
 
@@ -1073,6 +1075,7 @@ describe Appsignal do
1073
1075
  Appsignal.start_logger
1074
1076
  Appsignal.logger.error("Log to not writable log path")
1075
1077
  end
1078
+ expect(Appsignal.logger).to be_a(Appsignal::Logger)
1076
1079
  end
1077
1080
  after do
1078
1081
  FileUtils.chmod 0o755, Appsignal::Config.system_tmp_dir
@@ -1101,6 +1104,7 @@ describe Appsignal do
1101
1104
  Appsignal.start_logger
1102
1105
  Appsignal.logger.error("Log to stdout")
1103
1106
  end
1107
+ expect(Appsignal.logger).to be_a(Appsignal::Logger)
1104
1108
  end
1105
1109
  around { |example| recognize_as_heroku { example.run } }
1106
1110
 
@@ -12,15 +12,22 @@ module LogHelpers
12
12
  end
13
13
 
14
14
  def test_logger(log)
15
- Logger.new(log).tap do |logger|
16
- logger.formatter =
17
- proc do |severity, _datetime, _progname, msg|
18
- # This format is used in the `contains_log` matcher.
19
- "[#{severity}] #{msg}\n"
20
- end
15
+ Appsignal::Logger.new(log).tap do |logger|
16
+ logger.formatter = logger_formatter
21
17
  end
22
18
  end
23
19
 
20
+ def logger_formatter
21
+ proc do |severity, _datetime, _progname, msg|
22
+ log_line(severity, msg)
23
+ end
24
+ end
25
+
26
+ def log_line(severity, message)
27
+ # This format is used in the `contains_log` matcher.
28
+ "[#{severity}] #{message}\n"
29
+ end
30
+
24
31
  def log_contents(log)
25
32
  log.rewind
26
33
  log.read
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.10.2
4
+ version: 2.10.3
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: 2020-01-30 00:00:00.000000000 Z
13
+ date: 2020-02-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -237,6 +237,7 @@ files:
237
237
  - lib/appsignal/integrations/sinatra.rb
238
238
  - lib/appsignal/integrations/webmachine.rb
239
239
  - lib/appsignal/js_exception_transaction.rb
240
+ - lib/appsignal/logger.rb
240
241
  - lib/appsignal/marker.rb
241
242
  - lib/appsignal/minutely.rb
242
243
  - lib/appsignal/rack/generic_instrumentation.rb
@@ -314,6 +315,7 @@ files:
314
315
  - spec/lib/appsignal/integrations/sinatra_spec.rb
315
316
  - spec/lib/appsignal/integrations/webmachine_spec.rb
316
317
  - spec/lib/appsignal/js_exception_transaction_spec.rb
318
+ - spec/lib/appsignal/logger_spec.rb
317
319
  - spec/lib/appsignal/marker_spec.rb
318
320
  - spec/lib/appsignal/minutely_spec.rb
319
321
  - spec/lib/appsignal/rack/generic_instrumentation_spec.rb
@@ -392,7 +394,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
392
394
  - !ruby/object:Gem::Version
393
395
  version: '0'
394
396
  requirements: []
395
- rubygems_version: 3.0.6
397
+ rubygems_version: 3.1.2
396
398
  signing_key:
397
399
  specification_version: 4
398
400
  summary: Logs performance and exception data from your app to appsignal.com
@@ -452,6 +454,7 @@ test_files:
452
454
  - spec/lib/appsignal/integrations/sinatra_spec.rb
453
455
  - spec/lib/appsignal/integrations/webmachine_spec.rb
454
456
  - spec/lib/appsignal/js_exception_transaction_spec.rb
457
+ - spec/lib/appsignal/logger_spec.rb
455
458
  - spec/lib/appsignal/marker_spec.rb
456
459
  - spec/lib/appsignal/minutely_spec.rb
457
460
  - spec/lib/appsignal/rack/generic_instrumentation_spec.rb