libhoney 1.11.0 → 1.12.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: dd29a10e412de6aef7a21988cdf51e253dbfdfa4e3c53a7161f617b27dbcc81a
4
- data.tar.gz: 25c577fcda6470dd420a292a08cec6632e18889ac1a0ac3bc82c166258860216
3
+ metadata.gz: aaff0cc763c16bc795c21403f744d3a5e6773d2503c338d9f161fc1d0ef01341
4
+ data.tar.gz: e4f44b656d422207f25441c867519118f1f4557718c0c12e25f198e4871052b5
5
5
  SHA512:
6
- metadata.gz: 85133ade7a0a6cb208ed0912a6a001fe79d0f8e6c35b7d084512e7e57ac47df94f9181e8428df535f620f9bc4ad9333582c945a5aa72f8e9a0de35a976ce7460
7
- data.tar.gz: bf7c51ec4d23ae23aaed304c670aed2b08c0f7d51f6c8c7a6c139161f20d70e5c5691b143f00dbc8af5c3b6b075e894a9836e9316e4fce0e7f592527a74b11e7
6
+ metadata.gz: 17701619551ad22950ffe421c9a98a4546e00ea8447ee52b22c19d21af9adc342951eed7ee0046c0ca8459d63ffc90ff64cb3759e003971681bb3b567debd9fe
7
+ data.tar.gz: c701b48807d76fcef732eaa47e7059ef71cfeaa40693bc039b094968b12407f26d9f6647d3f204a4c2feeed551ca07840c9a1d0850b8ab755eeeb0fdff3675b7
data/README.md CHANGED
@@ -7,9 +7,7 @@ Requires Ruby 2.2 or greater.
7
7
  - [Usage and Examples](https://docs.honeycomb.io/sdk/ruby/)
8
8
  - [API Reference](https://www.rubydoc.info/gems/libhoney)
9
9
 
10
- For tracing support and automatic instrumentation of Sinatra, Rack, ActiveRecord, and other frameworks, check out our [Beeline for Ruby](https://github.com/honeycombio/beeline-ruby).
11
-
12
- For automatic instrumentation of Ruby on Rails, check out our [Rails integration](https://github.com/honeycombio/honeycomb-rails).
10
+ For tracing support and automatic instrumentation of Rails, Sinatra, Rack, ActiveRecord, and other frameworks, check out our [Beeline for Ruby](https://github.com/honeycombio/beeline-ruby).
13
11
 
14
12
  ## Contributions
15
13
 
data/example/factorial.rb CHANGED
@@ -30,49 +30,43 @@ def run_factorial(low, high, libh_builder)
30
30
  end
31
31
  end
32
32
 
33
- def read_responses(response_queue)
34
- loop do
35
- response = response_queue.pop
36
- break if response.nil?
37
-
38
- puts "Sent: Event with metadata #{response.metadata} in #{response.duration * 1000}ms."
39
- puts "Got: Response code #{response.status_code}"
40
- puts
41
- end
42
- end
43
-
44
33
  libhoney = Libhoney::Client.new(writekey: writekey,
45
- dataset: dataset,
46
- max_concurrent_batches: 1)
47
-
48
- responses = libhoney.responses
34
+ dataset: dataset)
49
35
 
50
36
  Thread.new do
51
37
  begin
52
- # attach fields to top-level instance
53
- libhoney.add_field('version', '3.4.5')
54
-
55
- a_proc = proc { Thread.list.select { |thread| thread.status == 'run' }.count }
56
- libhoney.add_dynamic_field('num_threads', a_proc)
57
-
58
- event = libhoney.event
59
- event.metadata = { fn: 'work_thread' }
60
- event.add_field('start_time', Time.now.iso8601(3))
61
- event.with_timer 'run_fact_low_dur_ms' do
62
- run_factorial(1, 20, libhoney.builder(range: 'low'))
63
- end
64
- event.with_timer 'run_fact_high_dur_ms' do
65
- run_factorial(31, 40, libhoney.builder(range: 'high'))
38
+ loop do
39
+ response = libhoney.responses.pop
40
+ break if response.nil?
41
+
42
+ puts "Sent: Event with metadata #{response.metadata} in #{response.duration * 1000}ms."
43
+ puts "Got: Response code #{response.status_code}"
44
+ puts " #{response.error.class}: #{response.error}" if response.error
45
+ puts
66
46
  end
67
- event.add_field('end_time', Time.now.iso8601(3))
68
- # sends an event with "version", "num_threads", "start_time", "end_time",
69
- # "run_fact_low_dur_ms", "run_fact_high_dur_ms"
70
- event.send
71
-
72
- libhoney.close
73
47
  rescue StandardError => e
74
- puts e
48
+ puts "#{e.class} in response reader thread: #{e}"
75
49
  end
76
50
  end
77
51
 
78
- read_responses(responses)
52
+ # attach fields to top-level instance
53
+ libhoney.add_field('version', '3.4.5')
54
+
55
+ a_proc = proc { Thread.list.select { |thread| thread.status == 'run' }.count }
56
+ libhoney.add_dynamic_field('num_threads', a_proc)
57
+
58
+ event = libhoney.event
59
+ event.metadata = { fn: 'work_thread' }
60
+ event.add_field('start_time', Time.now.iso8601(3))
61
+ event.with_timer 'run_fact_low_dur_ms' do
62
+ run_factorial(1, 20, libhoney.builder(range: 'low'))
63
+ end
64
+ event.with_timer 'run_fact_high_dur_ms' do
65
+ run_factorial(31, 40, libhoney.builder(range: 'high'))
66
+ end
67
+ event.add_field('end_time', Time.now.iso8601(3))
68
+ # sends an event with "version", "num_threads", "start_time", "end_time",
69
+ # "run_fact_low_dur_ms", "run_fact_high_dur_ms"
70
+ event.send
71
+
72
+ libhoney.close
@@ -29,38 +29,47 @@ end
29
29
  module Libhoney
30
30
  ##
31
31
  # This is a library to allow you to send events to Honeycomb from within your
32
- # ruby application.
32
+ # Ruby application.
33
33
  #
34
- # Example:
34
+ # @example Send a simple event
35
35
  # require 'libhoney'
36
- # honey = Libhoney.new(writekey, dataset, url, sample_rate, num_workers)
37
- # event = honey.event
38
- # event.add({'pglatency' => 100})
39
- # honey.send(event)
40
- # <repeat creating and sending events until your program is finished>
36
+ # honey = Libhoney.new(writekey, dataset, sample_rate)
37
+ #
38
+ # evt = honey.event
39
+ # evt.add(pglatency: 100)
40
+ # honey.send(evt)
41
+ #
42
+ # # repeat creating and sending events until your program is finished
43
+ #
41
44
  # honey.close
42
45
  #
43
- # Arguments:
44
- # * *writekey* is the key to use the Honeycomb service (required)
45
- # * *dataset* is the dataset to write into (required)
46
- # * *sample_rate* is how many samples you want to keep. IE: 1 means you want 1 out of 1 samples kept, or all of them. 10 means you want 1 out of 10 samples kept. And so on.
47
- # * *url* is the url to connect to Honeycomb
48
- # * *num_workers* is the number of threads working on the queue of events you are generating
46
+ # @example Override the default timestamp on an event
47
+ # one_hour_ago = Time.now - 3600
49
48
  #
50
- # Note that by default, the max queue size is 1000. If the queue gets bigger than that, we start dropping events.
49
+ # evt = libhoney.event
50
+ # evt.add_fields(useful_fields)
51
+ # evt.timestamp = one_hour_ago
52
+ # evt.send
51
53
  #
52
54
  class Client
53
55
  API_HOST = 'https://api.honeycomb.io/'.freeze
54
56
 
55
57
  # Instantiates libhoney and prepares it to send events to Honeycomb.
56
58
  #
57
- # @param writekey [String] the write key from your honeycomb team (required)
58
- # @param dataset [String] the dataset you want (required)
59
- # @param sample_rate [Fixnum] cause libhoney to send 1 out of sampleRate events. overrides the libhoney instance's value.
60
- # @param api_host [String] the base url to send events to
59
+ # @param writekey [String] the Honeycomb API key with which to authenticate
60
+ # this request (required)
61
+ # @param dataset [String] the Honeycomb dataset into which to send events (required)
62
+ # @param sample_rate [Fixnum] cause +libhoney+ to send 1 out of +sample_rate+ events.
63
+ # overrides the libhoney instance's value. (e.g. setting this to +10+ will result in
64
+ # a 1-in-10 chance of it being successfully emitted to Honeycomb, and the
65
+ # Honeycomb query engine will interpret it as representative of 10 events)
66
+ # @param api_host [String] defaults to +API_HOST+, override to change the
67
+ # destination for these Honeycomb events.
61
68
  # @param transmission [Object] transport used to actually send events. If nil (the default), will be lazily initialized with a {TransmissionClient} on first event send.
62
69
  # @param block_on_send [Boolean] if more than pending_work_capacity events are written, block sending further events
63
70
  # @param block_on_responses [Boolean] if true, block if there is no thread reading from the response queue
71
+ # @param pending_work_capacity [Fixnum] defaults to 1000. If the queue of
72
+ # pending events exceeds 1000, this client will start dropping events.
64
73
  def initialize(writekey: nil,
65
74
  dataset: nil,
66
75
  sample_rate: 1,
@@ -205,14 +214,14 @@ module Libhoney
205
214
  def send_event(event)
206
215
  @lock.synchronize do
207
216
  transmission_client_params = {
208
- max_batch_size: @max_batch_size,
209
- send_frequency: @send_frequency,
217
+ max_batch_size: @max_batch_size,
218
+ send_frequency: @send_frequency,
210
219
  max_concurrent_batches: @max_concurrent_batches,
211
- pending_work_capacity: @pending_work_capacity,
212
- responses: @responses,
213
- block_on_send: @block_on_send,
214
- block_on_responses: @block_on_responses,
215
- user_agent_addition: @user_agent_addition
220
+ pending_work_capacity: @pending_work_capacity,
221
+ responses: @responses,
222
+ block_on_send: @block_on_send,
223
+ block_on_responses: @block_on_responses,
224
+ user_agent_addition: @user_agent_addition
216
225
  }
217
226
 
218
227
  @transmission ||= TransmissionClient.new(transmission_client_params)
@@ -1,11 +1,44 @@
1
1
  module Libhoney
2
- ##
3
2
  # This is the event object that you can fill up with data.
3
+ #
4
+ # @example Override the default timestamp on an event
5
+ # evt = libhoney.event
6
+ # evt.add_fields(useful_fields)
7
+ # evt.timestamp = Time.now
8
+ # evt.send
9
+ #
4
10
  class Event
5
- attr_accessor :writekey, :dataset, :sample_rate, :api_host
6
- attr_accessor :timestamp, :metadata
11
+ # @return [String] the Honeycomb API key with which to authenticate this
12
+ # request
13
+ attr_accessor :writekey
7
14
 
8
- # @return [Hash<String=>any>] the fields in this event
15
+ # @return [String] the Honeycomb dataset this event is destined for
16
+ # (defaults to the +Builder+'s +dataset+, which in turn defaults to the
17
+ # +Client+'s +dataset+)
18
+ attr_accessor :dataset
19
+
20
+ # @return [Fixnum] Set this attribute to indicate that it represents
21
+ # +sample_rate+ number of events (e.g. setting this to +10+ will result in
22
+ # a 1-in-10 chance of it being successfully emitted to Honeycomb, and the
23
+ # Honeycomb query engine will interpret it as representative of 10 events)
24
+ attr_accessor :sample_rate
25
+
26
+ # @return [String] Set this attribute in order to override the destination
27
+ # of these Honeycomb events (defaults to +Client::API_HOST+).
28
+ attr_accessor :api_host
29
+
30
+ # @return [Object] Set this attribute to any +Object+ you might need to
31
+ # identify this Event as it is returned to the responses queue (e.g. tag
32
+ # an Event with an internal ID in order to retry something specific on
33
+ # failure).
34
+ attr_accessor :metadata
35
+
36
+ # @return [Time] Set this attribute in order to override the timestamp
37
+ # associated with the event (defaults to the +Time.now+ at +Event+
38
+ # creation)
39
+ attr_accessor :timestamp
40
+
41
+ # @return [Hash<String=>any>] the fields added to this event
9
42
  attr_reader :data
10
43
 
11
44
  # @api private
@@ -71,7 +104,7 @@ module Libhoney
71
104
  self
72
105
  end
73
106
 
74
- # sends this event to honeycomb
107
+ # sends this event to Honeycomb
75
108
  #
76
109
  # @return [self] this event.
77
110
  def send
@@ -84,7 +117,7 @@ module Libhoney
84
117
  send_presampled
85
118
  end
86
119
 
87
- # sends a presampled event to honeycomb
120
+ # sends a presampled event to Honeycomb
88
121
  #
89
122
  # @return [self] this event.
90
123
  def send_presampled
@@ -48,7 +48,7 @@ module Libhoney
48
48
  h[api_host] = HTTP.timeout(connect: @send_timeout, write: @send_timeout, read: @send_timeout)
49
49
  .persistent(api_host)
50
50
  .headers(
51
- 'User-Agent' => @user_agent,
51
+ 'User-Agent' => @user_agent,
52
52
  'Content-Type' => 'application/json'
53
53
  )
54
54
  end
@@ -67,9 +67,9 @@ module Libhoney
67
67
  resp = http.post(url,
68
68
  json: event.data,
69
69
  headers: {
70
- 'X-Honeycomb-Team' => event.writekey,
70
+ 'X-Honeycomb-Team' => event.writekey,
71
71
  'X-Honeycomb-SampleRate' => event.sample_rate,
72
- 'X-Event-Time' => event.timestamp.iso8601(3)
72
+ 'X-Event-Time' => event.timestamp.iso8601(3)
73
73
  })
74
74
 
75
75
  # "You must consume response before sending next request via persistent connection"
@@ -1,3 +1,3 @@
1
1
  module Libhoney
2
- VERSION = '1.11.0'.freeze
2
+ VERSION = '1.12.0'.freeze
3
3
  end
data/libhoney.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.required_ruby_version = '>= 2.2.0'
24
24
 
25
25
  spec.add_development_dependency 'bump', '~> 0.5'
26
- spec.add_development_dependency 'bundler', '~> 1.7'
26
+ spec.add_development_dependency 'bundler'
27
27
  spec.add_development_dependency 'minitest', '~> 5.0'
28
28
  spec.add_development_dependency 'rake', '~> 12.3'
29
29
  spec.add_development_dependency 'rubocop'
@@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'yard'
32
32
  spec.add_development_dependency 'yardstick', '~> 0.9'
33
33
  spec.add_dependency 'addressable', '~> 2.0'
34
- spec.add_dependency 'http', '>= 2.0', '< 4.0'
34
+ spec.add_dependency 'http', '>= 2.0', '< 5.0'
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libhoney
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Honeycomb.io Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-09 00:00:00.000000000 Z
11
+ date: 2019-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.7'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.7'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -145,7 +145,7 @@ dependencies:
145
145
  version: '2.0'
146
146
  - - "<"
147
147
  - !ruby/object:Gem::Version
148
- version: '4.0'
148
+ version: '5.0'
149
149
  type: :runtime
150
150
  prerelease: false
151
151
  version_requirements: !ruby/object:Gem::Requirement
@@ -155,7 +155,7 @@ dependencies:
155
155
  version: '2.0'
156
156
  - - "<"
157
157
  - !ruby/object:Gem::Version
158
- version: '4.0'
158
+ version: '5.0'
159
159
  description: Ruby gem for sending data to Honeycomb
160
160
  email: support@honeycomb.io
161
161
  executables: []
@@ -206,8 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  - !ruby/object:Gem::Version
207
207
  version: '0'
208
208
  requirements: []
209
- rubyforge_project:
210
- rubygems_version: 2.7.7
209
+ rubygems_version: 3.0.2
211
210
  signing_key:
212
211
  specification_version: 4
213
212
  summary: send data to Honeycomb