Sha256: bc429d558dd94c9b4870942c14898e3f08ef80e60c72eee12e280f709442150d

Contents?: true

Size: 930 Bytes

Versions: 8

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

module Switchman
  class ShardedInstrumenter < ::SimpleDelegator
    def initialize(instrumenter, shard_host)
      super(instrumenter)
      @shard_host = shard_host
    end

    def instrument(name, payload = {})
      shard = @shard_host&.shard
      # attribute_methods_generated? will be false during a reload -
      # when we might be doing a query while defining attribute methods,
      # so just avoid logging then
      if shard.is_a?(Shard) && Shard.instance_variable_get(:@attribute_methods_generated)
        payload[:shard] = {
          database_server_id: shard.database_server.id,
          id: shard.id,
          env: if ::Rails.version < "7.0"
                 @shard_host.pool.connection_klass&.current_role
               else
                 @shard_host.pool.connection_class&.current_role
               end
        }
      end
      super(name, payload)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
switchman-3.6.8 lib/switchman/sharded_instrumenter.rb
switchman-3.6.7 lib/switchman/sharded_instrumenter.rb
switchman-3.6.6 lib/switchman/sharded_instrumenter.rb
switchman-3.6.5 lib/switchman/sharded_instrumenter.rb
switchman-3.6.3 lib/switchman/sharded_instrumenter.rb
switchman-3.6.2 lib/switchman/sharded_instrumenter.rb
switchman-3.6.1 lib/switchman/sharded_instrumenter.rb
switchman-3.6.0 lib/switchman/sharded_instrumenter.rb