Changelog

Improving AppSignal, one deploy at a time.

Dec 20, 2024

Fix tagged logging support and add logger broadcasting

Ruby4.3.0

Added

  • Add logger broadcasting. This change implements an alternative within Appsignal::Logger to ActiveSupport::BroadcastLogger, following the same interface. This enables a proper workaround to the issues with ActiveSupport::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 the Rails.logger with an AppSignal logger that broadcasts to the default Rails.logger:

    Ruby
    appsignal_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 with ActiveSupport::TaggedLogging:

    Ruby
    appsignal_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:

    Ruby
    Rails.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 for Appsignal::Logger.

View the Ruby gem v4.3.0 changelog for more information.

View all Ruby updates

Start your free trial

Don’t let the bad bugs bite. Try AppSignal for free.

AppSignal offers a 30-day free trial, no credit card is required. All features are available in all plans. Start monitoring your application in just a few clicks!