class Racecar::Datadog::ConsumerSubscriber

Public Instance Methods

join_group(event) click to toggle source
# File lib/racecar/datadog.rb, line 134
def join_group(event)
  tags = {
    client: event.payload.fetch(:client_id),
    group_id: event.payload.fetch(:group_id),
  }

  timing("consumer.join_group", event.duration, tags: tags)

  if event.payload.key?(:exception)
    increment("consumer.join_group.errors", tags: tags)
  end
end
leave_group(event) click to toggle source
# File lib/racecar/datadog.rb, line 147
def leave_group(event)
  tags = {
    client: event.payload.fetch(:client_id),
    group_id: event.payload.fetch(:group_id),
  }

  timing("consumer.leave_group", event.duration, tags: tags)

  if event.payload.key?(:exception)
    increment("consumer.leave_group.errors", tags: tags)
  end
end
main_loop(event) click to toggle source
# File lib/racecar/datadog.rb, line 169
def main_loop(event)
  tags = {
    client: event.payload.fetch(:client_id),
    group_id: event.payload.fetch(:group_id),
  }

  histogram("consumer.loop.duration", event.duration, tags: tags)
end
pause_status(event) click to toggle source
# File lib/racecar/datadog.rb, line 178
def pause_status(event)
  duration = event.payload.fetch(:duration)

  gauge("consumer.pause.duration", duration, tags: default_tags(event))
end
poll_retry(event) click to toggle source
# File lib/racecar/datadog.rb, line 160
def poll_retry(event)
  tags = {
    client: event.payload.fetch(:client_id),
    group_id: event.payload.fetch(:group_id),
  }
  rdkafka_error_code = event.payload.fetch(:exception).code.to_s.gsub(/\W/, '')
  increment("consumer.poll.rdkafka_error.#{rdkafka_error_code}", tags: tags)
end
process_batch(event) click to toggle source
# File lib/racecar/datadog.rb, line 112
def process_batch(event)
  offset = event.payload.fetch(:last_offset)
  messages = event.payload.fetch(:message_count)
  last_create_time = event.payload.fetch(:last_create_time)
  time_lag = last_create_time && ((Time.now - last_create_time) * 1000).to_i
  tags = default_tags(event)

  if event.payload.key?(:exception)
    increment("consumer.process_batch.errors", tags: tags)
  else
    timing("consumer.process_batch.latency", event.duration, tags: tags)
    count("consumer.messages", messages, tags: tags)
  end

  histogram("consumer.batch_size", messages, tags: tags)
  gauge("consumer.offset", offset, tags: tags)

  if time_lag
    gauge("consumer.time_lag", time_lag, tags: tags)
  end
end
process_message(event) click to toggle source
# File lib/racecar/datadog.rb, line 91
def process_message(event)
  offset = event.payload.fetch(:offset)
  create_time = event.payload.fetch(:create_time)
  time_lag = create_time && ((Time.now - create_time) * 1000).to_i
  tags = default_tags(event)

  if event.payload.key?(:exception)
    increment("consumer.process_message.errors", tags: tags)
  else
    timing("consumer.process_message.latency", event.duration, tags: tags)
    increment("consumer.messages", tags: tags)
  end

  gauge("consumer.offset", offset, tags: tags)

  # Not all messages have timestamps.
  if time_lag
    gauge("consumer.time_lag", time_lag, tags: tags)
  end
end

Private Instance Methods

default_tags(event) click to toggle source
# File lib/racecar/datadog.rb, line 186
def default_tags(event)
  {
    client: event.payload.fetch(:client_id),
    group_id: event.payload.fetch(:group_id),
    topic: event.payload.fetch(:topic),
    partition: event.payload.fetch(:partition),
  }
end