Sha256: 17bddda22530868364dc0fd1409b77e8c025b59ce848721a3672dd44ef5f80ff

Contents?: true

Size: 1.32 KB

Versions: 10

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require "socket"

module Honeycomb
  # Used to configure the Honeycomb client
  class Configuration
    attr_accessor :write_key,
                  :dataset,
                  :api_host,
                  :debug

    attr_writer :service_name, :client, :host_name

    def initialize
      @write_key = ENV["HONEYCOMB_WRITEKEY"]
      @dataset = ENV["HONEYCOMB_DATASET"]
      @service_name = ENV["HONEYCOMB_SERVICE"]
      @debug = ENV.key?("HONEYCOMB_DEBUG")
      @client = nil
    end

    def service_name
      @service_name || dataset
    end

    def client
      options = {}.tap do |o|
        o[:writekey] = write_key
        o[:dataset] = dataset
        api_host && o[:api_host] = api_host
      end

      @client ||
        (debug && Libhoney::LogClient.new) ||
        Libhoney::Client.new(options)
    end

    def after_initialize(client)
      super(client) if defined?(super)
    end

    def host_name
      # Send the heroku dyno name instead of hostname if available
      @host_name || ENV["DYNO"] || Socket.gethostname
    end

    def presend_hook(&hook)
      if block_given?
        @presend_hook = hook
      else
        @presend_hook
      end
    end

    def sample_hook(&hook)
      if block_given?
        @sample_hook = hook
      else
        @sample_hook
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
honeycomb-beeline-2.0.0 lib/honeycomb/configuration.rb
honeycomb-beeline-1.3.0 lib/honeycomb/configuration.rb
honeycomb-beeline-1.2.0 lib/honeycomb/configuration.rb
honeycomb-beeline-1.1.1 lib/honeycomb/configuration.rb
honeycomb-beeline-1.1.0 lib/honeycomb/configuration.rb
honeycomb-beeline-1.0.1 lib/honeycomb/configuration.rb
honeycomb-beeline-1.0.0 lib/honeycomb/configuration.rb
honeycomb-beeline-1.0.0.pre.beta4 lib/honeycomb/configuration.rb
honeycomb-beeline-1.0.0.pre.beta3 lib/honeycomb/configuration.rb
honeycomb-beeline-1.0.0.pre.beta2 lib/honeycomb/configuration.rb