scout_apm_logging 0.0.7 → 0.0.9

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: 820ef17ae470e00a8860d6cb25ba09fb908c5c1c2396a564144e8336be787c0f
4
- data.tar.gz: 3338d6fbdc74aa519db27e0017b23af3ede6f6bf7a1e3df4c10ca798e6bc6331
3
+ metadata.gz: 55f7d2c11024d2dba505a31f9a95face612da9befd41e70cce442655e5647711
4
+ data.tar.gz: 0d4b6f542d73fd0b435296e465f814b1593d7d52ae5dd31d7b07965c3e52e2a6
5
5
  SHA512:
6
- metadata.gz: 2e2e011988efb53ed021f0003efab939181af9df79f5ac7b90eea773c0cbf87641f410ea34b4904022bce5ab37f310287e4a04293bee53c66d9d16d988b0aa20
7
- data.tar.gz: '086fd228d639e53c693e05d9cd43f6200cd38f3df7dfa087e1f609fc51dec9b1621e51f06bf1c68eddaed19188c0772250b7249fa550e7a3f5d96a45519cd8f6'
6
+ metadata.gz: 35c113e4c84c336657d4a312385f7b23328518112be3f7a0a234eca56fd66422d264121dd0dbd19bf206ef309904ab9b3a4d40a4b50741185966979a8cb4c1a3
7
+ data.tar.gz: 6e196f2c3625af8ecc6d898a653be40f1e61511e9e20a4b7a30f5a9efa93c3eba6fda5f6bbcb3d43546800ae64b5b1fdd879d697a57f9e4e740e82b4ee350a3e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.0.9
2
+ * Add Scout Transaction ID to log attributes.
3
+
4
+ ## 0.0.8
5
+ * Fix internal method names for proxy logger to prevent accidental overriding.
6
+ * Re-broadcast to console in development for the proxy logger.
7
+ * Fix tags not being removed when yielded contents throw an exception.
8
+ * Fix missing return statement, where tagged logging patches were being added to unintended loggers.
9
+
1
10
  ## 0.0.7
2
11
  * Fix determined logger level comparison
3
12
 
@@ -12,7 +12,7 @@ module ScoutApm
12
12
  class Formatter < ::Logger::Formatter
13
13
  DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%LZ'
14
14
 
