honeycomb-rails 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5269a0de1a6d47dd7c0ff92bdd5e2a954369ad0f49b09ca5c23a7c3e1d4d0214
4
- data.tar.gz: 79a58361d5f1a334f9d58f48be31f13779d243130a7ea74951547baf4147f0c5
3
+ metadata.gz: a7cb5db4cd8ae4478d1cda742c05abc52cf47123c1990c5e41e398bd2db74a15
4
+ data.tar.gz: bc5beac5c64c75d6755a839717b9ac3a9e33a5b42c6fac948f4d4d15afd6910c
5
5
  SHA512:
6
- metadata.gz: 396f9cc14e318d1795a4883b54f1906a08692d98d6040219cf1726adb418fc4793c504859da5113e2a81f9fd18a12c89e2b8b87e2ef598d90714fbac61dddeee
7
- data.tar.gz: d472468f60e3d33fffa15b31b259edb1fdcbc0d08462a0eaf5853c61ec2cfae05b742134ab16e96ff061c0519c25c8cc1f6adfec304fdd68ce3d85fd84c434c2
6
+ metadata.gz: afc18e55a4563f1d8740f1cc7b328767ac6162ec7f95ce94eb745025f7c5e44856fef1bf1a75f448b88906d71c00dcc41a5376176113e2d719fd1cf2928744a4
7
+ data.tar.gz: d24b041b9aa4123cb0f4ab7fceb60594467aec3b576f332466986d0773cd6c2594b4912dd06506c48d3df31e2ca195fc0376dfe569f2061c7b119accff4a94f2
@@ -38,6 +38,11 @@ module HoneycombRails
38
38
  # about the current user.
39
39
  attr_accessor :record_user
40
40
 
41
+ # Override the default Libhoney::Client used to send events to Honeycomb.
42
+ # If this is specified, {#writekey} will be ignored.
43
+ # @api private
44
+ attr_accessor :client
45
+
41
46
  # Send request events to the Honeycomb dataset with this name (default:
42
47
  # 'rails'). Set to nil or an empty string to disable.
43
48
  attr_accessor :dataset
@@ -49,19 +54,48 @@ module HoneycombRails
49
54
  # The Honeycomb write key for your team (must be specified).
50
55
  attr_accessor :writekey
51
56
 
57
+ # @!attribute sample_rate
52
58
  # If set, determines how to record the sample rate for a given Honeycomb
53
59
  # event. (default: 1, do not sample)
54
60
  #
55
61
  # Valid values:
56
- # * Integer - sample Honeycomb events at a constant rate
57
- # * 1 or lower - disable sampling on this dataset; capture all events
58
- # * TODO: :rails - default Rails dynamic sampling?
62
+ # * Integer > 1 - sample Honeycomb events at a constant rate
63
+ # * 1 - disable sampling on this dataset; capture all events
64
+ #
65
+ # You can also pass a block, which will be called with the
66
+ # event type and the ActiveSupport::Notifications payload that was used to
67
+ # populate the Honeycomb event, and which should return a sample rate for
68
+ # the request or database query in question. For example, to sample
69
+ # successful (200) requests and read (SELECT) queries at 100:1 and all other
70
+ # requests at 1:1:
59
71
  #
60
- # You can also pass a Proc, which will be called with the
61
- # ActiveSupport::Notifications payload that was used to populate the
62
- # Honeycomb event, and which should return a sample rate for the request
63
- # in question.
64
- attr_accessor :sample_rate
72
+ # @example Dynamic sampling with a block
73
+ # config.sample_rate do |event_type, payload|
74
+ # case event_type
75
+ # when 'sql.active_record'
76
+ # if payload[:sql] =~ /^SELECT/
77
+ # 100
78
+ # else
79
+ # 1
80
+ # end
81
+ # when 'process_action.action_controller'
82
+ # if payload[:status] == 200
83
+ # 100
84
+ # else
85
+ # 1
86
+ # end
87
+ # end
88
+ # end
89
+
90
+ attr_writer :sample_rate
91
+
92
+ def sample_rate(&block)
93
+ if block
94
+ self.sample_rate = block
95
+ else
96
+ @sample_rate
97
+ end
98
+ end
65
99
 
66
100
  # If set to true, captures exception class name / message along with Rails
67
101
  # request events. (default: true)
@@ -5,11 +5,20 @@ module HoneycombRails
5
5
  def self.included(controller_class)
6
6
  super
7
7
 
8
- controller_class.before_action do
8
+ install_before_filter!(controller_class) do
9
9
  honeycomb_initialize
10
10
  end
11
11
  end
12
12
 
13
+ def self.install_before_filter!(controller_class, &block)
14
+ raise ArgumentError unless block_given?
15
+ if ::Rails::VERSION::MAJOR < 4
16
+ controller_class.before_filter(&block)
17
+ else
18
+ controller_class.before_action(&block)
19
+ end
20
+ end
21
+
13
22
  def honeycomb_initialize
14
23
  @honeycomb_metadata = {}
15
24
  end
@@ -19,15 +19,17 @@ module HoneycombRails
19
19
  config.after_initialize do
20
20
  HoneycombRails.config.logger ||= ::Rails.logger
21
21
 
