Sha256: f406cdc30a35be038dc8a6b47dbaf6426c3edca94c84c8635ce80991e1e13f1b

Contents?: true

Size: 1023 Bytes

Versions: 5

Compression:

Stored size: 1023 Bytes

Contents

require 'json'

module Libhoney
  # For debugging use: a mock version of TransmissionClient that simply prints
  # events to stderr or a file for inspection (and does not send them to
  # Honeycomb, or perform any network activity).
  #
  # @note This class is intended for use in development, for example if you want
  #       to verify what events your instrumented code is sending. Use in
  #       production is not recommended.
  class LogTransmissionClient
    def initialize(output:, verbose: false)
      @output = output
      @verbose = verbose
    end

    # Prints an event
    def add(event)
      if @verbose
        metadata = "Honeycomb dataset '#{event.dataset}' | #{event.timestamp.iso8601}"
        if event.sample_rate != 1
          metadata << " (sample rate: #{event.sample_rate})"
        end
        @output.print("#{metadata} | ")
      end
      @output.puts(event.data.to_json)
    end

    # Flushes the output (but does not close it)
    def close(drain)
      @output.flush
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
libhoney-1.10.1 lib/libhoney/log_transmission.rb
libhoney-1.10.0 lib/libhoney/log_transmission.rb
libhoney-1.9.0 lib/libhoney/log_transmission.rb
libhoney-1.8.1 lib/libhoney/log_transmission.rb
libhoney-1.7.0 lib/libhoney/log_transmission.rb