15
- def call(severity, time, progname, msg)
15
+ def call(severity, time, progname, msg) # rubocop:disable Metrics/AbcSize
16
16
  attributes_to_log = {
17
17
  severity: severity,
18
18
  time: format_datetime(time),
@@ -23,6 +23,7 @@ module ScoutApm
23
23
  attributes_to_log[:progname] = progname if progname
24
24
  attributes_to_log['service.name'] = service_name
25
25
 
26
+ attributes_to_log.merge!(scout_transaction_id)
26
27
  attributes_to_log.merge!(scout_layer)
27
28
  attributes_to_log.merge!(scout_context)
28
29
  # Naive local benchmarks show this takes around 200 microseconds. As such, we only apply it to WARN and above.
@@ -66,6 +67,10 @@ module ScoutApm
66
67
  user_context.transform_keys { |key| "user.#{key}" }.merge(extra_context)
67
68
  end
68
69
 
70
+ def scout_transaction_id
71
+ { "scout_transaction_id": ScoutApm::RequestManager.lookup.transaction_id }
72
+ end
73
+
69
74
  def local_log_location
70
75
  # Should give us the last local stack which called the log within just the last couple frames.
71
76
  last_local_location = caller[0..15].find { |path| path.include?(Rails.root.to_s) }
@@ -3,7 +3,9 @@
3
3
  module ScoutApm
4
4
  module Logging
5
5
  module Loggers
6
+ # The actual instance of the logger.
6
7
  class FileLogger < ::Logger
8
+ include ::ActiveSupport::LoggerSilence if const_defined?('::ActiveSupport::LoggerSilence')
7
9
  end
8
10
 
9
11
  # The newly created logger which we can configure, and will log to a filepath.
@@ -11,8 +11,8 @@ module ScoutApm
11
11
  # Patches TaggedLogging to work with our loggers.
12
12
  module TaggedLogging
13
13
  def tagged(*tags) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
14
- super(*tags) unless (self == ::Rails.logger && is_a?(ScoutApm::Logging::Loggers::Proxy)) ||
15
- (::Rails.logger.respond_to?(:broadcasts) && ::Rails.logger.broadcasts.include?(self))
14
+ return super(*tags) unless (self == ::Rails.logger && is_a?(ScoutApm::Logging::Loggers::Proxy)) ||
15
+ (::Rails.logger.respond_to?(:broadcasts) && ::Rails.logger.broadcasts.include?(self))
16
16
 
17
17
  if is_a?(ScoutApm::Logging::Loggers::Proxy)
18
18
  if block_given?
@@ -20,8 +20,13 @@ module ScoutApm
20
20
  loggers = @loggers[1..]
21
21
  pushed_counts = extend_and_push_tags(loggers, *tags)
22
22
 
23
- formatter.tagged(*tags) { yield self }.tap do
23
+ begin
24
+ formatter.tagged(*tags) { yield self }.tap do
25
+ logger_pop_tags(loggers, pushed_counts)
26
+ end
27
+ rescue StandardError => e
24
28
  logger_pop_tags(loggers, pushed_counts)
29
+ raise e
25
30
  end
26
31
  else
27
32
  loggers = instance_variable_get(:@loggers)
@@ -36,9 +41,13 @@ module ScoutApm
36
41
  # We skip the first logger to prevent double tagging when calling formatter.tagged
37
42
  loggers = ::Rails.logger.broadcasts[1..]
38
43
  pushed_counts = extend_and_push_tags(loggers, *tags)
39
-
40
- formatter.tagged(*tags) { yield self }.tap do
44
+ begin
45
+ formatter.tagged(*tags) { yield self }.tap do
46
+ logger_pop_tags(loggers, pushed_counts)
47
+ end
48
+ rescue StandardError => e
41
49
  logger_pop_tags(loggers, pushed_counts)
50
+ raise e
42
51
  end
43
52
  else
44
53
  broadcasts = ::Rails.logger.broadcasts
@@ -7,7 +7,7 @@ module ScoutApm
7
7
  class Proxy
8
8
  def self.create_with_loggers(*loggers)
9
9
  new.tap do |proxy_logger|
10
- loggers.each { |logger| proxy_logger.add(logger) }
10
+ loggers.each { |logger| proxy_logger.add_scout_loggers(logger) }
11
11
  end
12
12
  end
13
13
 
@@ -15,11 +15,11 @@ module ScoutApm
15
15
  @loggers = []
16
16
  end
17
17
 
18
- def add(logger)
18
+ def add_scout_loggers(logger)
19
19
  @loggers << logger
20
20
  end
21
21
 
22
- def remove(logger)
22
+ def remove_scout_loggers(logger)
23
23
  @loggers.reject! { |inst_log| inst_log == logger }
24
24
 
25
25
  @loggers
@@ -38,7 +38,7 @@ module ScoutApm
38
38
  end
39
39
 
40
40
  # Eseentially creates the original logger.
41
- def original_logger
41
+ def original_logger # rubocop:disable Metrics/AbcSize
42
42
  # We can use the previous logdev. log_device will continuously call write
43
43
  # through the devices until the logdev (@dev) is an IO device other than logdev:
44
44
  # https://github.com/ruby/ruby/blob/master/lib/logger/log_device.rb#L42
@@ -48,6 +48,14 @@ module ScoutApm
48
48
  ::Logger.new(original_logdevice).tap do |logger|
49
49
  logger.level = log_instance.level
50
50
  logger.formatter = log_instance.formatter
51
+
52
+ if ::Rails.env.development? && $stdout.tty? && $stderr.tty?
53
+ next if ActiveSupport::Logger.respond_to?(:logger_outputs_to?) && ActiveSupport::Logger.logger_outputs_to?(
54
+ logger, $stdout, $stderr
55
+ )
56
+
57
+ logger.extend(ActiveSupport::Logger.broadcast(ActiveSupport::Logger.new($stdout)))
58
+ end
51
59
  end
52
60
  end
53
61
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ScoutApm
4
4
  module Logging
5
- VERSION = '0.0.7'
5
+ VERSION = '0.0.9'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout_apm_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scout APM
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-20 00:00:00.000000000 Z
11
+ date: 2024-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: scout_apm