Class: Switchman::ShardedInstrumenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/switchman/sharded_instrumenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(instrumenter, shard_host) ⇒ ShardedInstrumenter

Returns a new instance of ShardedInstrumenter.



3
4
5
6
# File 'lib/switchman/sharded_instrumenter.rb', line 3

def initialize(instrumenter, shard_host)
  super instrumenter
  @shard_host = shard_host
end

Instance Method Details

#instrument(name, payload = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/switchman/sharded_instrumenter.rb', line 8

def instrument(name, payload={})
  shard = @shard_host.try(: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: shard.database_server.shackles_environment
    }
  end
  super name, payload
end