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.



5
6
7
8
# File 'lib/switchman/sharded_instrumenter.rb', line 5

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

Instance Method Details

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



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

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: shard.database_server.guard_rail_environment
    }
  end
  super name, payload
end