Fix tagged logging support and add logger broadcasting
Added
-
Add logger broadcasting. This change implements an alternative within
Appsignal::Logger
toActiveSupport::BroadcastLogger
, following the same interface. This enables a proper workaround to the issues withActiveSupport::BroadcastLogger
((#49745, #51883)) when used alongside tagged logging.For example, to use tagged logging both in logs emitted by the default
Rails.logger
and in logs sent to AppSignal, replace theRails.logger
with an AppSignal logger that broadcasts to the defaultRails.logger
:Rubyappsignal_logger = Appsignal::Logger.new("app") appsignal_logger.broadcast_to(Rails.logger) Rails.logger = ActiveSupport::TaggedLogging.new(appsignal_logger)
Removed
-
Remove tagged logging support from
Appsignal::Logger
.Tagged logging is still supported by wrapping an instance of
Appsignal::Logger
withActiveSupport::TaggedLogging
:Rubyappsignal_logger = Appsignal::Logger.new("rails") tagged_logger = ActiveSupport::TaggedLogging.new(appsignal_logger) Rails.logger = tagged_logger
Removing this functionality allows for a workaround to issues within Rails (#49745, #51883), where using the broadcast logger to log to more than one tagged logger results in incorrect behaviour of the tagged logging methods, resulting in breakage throughout Rails' internals:
Ruby# We use the built-in request ID middleware as an example that triggers # the issue: Rails.config.log_tags = [:request_id] appsignal_logger = Appsignal::Logger.new("rails") tagged_logger = ActiveSupport::TaggedLogging.new(appsignal_logger) # This does not work correctly, because the default `Rails.logger` is a # broadcast logger that is already broadcasting to a tagged logger. # When asked to broadcast to a second tagged logger, the return value of # `Rails.logger.tagged { ... }` will be incorrect, in turn causing the # `RequestID` middleware, which uses it internally, to return broken # Rack responses. Rails.logger.broadcast_to(tagged_logger)
By reverting the changes to our logger so that it is no longer a tagged logger, we enable a workaround to this issue:
RubyRails.config.log_tags = [:request_id] appsignal_logger = Appsignal::Logger.new("rails") # This works correctly, because `appsignal_logger` is not a tagged logger. # Note that `appsignal_logger` will not have the `request_id` tags. Rails.logger.broadcast_to(appsignal_logger)
Fixed
- Fix
#silence
implementation forAppsignal::Logger
.
View the Ruby gem v4.3.0 changelog for more information.