scout_apm_logging 0.0.0.1 → 0.0.2
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/Rakefile +2 -0
- data/lib/scout_apm/logging/config.rb +1 -1
- data/lib/scout_apm/logging/loggers/capture.rb +21 -16
- data/lib/scout_apm/logging/loggers/logger.rb +2 -2
- data/lib/scout_apm/logging/loggers/proxy.rb +7 -2
- data/lib/scout_apm/logging/loggers/swaps/rails.rb +71 -0
- data/lib/scout_apm/logging/loggers/swaps/scout.rb +62 -0
- data/lib/scout_apm/logging/loggers/swaps/sidekiq.rb +64 -0
- data/lib/scout_apm/logging/monitor_manager/manager.rb +11 -5
- data/lib/scout_apm/logging/version.rb +1 -1
- data/lib/scout_apm_logging.rb +1 -1
- data/scout_apm_logging.gemspec +0 -2
- data/spec/integration/loggers/capture_spec.rb +5 -15
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/loggers/capture_spec.rb +1 -16
- data/spec/unit/monitor/collector/configuration_spec.rb +3 -3
- metadata +5 -3
- data/lib/scout_apm/logging/loggers/swap.rb +0 -82
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbe47505a0defc4e795ece37c30380707600c95708954f2aa99b86e2eff5aefb
|
4
|
+
data.tar.gz: 7aa1c9af19eb96358fbc5ceb037b901cc2dd4a01ab87cc6d737f9b0205fa77cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1d8ee77dd245e14a26a40298c5c77d61af4b1869aa4bc8d53ae1856ae336456148a7a3d2ad865b1e920ef4184fe14120cb07dc453e7b6a8e25738495123a7f1
|
7
|
+
data.tar.gz: 25380fc37e48a7a6a6f901246faf3fec03884c4665a853d6decb3646a566a8b637aaf1851e86f76865429838fb631aaa5d0c245dd9ff7d453824f80a854f2ce3
|
data/Rakefile
CHANGED
@@ -227,7 +227,7 @@ module ScoutApm
|
|
227
227
|
'log_level' => 'info',
|
228
228
|
'logs_monitored' => [],
|
229
229
|
'logs_capture_level' => 'debug',
|
230
|
-
'logs_reporting_endpoint' => 'https://otlp.
|
230
|
+
'logs_reporting_endpoint' => 'https://otlp.scoutotel.com:4317',
|
231
231
|
'logs_proxy_log_dir' => '/tmp/scout_apm/logs/',
|
232
232
|
'manager_lock_file' => '/tmp/scout_apm/monitor_lock_file.lock',
|
233
233
|
'monitor_pid_file' => '/tmp/scout_apm/scout_apm_log_monitor.pid',
|
@@ -2,8 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'logger'
|
4
4
|
|
5
|
-
require_relative './
|
5
|
+
require_relative './formatter'
|
6
|
+
require_relative './logger'
|
6
7
|
require_relative './proxy'
|
8
|
+
require_relative './swaps/rails'
|
9
|
+
require_relative './swaps/sidekiq'
|
10
|
+
require_relative './swaps/scout'
|
7
11
|
|
8
12
|
module ScoutApm
|
9
13
|
module Logging
|
@@ -12,33 +16,34 @@ module ScoutApm
|
|
12
16
|
class Capture
|
13
17
|
attr_reader :context
|
14
18
|
|
19
|
+
KNOWN_LOGGERS = [
|
20
|
+
Swaps::Rails,
|
21
|
+
Swaps::Sidekiq,
|
22
|
+
Swaps::Scout
|
23
|
+
].freeze
|
24
|
+
|
15
25
|
def initialize(context)
|
16
26
|
@context = context
|
17
27
|
end
|
18
28
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
29
|
+
def capture_and_swap_log_locations!
|
30
|
+
return unless context.config.value('logs_monitor')
|
31
|
+
|
32
|
+
create_proxy_log_dir!
|
23
33
|
|
24
|
-
#
|
25
|
-
updated_log_locations =
|
26
|
-
|
34
|
+
# We can move this to filter_map when our lagging version is Ruby 2.7
|
35
|
+
updated_log_locations = KNOWN_LOGGERS.map do |logger|
|
36
|
+
logger.new(context).update_logger! if logger.present?
|
27
37
|
end
|
38
|
+
updated_log_locations.compact!
|
28
39
|
|
29
40
|
context.config.state.add_log_locations!(updated_log_locations)
|
30
41
|
end
|
31
42
|
|
32
43
|
private
|
33
44
|
|
34
|
-
def
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def swapped_in_location(log_instance)
|
39
|
-
swap = Swap.new(context, log_instance)
|
40
|
-
swap.update_logger!
|
41
|
-
swap.log_location
|
45
|
+
def create_proxy_log_dir!
|
46
|
+
Utils.ensure_directory_exists(context.config.value('logs_proxy_log_dir'))
|
42
47
|
end
|
43
48
|
end
|
44
49
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'logger'
|
4
|
-
|
5
3
|
module ScoutApm
|
6
4
|
module Logging
|
7
5
|
module Loggers
|
@@ -29,6 +27,8 @@ module ScoutApm
|
|
29
27
|
new_logger = FileLogger.new(determine_file_path, LOG_AGE, LOG_SIZE)
|
30
28
|
# Ruby's Logger handles a lot of the coercion itself.
|
31
29
|
new_logger.level = context.config.value('logs_capture_level')
|
30
|
+
# Add our custom formatter to the logger.
|
31
|
+
new_logger.formatter = Formatter.new
|
32
32
|
new_logger
|
33
33
|
end
|
34
34
|
|
@@ -1,12 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'logger'
|
4
|
-
|
5
3
|
module ScoutApm
|
6
4
|
module Logging
|
7
5
|
module Loggers
|
8
6
|
# Holds both the original application logger and the new one. Relays commands to both.
|
9
7
|
class Proxy
|
8
|
+
def self.create_with_loggers(original_logger, new_file_logger)
|
9
|
+
new.tap do |proxy_logger|
|
10
|
+
proxy_logger.add(original_logger)
|
11
|
+
proxy_logger.add(new_file_logger)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
10
15
|
def initialize
|
11
16
|
@loggers = []
|
12
17
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ScoutApm
|
4
|
+
module Logging
|
5
|
+
module Loggers
|
6
|
+
module Swaps
|
7
|
+
# Swaps in our logger for the Rails logger.
|
8
|
+
class Rails
|
9
|
+
attr_reader :context
|
10
|
+
|
11
|
+
def self.present?
|
12
|
+
defined?(::Rails) && ::Rails.logger
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(context)
|
16
|
+
@context = context
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_logger!
|
20
|
+
# In Rails 7.1, broadcast logger was added which allows sinking to multiple IO devices.
|
21
|
+
if defined?(::ActiveSupport::BroadcastLogger) && log_instance.is_a?(::ActiveSupport::BroadcastLogger)
|
22
|
+
add_logger_to_broadcast!
|
23
|
+
else
|
24
|
+
swap_in_proxy_logger!
|
25
|
+
end
|
26
|
+
|
27
|
+
new_log_location
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def log_instance
|
33
|
+
::Rails.logger
|
34
|
+
end
|
35
|
+
|
36
|
+
def new_file_logger
|
37
|
+
@new_file_logger ||= Loggers::Logger.new(context, log_instance).create_logger!
|
38
|
+
end
|
39
|
+
|
40
|
+
# Eseentially creates the original logger.
|
41
|
+
def original_logger
|
42
|
+
# We can use the previous logdev. log_device will continuously call write
|
43
|
+
# through the devices until the logdev (@dev) is an IO device other than logdev:
|
44
|
+
# https://github.com/ruby/ruby/blob/master/lib/logger/log_device.rb#L42
|
45
|
+
# Log device holds the configurations around shifting too.
|
46
|
+
original_logdevice = log_instance.instance_variable_get(:@logdev)
|
47
|
+
|
48
|
+
::Logger.new(original_logdevice).tap do |logger|
|
49
|
+
logger.formatter = log_instance.formatter
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def new_log_location
|
54
|
+
new_file_logger.instance_variable_get(:@logdev).filename
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_logger_to_broadcast!
|
58
|
+
log_instance.broadcast_to(new_file_logger)
|
59
|
+
end
|
60
|
+
|
61
|
+
def swap_in_proxy_logger!
|
62
|
+
# First logger needs to be the original logger for the return value of relayed calls.
|
63
|
+
proxy_logger = Proxy.create_with_loggers(original_logger, new_file_logger)
|
64
|
+
|
65
|
+
::Rails.logger = proxy_logger
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ScoutApm
|
4
|
+
module Logging
|
5
|
+
module Loggers
|
6
|
+
module Swaps
|
7
|
+
# Swaps in our logger for the test Scout logger.
|
8
|
+
class Scout
|
9
|
+
attr_reader :context
|
10
|
+
|
11
|
+
def self.present?
|
12
|
+
defined?(::TestLoggerWrapper) && ::TestLoggerWrapper.logger
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(context)
|
16
|
+
@context = context
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_logger!
|
20
|
+
swap_in_proxy_logger!
|
21
|
+
|
22
|
+
new_log_location
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def log_instance
|
28
|
+
::TestLoggerWrapper.logger
|
29
|
+
end
|
30
|
+
|
31
|
+
def new_file_logger
|
32
|
+
@new_file_logger ||= Loggers::Logger.new(context, log_instance).create_logger!
|
33
|
+
end
|
34
|
+
|
35
|
+
# Eseentially creates the original logger.
|
36
|
+
def original_logger
|
37
|
+
# We can use the previous logdev. log_device will continuously call write
|
38
|
+
# through the devices until the logdev (@dev) is an IO device other than logdev:
|
39
|
+
# https://github.com/ruby/ruby/blob/master/lib/logger/log_device.rb#L42
|
40
|
+
# Log device holds the configurations around shifting too.
|
41
|
+
original_logdevice = log_instance.instance_variable_get(:@logdev)
|
42
|
+
|
43
|
+
::Logger.new(original_logdevice).tap do |logger|
|
44
|
+
logger.formatter = log_instance.formatter
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def new_log_location
|
49
|
+
new_file_logger.instance_variable_get(:@logdev).filename
|
50
|
+
end
|
51
|
+
|
52
|
+
def swap_in_proxy_logger!
|
53
|
+
# First logger needs to be the original logger for the return value of relayed calls.
|
54
|
+
proxy_logger = Proxy.create_with_loggers(original_logger, new_file_logger)
|
55
|
+
|
56
|
+
::TestLoggerWrapper.logger = proxy_logger
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ScoutApm
|
4
|
+
module Logging
|
5
|
+
module Loggers
|
6
|
+
module Swaps
|
7
|
+
# Swaps in our logger for the Sidekiq logger.
|
8
|
+
class Sidekiq
|
9
|
+
attr_reader :context
|
10
|
+
|
11
|
+
def self.present?
|
12
|
+
defined?(::Sidekiq) && ::Sidekiq.logger
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(context)
|
16
|
+
@context = context
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_logger!
|
20
|
+
swap_in_proxy_logger!
|
21
|
+
|
22
|
+
new_log_location
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def log_instance
|
28
|
+
::Sidekiq.logger
|
29
|
+
end
|
30
|
+
|
31
|
+
def new_file_logger
|
32
|
+
@new_file_logger ||= Loggers::Logger.new(context, log_instance).create_logger!
|
33
|
+
end
|
34
|
+
|
35
|
+
# Eseentially creates the original logger.
|
36
|
+
def original_logger
|
37
|
+
# We can use the previous logdev. log_device will continuously call write
|
38
|
+
# through the devices until the logdev (@dev) is an IO device other than logdev:
|
39
|
+
# https://github.com/ruby/ruby/blob/master/lib/logger/log_device.rb#L42
|
40
|
+
# Log device holds the configurations around shifting too.
|
41
|
+
original_logdevice = log_instance.instance_variable_get(:@logdev)
|
42
|
+
|
43
|
+
::Logger.new(original_logdevice).tap do |logger|
|
44
|
+
logger.formatter = log_instance.formatter
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def new_log_location
|
49
|
+
new_file_logger.instance_variable_get(:@logdev).filename
|
50
|
+
end
|
51
|
+
|
52
|
+
def swap_in_proxy_logger!
|
53
|
+
# First logger needs to be the original logger for the return value of relayed calls.
|
54
|
+
proxy_logger = Proxy.create_with_loggers(original_logger, new_file_logger)
|
55
|
+
|
56
|
+
::Sidekiq.configure_server do |config|
|
57
|
+
config.logger = proxy_logger
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -24,9 +24,6 @@ module ScoutApm
|
|
24
24
|
add_exit_handler!
|
25
25
|
|
26
26
|
determine_configuration_state
|
27
|
-
|
28
|
-
# Continue to hold the lock until we have written the PID file.
|
29
|
-
ensure_monitor_pid_file_exists
|
30
27
|
end
|
31
28
|
|
32
29
|
def determine_configuration_state
|
@@ -35,6 +32,9 @@ module ScoutApm
|
|
35
32
|
if monitoring_enabled
|
36
33
|
context.logger.info('Log monitoring enabled')
|
37
34
|
create_process
|
35
|
+
|
36
|
+
# Continue to hold the lock until we have written the PID file.
|
37
|
+
ensure_monitor_pid_file_exists
|
38
38
|
else
|
39
39
|
context.logger.info('Log monitoring disabled')
|
40
40
|
remove_processes
|
@@ -50,7 +50,10 @@ module ScoutApm
|
|
50
50
|
at_exit do
|
51
51
|
# Only remove/restart the monitor and collector if we are exiting from an app_server process.
|
52
52
|
# We need to wait on this check, as the process command line changes at some point.
|
53
|
-
|
53
|
+
if Utils.current_process_is_app_server?
|
54
|
+
context.logger.debug('Exiting from app server process. Removing monitor and collector processes.')
|
55
|
+
remove_processes
|
56
|
+
end
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
@@ -64,12 +67,15 @@ module ScoutApm
|
|
64
67
|
gem_directory = File.expand_path('../../../..', __dir__)
|
65
68
|
|
66
69
|
# As we daemonize the process, we will write to the pid file within the process.
|
67
|
-
Process.spawn("ruby #{gem_directory}/bin/scout_apm_logging_monitor", in: reader)
|
70
|
+
pid = Process.spawn("ruby #{gem_directory}/bin/scout_apm_logging_monitor", in: reader)
|
68
71
|
|
69
72
|
reader.close
|
70
73
|
# TODO: Add support for Sinatra.
|
71
74
|
writer.puts Rails.root if defined?(Rails)
|
72
75
|
writer.close
|
76
|
+
# Block until we have spawned the process and forked. This is to ensure
|
77
|
+
# we keep the exclusive lock until the process has written the PID file.
|
78
|
+
Process.wait(pid)
|
73
79
|
end
|
74
80
|
|
75
81
|
private
|
data/lib/scout_apm_logging.rb
CHANGED
@@ -21,7 +21,7 @@ module ScoutApm
|
|
21
21
|
initializer 'scout_apm_logging.monitor' do
|
22
22
|
context = ScoutApm::Logging::MonitorManager.instance.context
|
23
23
|
|
24
|
-
Loggers::Capture.new(context).
|
24
|
+
Loggers::Capture.new(context).capture_and_swap_log_locations!
|
25
25
|
|
26
26
|
unless Utils.skip_setup?
|
27
27
|
Utils.attempt_exclusive_lock(context) do
|
data/scout_apm_logging.gemspec
CHANGED
@@ -2,6 +2,8 @@ require 'logger'
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
+
require_relative '../../../lib/scout_apm/logging/loggers/capture'
|
6
|
+
|
5
7
|
describe ScoutApm::Logging::Loggers::Capture do
|
6
8
|
it 'should find the logger, capture the log destination, and rotate collector configs' do
|
7
9
|
ENV['SCOUT_MONITOR_INTERVAL'] = '10'
|
@@ -17,9 +19,7 @@ describe ScoutApm::Logging::Loggers::Capture do
|
|
17
19
|
first_logger = ScoutTestLogger.new('/tmp/first_file.log')
|
18
20
|
first_logger_basename = File.basename(first_logger.instance_variable_get(:@logdev).filename.to_s)
|
19
21
|
first_logger_updated_path = File.join(context.config.value('logs_proxy_log_dir'), first_logger_basename)
|
20
|
-
|
21
|
-
# While we only use the ObjectSpace for the test logger, we need to wait for it to be captured.
|
22
|
-
wait_for_logger
|
22
|
+
TestLoggerWrapper.logger = first_logger
|
23
23
|
|
24
24
|
similuate_railtie
|
25
25
|
|
@@ -36,6 +36,7 @@ describe ScoutApm::Logging::Loggers::Capture do
|
|
36
36
|
second_logger = ScoutTestLogger.new('/tmp/second_file.log')
|
37
37
|
second_logger_basename = File.basename(second_logger.instance_variable_get(:@logdev).filename.to_s)
|
38
38
|
second_logger_updated_path = File.join(context.config.value('logs_proxy_log_dir'), second_logger_basename)
|
39
|
+
TestLoggerWrapper.logger = second_logger
|
39
40
|
|
40
41
|
similuate_railtie
|
41
42
|
|
@@ -61,18 +62,7 @@ describe ScoutApm::Logging::Loggers::Capture do
|
|
61
62
|
def similuate_railtie
|
62
63
|
context = ScoutApm::Logging::MonitorManager.instance.context
|
63
64
|
|
64
|
-
ScoutApm::Logging::Loggers::Capture.new(context).
|
65
|
+
ScoutApm::Logging::Loggers::Capture.new(context).capture_and_swap_log_locations!
|
65
66
|
ScoutApm::Logging::MonitorManager.new.setup!
|
66
67
|
end
|
67
|
-
|
68
|
-
def wait_for_logger
|
69
|
-
start_time = Time.now
|
70
|
-
loop do
|
71
|
-
break if ObjectSpace.each_object(ScoutTestLogger).count.positive?
|
72
|
-
|
73
|
-
raise 'Timed out while waiting for logger in ObjectSpace' if Time.now - start_time > 10
|
74
|
-
|
75
|
-
sleep 0.1
|
76
|
-
end
|
77
|
-
end
|
78
68
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,6 @@ require 'stringio'
|
|
4
4
|
require 'spec_helper'
|
5
5
|
|
6
6
|
require_relative '../../../lib/scout_apm/logging/loggers/capture'
|
7
|
-
require_relative '../../../lib/scout_apm/logging/loggers/proxy'
|
8
7
|
|
9
8
|
def capture_stdout
|
10
9
|
old_stdout = $stdout
|
@@ -29,11 +28,8 @@ describe ScoutApm::Logging::Loggers::Capture do
|
|
29
28
|
|
30
29
|
TestLoggerWrapper.logger = ScoutTestLogger.new($stdout)
|
31
30
|
|
32
|
-
# While we only use the ObjectSpace for the test logger, we need to wait for it to be captured.
|
33
|
-
wait_for_logger
|
34
|
-
|
35
31
|
capture = ScoutApm::Logging::Loggers::Capture.new(context)
|
36
|
-
capture.
|
32
|
+
capture.capture_and_swap_log_locations!
|
37
33
|
|
38
34
|
expect(TestLoggerWrapper.logger.class).to eq(ScoutApm::Logging::Loggers::Proxy)
|
39
35
|
|
@@ -50,15 +46,4 @@ describe ScoutApm::Logging::Loggers::Capture do
|
|
50
46
|
|
51
47
|
expect(output_from_log).to include('TEST')
|
52
48
|
end
|
53
|
-
|
54
|
-
def wait_for_logger
|
55
|
-
start_time = Time.now
|
56
|
-
loop do
|
57
|
-
break if ObjectSpace.each_object(::ScoutTestLogger).count.positive?
|
58
|
-
|
59
|
-
raise 'Timed out while waiting for logger in ObjectSpace' if Time.now - start_time > 10
|
60
|
-
|
61
|
-
sleep 0.1
|
62
|
-
end
|
63
|
-
end
|
64
49
|
end
|
@@ -12,7 +12,7 @@ describe ScoutApm::Logging::Collector::Configuration do
|
|
12
12
|
expect(File.exist?(context.config.value('collector_config_file'))).to be_truthy
|
13
13
|
config = YAML.load_file(context.config.value('collector_config_file'))
|
14
14
|
|
15
|
-
expect(config['exporters']['otlp']['endpoint']).to eq('https://otlp.
|
15
|
+
expect(config['exporters']['otlp']['endpoint']).to eq('https://otlp.scoutotel.com:4317')
|
16
16
|
expect(config['exporters']['otlp']['headers']['x-telemetryhub-key']).to eq('00001000010000abc')
|
17
17
|
expect(config['receivers']['filelog']['include']).to eq(['/tmp/fake_log_file.log'])
|
18
18
|
end
|
@@ -26,7 +26,7 @@ describe ScoutApm::Logging::Collector::Configuration do
|
|
26
26
|
expect(File.exist?(context.config.value('collector_config_file'))).to be_truthy
|
27
27
|
config = YAML.load_file(context.config.value('collector_config_file'))
|
28
28
|
|
29
|
-
expect(config['exporters']['otlp']['endpoint']).to eq('https://otlp.
|
29
|
+
expect(config['exporters']['otlp']['endpoint']).to eq('https://otlp.scoutotel.com:4317')
|
30
30
|
expect(config['exporters']['otlp']['headers']['x-telemetryhub-key']).to eq('00001000010000abc')
|
31
31
|
expect(config['receivers']['filelog']['include']).to eq(['/tmp/fake_log_file.log'])
|
32
32
|
|
@@ -44,7 +44,7 @@ describe ScoutApm::Logging::Collector::Configuration do
|
|
44
44
|
expect(File.exist?(context.config.value('collector_config_file'))).to be_truthy
|
45
45
|
config = YAML.load_file(context.config.value('collector_config_file'))
|
46
46
|
|
47
|
-
expect(config['exporters']['otlp']['endpoint']).to eq('https://otlp.
|
47
|
+
expect(config['exporters']['otlp']['endpoint']).to eq('https://otlp.scoutotel.com:4317')
|
48
48
|
expect(config['exporters']['otlp']['headers']['x-telemetryhub-key']).to eq('00001000010000abc')
|
49
49
|
expect(config['receivers']['filelog']['include']).to eq(['/tmp/fake_log_file.log'])
|
50
50
|
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.
|
4
|
+
version: 0.0.2
|
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-07-
|
11
|
+
date: 2024-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: scout_apm
|
@@ -89,7 +89,9 @@ files:
|
|
89
89
|
- lib/scout_apm/logging/loggers/formatter.rb
|
90
90
|
- lib/scout_apm/logging/loggers/logger.rb
|
91
91
|
- lib/scout_apm/logging/loggers/proxy.rb
|
92
|
-
- lib/scout_apm/logging/loggers/
|
92
|
+
- lib/scout_apm/logging/loggers/swaps/rails.rb
|
93
|
+
- lib/scout_apm/logging/loggers/swaps/scout.rb
|
94
|
+
- lib/scout_apm/logging/loggers/swaps/sidekiq.rb
|
93
95
|
- lib/scout_apm/logging/monitor/collector/checksum.rb
|
94
96
|
- lib/scout_apm/logging/monitor/collector/configuration.rb
|
95
97
|
- lib/scout_apm/logging/monitor/collector/downloader.rb
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
require_relative './formatter'
|
6
|
-
require_relative './logger'
|
7
|
-
|
8
|
-
module ScoutApm
|
9
|
-
module Logging
|
10
|
-
module Loggers
|
11
|
-
# Swaps in our logger for the application's logger.
|
12
|
-
class Swap
|
13
|
-
attr_reader :context, :log_instance, :new_file_logger
|
14
|
-
|
15
|
-
def initialize(context, log_instance)
|
16
|
-
@context = context
|
17
|
-
@log_instance = log_instance
|
18
|
-
end
|
19
|
-
|
20
|
-
def update_logger!
|
21
|
-
create_proxy_log_dir!
|
22
|
-
|
23
|
-
# In Rails 7.1, broadcast logger was added which allows sinking to multiple IO devices.
|
24
|
-
if defined?(::ActiveSupport::BroadcastLogger) && log_instance.is_a?(::ActiveSupport::BroadcastLogger)
|
25
|
-
add_logger_to_broadcast!
|
26
|
-
else
|
27
|
-
swap_in_proxy_logger!
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def log_location
|
32
|
-
new_file_logger.instance_variable_get(:@logdev).filename
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def add_logger_to_broadcast!
|
38
|
-
@new_file_logger = create_file_logger
|
39
|
-
@new_file_logger.formatter = Loggers::Formatter.new
|
40
|
-
|
41
|
-
log_instance.broadcast_to(new_file_logger)
|
42
|
-
end
|
43
|
-
|
44
|
-
def swap_in_proxy_logger! # rubocop:disable Metrics/AbcSize
|
45
|
-
proxy_logger = Proxy.new
|
46
|
-
# We can use the previous logdev. log_device will continuously call write
|
47
|
-
# through the devices until the logdev (@dev) is an IO device other than logdev:
|
48
|
-
# https://github.com/ruby/ruby/blob/master/lib/logger/log_device.rb#L42
|
49
|
-
# Log device holds the configurations around shifting too.
|
50
|
-
original_logdevice = log_instance.instance_variable_get(:@logdev)
|
51
|
-
updated_original_logger = ::Logger.new(original_logdevice)
|
52
|
-
updated_original_logger.formatter = log_instance.formatter
|
53
|
-
|
54
|
-
@new_file_logger = create_file_logger
|
55
|
-
@new_file_logger.formatter = Loggers::Formatter.new
|
56
|
-
|
57
|
-
# First logger needs to be the original logger for the return value of relayed calls.
|
58
|
-
proxy_logger.add(updated_original_logger)
|
59
|
-
proxy_logger.add(new_file_logger)
|
60
|
-
|
61
|
-
if defined?(::ActiveSupport::Logger) && log_instance.is_a?(::ActiveSupport::Logger)
|
62
|
-
Rails.logger = proxy_logger
|
63
|
-
elsif defined?(::Sidekiq::Logger) && log_instance.is_a?(::Sidekiq::Logger)
|
64
|
-
Sidekiq.configure_server do |config|
|
65
|
-
config.logger = proxy_logger
|
66
|
-
end
|
67
|
-
elsif defined?(::ScoutTestLogger) && log_instance.is_a?(::ScoutTestLogger)
|
68
|
-
TestLoggerWrapper.logger = proxy_logger
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def create_file_logger
|
73
|
-
Loggers::Logger.new(context, log_instance).create_logger!
|
74
|
-
end
|
75
|
-
|
76
|
-
def create_proxy_log_dir!
|
77
|
-
Utils.ensure_directory_exists(context.config.value('logs_proxy_log_dir'))
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|