Class: Honeycomb::Configuration

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Configuration
Defined in:
lib/honeycomb/configuration.rb

Overview

Used to configure the Honeycomb client

Instance Attribute Summary collapse

Attributes included from ActiveSupport::Configuration

#notification_events

Instance Method Summary collapse

Methods included from ActiveSupport::Configuration

#active_support_handlers, #default_handler, #handle_notification_event, #on_notification_event

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



17
18
19
20
21
22
23
24
# File 'lib/honeycomb/configuration.rb', line 17

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

Instance Attribute Details

#api_hostObject

Returns the value of attribute api_host.



10
11
12
# File 'lib/honeycomb/configuration.rb', line 10

def api_host
  @api_host
end

#clientObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/honeycomb/configuration.rb', line 57

def client
  # memoized:
  # either the user has supplied a pre-configured Libhoney client
  @client ||=
    # or we'll create one and return it from here on
    if debug
      Libhoney::LogClient.new
    else
      validate_options
      Libhoney::Client.new(**libhoney_client_options)
    end
end

#datasetObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/honeycomb/configuration.rb', line 37

def dataset
  return @dataset if classic?
  return "unknown_service" if service_name.nil?

  stripped_service_name = service_name.strip

  warn("found extra whitespace in service name") if stripped_service_name != service_name

  if stripped_service_name.empty? || stripped_service_name.start_with?("unknown_service")
    # don't use process name in dataset
    "unknown_service"
  else
    stripped_service_name
  end
end

#debugObject

Returns the value of attribute debug.



10
11
12
# File 'lib/honeycomb/configuration.rb', line 10

def debug
  @debug
end

#error_backtrace_limitObject

Returns the value of attribute error_backtrace_limit.



15
16
17
# File 'lib/honeycomb/configuration.rb', line 15

def error_backtrace_limit
  @error_backtrace_limit
end

#host_nameObject



74
75
76
77
# File 'lib/honeycomb/configuration.rb', line 74

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

#service_nameObject



30
31
32
33
34
35
# File 'lib/honeycomb/configuration.rb', line 30

def service_name
  return @service_name if service_name_given?
  return @dataset if classic?

  "unknown_service:" + $PROGRAM_NAME.split("/").last
end

#write_keyObject

Returns the value of attribute write_key.



10
11
12
# File 'lib/honeycomb/configuration.rb', line 10

def write_key
  @write_key
end

Instance Method Details

#after_initialize(client) ⇒ Object



70
71
72
# File 'lib/honeycomb/configuration.rb', line 70

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

#classic?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/honeycomb/configuration.rb', line 26

def classic?
  Libhoney.classic_api_key?(@write_key)
end

#http_trace_parser_hook(&hook) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/honeycomb/configuration.rb', line 95

def http_trace_parser_hook(&hook)
  if block_given?
    @http_trace_parser_hook = hook
  elsif @http_trace_parser_hook
    @http_trace_parser_hook
  elsif classic?
    DefaultPropagation::UnmarshalTraceContext.method(:parse_rack_env)
  else
    # by default we try to parse incoming honeycomb traces
    DefaultModernPropagation::UnmarshalTraceContext.method(:parse_rack_env)
  end
end

#http_trace_propagation_hook(&hook) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/honeycomb/configuration.rb', line 108

def http_trace_propagation_hook(&hook)
  if block_given?
    @http_trace_propagation_hook = hook
  elsif @http_trace_propagation_hook
    @http_trace_propagation_hook
  elsif classic?
    HoneycombPropagation::MarshalTraceContext.method(:parse_faraday_env)
  else
    # by default we send outgoing honeycomb trace headers
    HoneycombModernPropagation::MarshalTraceContext.method(:parse_faraday_env)
  end
end

#presend_hook(&hook) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/honeycomb/configuration.rb', line 79

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

#sample_hook(&hook) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/honeycomb/configuration.rb', line 87

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