Skip to content

Commit

Permalink
chore: Rename skip_instrumenting to skip_otel_emit
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle committed Dec 5, 2024
1 parent 8f9038c commit 40f4b9a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def unknown(*args)
private

# Emit logs from only one of the loggers in the broadcast.
# Set @skip_instrumenting to `true` to the rest of the loggers before emitting the logs.
# Set @skip_instrumenting to `false` after the log is emitted.
# Set @skip_otel_emit to `true` to the rest of the loggers before emitting the logs.
# Set @skip_otel_emit to `false` after the log is emitted.
def emit_one_broadcast(*args)
broadcasts[1..-1].each { |broadcasted_logger| broadcasted_logger.instance_variable_set(:@skip_instrumenting, true) }
broadcasts[1..-1].each { |broadcasted_logger| broadcasted_logger.instance_variable_set(:@skip_otel_emit, true) }
yield
broadcasts.each { |broadcasted_logger| broadcasted_logger.instance_variable_set(:@skip_instrumenting, false) }
broadcasts.each { |broadcasted_logger| broadcasted_logger.instance_variable_set(:@skip_otel_emit, false) }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module ActiveSupportLogger
# destinations from generating OpenTelemetry log record objects.
# Available in Rails 7.0 and below
def broadcast(logger)
logger.instance_variable_set(:@skip_instrumenting, true)
logger.instance_variable_set(:@skip_otel_emit, true)
super
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ module Logger
module Patches
# Instrumention for methods from Ruby's Logger class
module Logger
attr_writer :skip_instrumenting
attr_writer :skip_otel_emit

def format_message(severity, datetime, progname, msg)
formatted_message = super
return formatted_message if skip_instrumenting?
return formatted_message if skip_otel_emit?

OpenTelemetry.logger_provider.logger(
name: OpenTelemetry::Instrumentation::Logger::NAME,
Expand All @@ -31,8 +31,8 @@ def format_message(severity, datetime, progname, msg)

private

def skip_instrumenting?
@skip_instrumenting || false
def skip_otel_emit?
@skip_otel_emit || false
end

def severity_number(severity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
assert_match(/#{msg}/, log_record.body)
end

it 'does not add @skip_instrumenting to the initial logger' do
refute Rails.logger.instance_variable_defined?(:@skip_instrumenting)
it 'does not add @skip_otel_emit to the initial logger' do
refute Rails.logger.instance_variable_defined?(:@skip_otel_emit)
end

it 'adds @skip_instrumenting to broadcasted loggers' do
assert broadcasted_logger.instance_variable_defined?(:@skip_instrumenting)
it 'adds @skip_otel_emit to broadcasted loggers' do
assert broadcasted_logger.instance_variable_defined?(:@skip_otel_emit)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
end
end

it 'does not emit when @skip_instrumenting is true' do
ruby_logger.instance_variable_set(:@skip_instrumenting, true)
it 'does not emit when @skip_otel_emit is true' do
ruby_logger.instance_variable_set(:@skip_otel_emit, true)
ruby_logger.debug(msg)
assert_nil(log_record)
end
Expand Down

0 comments on commit 40f4b9a

Please sign in to comment.