Class: HoneycombRails::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/honeycomb-rails/config.rb

Overview

Configuration for the Honeycomb Rails integration.

Specify this at app initialization time via configure.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



6
7
8
9
10
11
12
13
14
# File 'lib/honeycomb-rails/config.rb', line 6

def initialize
  @dataset = 'rails'
  @db_dataset = 'active_record'
  @record_flash = true
  @record_user = :detect
  @capture_exceptions = true
  @capture_exception_backtraces = true
  @sample_rate = 1
end

Instance Attribute Details

#capture_exception_backtracesObject

If set to true, captures backtraces when capturing exception metadata. No-op if capture_exceptions is false. (default: true)



106
107
108
# File 'lib/honeycomb-rails/config.rb', line 106

def capture_exception_backtraces
  @capture_exception_backtraces
end

#capture_exceptionsObject

If set to true, captures exception class name / message along with Rails request events. (default: true)



102
103
104
# File 'lib/honeycomb-rails/config.rb', line 102

def capture_exceptions
  @capture_exceptions
end

#clientObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Override the default Libhoney::Client used to send events to Honeycomb. If this is specified, #writekey will be ignored.



44
45
46
# File 'lib/honeycomb-rails/config.rb', line 44

def client
  @client
end

#datasetObject

Send request events to the Honeycomb dataset with this name (default: ‘rails’). Set to nil or an empty string to disable.



48
49
50
# File 'lib/honeycomb-rails/config.rb', line 48

def dataset
  @dataset
end

#db_datasetObject

Send ActiveRecord query events to the Honeycomb dataset with this name (default: ‘active_record’). Set to nil or empty string to disable.



52
53
54
# File 'lib/honeycomb-rails/config.rb', line 52

def db_dataset
  @db_dataset
end

#loggerObject

If set, routes HoneycombRails-specific log output to this logger (defaults to Rails.logger)



25
26
27
# File 'lib/honeycomb-rails/config.rb', line 25

def logger
  @logger
end

#record_flash=(value) ⇒ Object (writeonly)

Whether to record flash messages (default: true).



17
18
19
# File 'lib/honeycomb-rails/config.rb', line 17

def record_flash=(value)
  @record_flash = value
end

#record_userObject

If set, determines how to record the current user during request processing (default: :detect). Set to nil or false to disable.

Valid values:

  • :devise - if your app uses Devise for authentication

  • :devise_api - if your app uses Devise for authentication in an ‘api’ namespace

  • :detect - autodetect how to determine the current user

  • nil, false - disable recording current user

You can also pass a Proc, which will be called with the current controller instance during each request, and which should return a hash of metadata about the current user.



39
40
41
# File 'lib/honeycomb-rails/config.rb', line 39

def record_user
  @record_user
end

#sample_rate(&block) ⇒ Object

If set, determines how to record the sample rate for a given Honeycomb event. (default: 1, do not sample)

Valid values:

  • Integer > 1 - sample Honeycomb events at a constant rate

  • 1 - disable sampling on this dataset; capture all events

You can also pass a block, which will be called with the event type and the ActiveSupport::Notifications payload that was used to populate the Honeycomb event, and which should return a sample rate for the request or database query in question. For example, to sample successful (200) requests and read (SELECT) queries at 100:1 and all other requests at 1:1:

Examples:

Dynamic sampling with a block

config.sample_rate do |event_type, payload|
  case event_type
  when 'sql.active_record'
    if payload[:sql] =~ /^SELECT/
      100
    else
      1
    end
  when 'process_action.action_controller'
    if payload[:status] == 200
      100
    else
      1
    end
  end
end


90
# File 'lib/honeycomb-rails/config.rb', line 90

attr_writer :sample_rate

#writekeyObject

The Honeycomb write key for your team (must be specified).



55
56
57
# File 'lib/honeycomb-rails/config.rb', line 55

def writekey
  @writekey
end

Instance Method Details

#record_flash?Boolean

Whether to record flash messages (default: true).

Returns:

  • (Boolean)


19
20
21
# File 'lib/honeycomb-rails/config.rb', line 19

def record_flash?
  !!@record_flash
end