Module: LogStruct::Integrations::ActiveModelSerializers
- Extended by:
- T::Sig
- Defined in:
- lib/log_struct/integrations/active_model_serializers.rb
Overview
ActiveModelSerializers integration. Subscribes to AMS notifications and emits structured logs with serializer/adapter/duration details.
Class Method Summary collapse
Class Method Details
.setup(config) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/log_struct/integrations/active_model_serializers.rb', line 14 def self.setup(config) return nil unless defined?(::ActiveSupport::Notifications) # Only activate if AMS appears to be present return nil unless defined?(::ActiveModelSerializers) # Subscribe to common AMS notification names; keep broad but specific pattern = /\.active_model_serializers\z/ ::ActiveSupport::Notifications.subscribe(pattern) do |_name, started, finished, _unique_id, payload| # started/finished are Time; convert to ms duration_ms = ((finished - started) * 1000.0).round(3) serializer = payload[:serializer] || payload[:serializer_class] adapter = payload[:adapter] resource = payload[:resource] || payload[:object] LogStruct.info( LogStruct::Log::ActiveModelSerializers.new( message: "ams.render", serializer: serializer&.name, adapter: adapter&.class&.name, resource_class: resource&.class&.name, duration_ms: duration_ms, timestamp: started ) ) rescue => e LogStruct.handle_exception(e, source: LogStruct::Source::Rails, context: {integration: :active_model_serializers}) end true end |