Skip to content

Commit

Permalink
Remove public reader for log_record_processors
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle committed Oct 17, 2023
1 parent 5528277 commit 37befe6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
17 changes: 6 additions & 11 deletions logs_sdk/lib/opentelemetry/sdk/logs/logger_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,18 @@ 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'
# Returns a new LoggerProvider instance.
#
# @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
Expand Down Expand Up @@ -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

Expand All @@ -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?

Expand Down Expand Up @@ -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?

Expand Down
4 changes: 2 additions & 2 deletions logs_sdk/test/opentelemetry/sdk/logs/logger_provider_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 37befe6

Please sign in to comment.