22
- writekey = HoneycombRails.config.writekey
23
- if writekey.blank?
24
- HoneycombRails.config.logger.warn("No write key defined! (Check your config's `writekey` value in config/initializers/honeycomb.rb) No events will be sent to Honeycomb.")
22
+ @libhoney = HoneycombRails.config.client || begin
23
+ writekey = HoneycombRails.config.writekey
24
+ if writekey.blank?
25
+ HoneycombRails.config.logger.warn("No write key defined! (Check your config's `writekey` value in config/initializers/honeycomb.rb) No events will be sent to Honeycomb.")
26
+ end
27
+
28
+ Libhoney::Client.new(
29
+ writekey: writekey,
30
+ user_agent_addition: HoneycombRails::USER_AGENT_SUFFIX,
31
+ )
25
32
  end
26
-
27
- @libhoney = Libhoney::Client.new(
28
- writekey: writekey,
29
- user_agent_addition: HoneycombRails::USER_AGENT_SUFFIX,
30
- )
31
33
  end
32
34
 
33
35
  config.after_initialize do
@@ -1,3 +1,5 @@
1
+ require 'honeycomb-rails/subscribers/sampling'
2
+
1
3
  require 'active_support/core_ext/hash'
2
4
  require 'active_support/notifications'
3
5
  require 'rails'
@@ -5,6 +7,8 @@ require 'rails'
5
7
  module HoneycombRails
6
8
  module Subscribers
7
9
  class ActiveRecord
10
+ include Sampling
11
+
8
12
  def initialize(honeybuilder)
9
13
  @honeybuilder = honeybuilder
10
14
  end
@@ -34,7 +38,12 @@ module HoneycombRails
34
38
  # filters and silencers to trim down the noise.
35
39
  data[:local_stack] = Rails.backtrace_cleaner.clean(caller)
36
40
 
37
- @honeybuilder.send_now(data)
41
+ honeycomb_event = @honeybuilder.event
42
+ honeycomb_event.add(data)
43
+
44
+ sample_event_if_required(honeycomb_event, event)
45
+
46
+ honeycomb_event.send
38
47
  end
39
48
  end
40
49
  end
@@ -1,4 +1,5 @@
1
1
  require 'honeycomb-rails/constants'
2
+ require 'honeycomb-rails/subscribers/sampling'
2
3
 
3
4
  require 'active_support/core_ext/hash'
4
5
  require 'active_support/notifications'
@@ -6,6 +7,8 @@ require 'active_support/notifications'
6
7
  module HoneycombRails
7
8
  module Subscribers
8
9
  class ProcessAction
10
+ include Sampling
11
+
9
12
  def initialize(libhoney)
10
13
  @libhoney = libhoney
11
14
  end
@@ -24,6 +27,10 @@ module HoneycombRails
24
27
  :status, :db_runtime, :view_runtime,
25
28
  :exception, :exception_object)
26
29
 
30
+ if request_id = event.payload[:headers][:'action_dispatch.request_id']
31
+ data[:request_id] = request_id
32
+ end
33
+
27
34
  # Massage data to return "all" as the :format if not set
28
35
  if !data[:format] || data[:format] == "format:*/*"
29
36
  data[:format] = "all"
@@ -69,14 +76,7 @@ module HoneycombRails
69
76
  honeycomb_event = @libhoney.event
70
77
  honeycomb_event.add(data)
71
78
 
72
- case HoneycombRails.config.sample_rate
73
- when Proc
74
- honeycomb_event.sample_rate = HoneycombRails.config.sample_rate.call(event.payload)
75
- when Integer
76
- if HoneycombRails.config.sample_rate > 1
77
- honeycomb_event.sample_rate = HoneycombRails.config.sample_rate
78
- end
79
- end
79
+ sample_event_if_required(honeycomb_event, event)
80
80
 
81
81
  honeycomb_event.send
82
82
  end
@@ -0,0 +1,19 @@
1
+ module HoneycombRails
2
+ module Subscribers
3
+ module Sampling
4
+ def sample_event_if_required(honeycomb_event, notification_event)
5
+ case HoneycombRails.config.sample_rate
6
+ when Proc
7
+ honeycomb_event.sample_rate = HoneycombRails.config.sample_rate.call(
8
+ notification_event.name,
9
+ notification_event.payload,
10
+ )
11
+ when Integer
12
+ if HoneycombRails.config.sample_rate > 1
13
+ honeycomb_event.sample_rate = HoneycombRails.config.sample_rate
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,7 @@
1
1
  module HoneycombRails
2
2
  GEM_NAME = 'honeycomb-rails'
3
3
 
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.0'
5
5
 
6
6
  USER_AGENT_SUFFIX = "#{GEM_NAME}/#{VERSION}".freeze
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: honeycomb-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stokes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-04-18 00:00:00.000000000 Z
12
+ date: 2018-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: libhoney
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec-rails
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: yard
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +132,7 @@ files:
118
132
  - lib/honeycomb-rails/subscribers.rb
119
133
  - lib/honeycomb-rails/subscribers/active_record.rb
120
134
  - lib/honeycomb-rails/subscribers/process_action.rb
135
+ - lib/honeycomb-rails/subscribers/sampling.rb
121
136
  - lib/honeycomb-rails/version.rb
122
137
  homepage: https://github.com/honeycombio/honeycomb-rails
123
138
  licenses:
@@ -139,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
154
  version: '0'
140
155
  requirements: []
141
156
  rubyforge_project:
142
- rubygems_version: 2.7.6
157
+ rubygems_version: 2.7.7
143
158
  signing_key:
144
159
  specification_version: 4
145
160
  summary: Easily instrument your Rails apps with Honeycomb