Sha256: c73c94f414f5226e3efb3d42bd11b78e1b89eaa5114fb7da163b44ea699d8819

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require "libhoney"

require "honeycomb/beeline/version"
require "honeycomb/client"
require "honeycomb/trace"

# main module
module Honeycomb
  class << self
    attr_reader :client

    def configure
      Configuration.new.tap do |config|
        yield config
        @client = Honeycomb::Client.new(client: config.client,
                                        service_name: config.service_name)
        config.after_initialize(@client)
      end

      @client
    end

    def start_span(name:, &block)
      client.start_span(name: name, &block)
    end

    def load_integrations
      %i[faraday rack sinatra rails sequel active_support].each do |integration|
        begin
          require "honeycomb/integrations/#{integration}"
        rescue LoadError
        end
      end
    end
  end

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

    attr_writer :service_name, :client

    def initialize
      @write_key = ENV["HONEYCOMB_WRITEKEY"]
      @dataset = ENV["HONEYCOMB_DATASET"]
      @service_name = ENV["HONEYCOMB_SERVICE"]
      @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 || Libhoney::Client.new(options)
    end

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

Honeycomb.load_integrations unless ENV["HONEYCOMB_DISABLE_AUTOCONFIGURE"]

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
honeycomb-beeline-1.0.0.pre.alpha1 lib/honeycomb-beeline.rb