From 37befe6f0a5b0d460e368f8fcbf85f31284e384c Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Tue, 17 Oct 2023 15:49:22 -0700 Subject: [PATCH] Remove public reader for log_record_processors --- .../opentelemetry/sdk/logs/logger_provider.rb | 17 ++++++----------- .../sdk/logs/logger_provider_test.rb | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/logs_sdk/lib/opentelemetry/sdk/logs/logger_provider.rb b/logs_sdk/lib/opentelemetry/sdk/logs/logger_provider.rb index f71700e5c..1fb453cb6 100644 --- a/logs_sdk/lib/opentelemetry/sdk/logs/logger_provider.rb +++ b/logs_sdk/lib/opentelemetry/sdk/logs/logger_provider.rb @@ -9,7 +9,7 @@ module SDK module Logs # The SDK implementation of OpenTelemetry::Logs::LoggerProvider. class LoggerProvider < OpenTelemetry::Logs::LoggerProvider - attr_reader :resource, :log_record_processors + attr_reader :resource UNEXPECTED_ERROR_MESSAGE = 'unexpected error in ' \ 'OpenTelemetry::SDK::Logs::LoggerProvider#%s' @@ -17,15 +17,10 @@ class LoggerProvider < OpenTelemetry::Logs::LoggerProvider # # @param [optional Resource] resource The resource to associate with # new LogRecords created by {Logger}s created by this LoggerProvider. - # @param [optional Array] log_record_processors The - # {LogRecordProcessor}s to associate with this LoggerProvider. # # @return [OpenTelemetry::SDK::Logs::LoggerProvider] - def initialize( - resource: OpenTelemetry::SDK::Resources::Resource.create, - log_record_processors: [] - ) - @log_record_processors = log_record_processors + def initialize(resource: OpenTelemetry::SDK::Resources::Resource.create) + @log_record_processors = [] @mutex = Mutex.new @resource = resource @stopped = false @@ -53,7 +48,7 @@ def logger(name = nil, version = nil) # {LogRecordProcessor} to add to this LoggerProvider. def add_log_record_processor(log_record_processor) @mutex.synchronize do - @log_record_processors = log_record_processors.dup.push(log_record_processor) + @log_record_processors = @log_record_processors.dup.push(log_record_processor) end end @@ -77,7 +72,7 @@ def shutdown(timeout: nil) end start_time = OpenTelemetry::Common::Utilities.timeout_timestamp - results = log_record_processors.map do |processor| + results = @log_record_processors.map do |processor| remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time) break [OpenTelemetry::SDK::Logs::Export::TIMEOUT] if remaining_timeout&.zero? @@ -108,7 +103,7 @@ def force_flush(timeout: nil) return Export::SUCCESS if @stopped start_time = OpenTelemetry::Common::Utilities.timeout_timestamp - results = log_record_processors.map do |processor| + results = @log_record_processors.map do |processor| remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time) return Export::TIMEOUT if remaining_timeout&.zero? diff --git a/logs_sdk/test/opentelemetry/sdk/logs/logger_provider_test.rb b/logs_sdk/test/opentelemetry/sdk/logs/logger_provider_test.rb index 72aadf8b9..b65558899 100644 --- a/logs_sdk/test/opentelemetry/sdk/logs/logger_provider_test.rb +++ b/logs_sdk/test/opentelemetry/sdk/logs/logger_provider_test.rb @@ -26,10 +26,10 @@ describe '#add_log_record_processor' do it "adds the processor to the logger provider's processors" do - assert_equal(0, logger_provider.log_record_processors.length) + assert_equal(0, logger_provider.instance_variable_get(:@log_record_processors).length) logger_provider.add_log_record_processor(mock_log_record_processor) - assert_equal(1, logger_provider.log_record_processors.length) + assert_equal(1, logger_provider.instance_variable_get(:@log_record_processors).length) end end