libhoney 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +28 -0
- data/lib/libhoney/client.rb +20 -1
- data/lib/libhoney/event.rb +1 -5
- data/lib/libhoney/mock_transmission.rb +26 -0
- data/lib/libhoney/transmission.rb +4 -0
- data/lib/libhoney/version.rb +1 -1
- data/lib/libhoney.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 930fb89e75aad3624d26e929b09d4b900a88df25ad4c0462eedd85ea5efe1091
|
4
|
+
data.tar.gz: 0f7584e0ca46508f3da2d74523c15126f78f230312c865c2facadcac49dcb187
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3990fcde2ad49d87eb9503ef89ca42cc7ab03c6c6ec2527bd1ec84062496a8e3c514e7b53c09ef5a278390f778afb807a3728617e0e00de89f1b7d0c1494285
|
7
|
+
data.tar.gz: 4bee236b58007911ad8c1e0ced9754bc127a1629aa330903c7a40ed8452d0d8c3274ed0e2b444ae04965137a50a72ce6198e9a278fbbb2a4af5fbccba60719f5
|
data/README.md
CHANGED
@@ -59,6 +59,34 @@ honeycomb.close
|
|
59
59
|
|
60
60
|
You can find a more complete example demonstrating usage in [`example/fact.rb`](example/fact.rb)
|
61
61
|
|
62
|
+
## Testing instrumented code
|
63
|
+
|
64
|
+
Once you've instrumented your code to send events to Honeycomb, you may want to
|
65
|
+
consider writing tests that verify your code is producing the events you expect,
|
66
|
+
annotating them with the right information, etc. That way, if your code changes
|
67
|
+
and breaks the instrumentation, you'll find out straight away, instead of at 3am
|
68
|
+
when you need that data available for debugging!
|
69
|
+
|
70
|
+
To support this use case, libhoney provides a
|
71
|
+
[`TestClient`](http://www.rubydoc.info/gems/libhoney/Libhoney/TestClient) which
|
72
|
+
you can swap in for the usual `Client`. Example usage:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
fakehoney = Libhoney::TestClient.new
|
76
|
+
|
77
|
+
my_app = MyApp.new(..., fakehoney, ...)
|
78
|
+
my_app.do_stuff
|
79
|
+
|
80
|
+
expect(fakehoney.events.size).to eq 3
|
81
|
+
|
82
|
+
first_event = fakehoney.events[0]
|
83
|
+
expect(first_event.data['hovercraft_contents']).to eq 'Eels'
|
84
|
+
```
|
85
|
+
|
86
|
+
For more detail see the docs for
|
87
|
+
[`TestClient`](http://www.rubydoc.info/gems/libhoney/Libhoney/TestClient) and
|
88
|
+
[`Event`](http://www.rubydoc.info/gems/libhoney/Libhoney/Event).
|
89
|
+
|
62
90
|
## Contributions
|
63
91
|
|
64
92
|
Features, bug fixes and other changes to libhoney are gladly accepted. Please
|
data/lib/libhoney/client.rb
CHANGED
@@ -53,12 +53,14 @@ module Libhoney
|
|
53
53
|
# @param dataset [String] the dataset you want
|
54
54
|
# @param sample_rate [Fixnum] cause libhoney to send 1 out of sampleRate events. overrides the libhoney instance's value.
|
55
55
|
# @param api_host [String] the base url to send events to
|
56
|
+
# @param transmission [Object] transport used to actually send events. If nil (the default), will be lazily initialized with a {TransmissionClient} on first event send.
|
56
57
|
# @param block_on_send [Boolean] if more than pending_work_capacity events are written, block sending further events
|
57
58
|
# @param block_on_responses [Boolean] if true, block if there is no thread reading from the response queue
|
58
59
|
def initialize(writekey: '',
|
59
60
|
dataset: '',
|
60
61
|
sample_rate: 1,
|
61
62
|
api_host: 'https://api.honeycomb.io/',
|
63
|
+
transmission: nil,
|
62
64
|
block_on_send: false,
|
63
65
|
block_on_responses: false,
|
64
66
|
max_batch_size: 50,
|
@@ -83,7 +85,7 @@ module Libhoney
|
|
83
85
|
@max_concurrent_batches = max_concurrent_batches
|
84
86
|
@pending_work_capacity = pending_work_capacity
|
85
87
|
@responses = SizedQueue.new(2 * @pending_work_capacity)
|
86
|
-
@tx =
|
88
|
+
@tx = transmission
|
87
89
|
@lock = Mutex.new
|
88
90
|
|
89
91
|
self
|
@@ -203,6 +205,23 @@ module Libhoney
|
|
203
205
|
def should_drop(sample_rate)
|
204
206
|
rand(1..sample_rate) != 1
|
205
207
|
end
|
208
|
+
end
|
206
209
|
|
210
|
+
# A client with the network stubbed out for testing purposes. Does not
|
211
|
+
# actually send any events to Honeycomb; instead, records events for later
|
212
|
+
# inspection.
|
213
|
+
#
|
214
|
+
# @note This class is intended for use in tests, for example if you want to
|
215
|
+
# verify what events your instrumented code is sending. Use in
|
216
|
+
# production is not recommended.
|
217
|
+
class TestClient < Client
|
218
|
+
def initialize(*args, **kwargs)
|
219
|
+
super(*args, transmission: MockTransmissionClient.new, **kwargs)
|
220
|
+
end
|
221
|
+
|
222
|
+
# @return [Array<Event>] the recorded events
|
223
|
+
def events
|
224
|
+
@tx.events
|
225
|
+
end
|
207
226
|
end
|
208
227
|
end
|
data/lib/libhoney/event.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Libhoney
|
2
2
|
##
|
3
3
|
# This is the event object that you can fill up with data.
|
4
|
-
# The data itself is a ruby hash.
|
5
4
|
class Event
|
6
5
|
attr_accessor :writekey, :dataset, :sample_rate, :api_host
|
7
6
|
attr_accessor :timestamp, :metadata
|
8
7
|
|
8
|
+
# @return [Hash<String=>any>] the fields in this event
|
9
9
|
attr_reader :data
|
10
10
|
|
11
11
|
# @api private
|
@@ -92,10 +92,6 @@ module Libhoney
|
|
92
92
|
# @return [self] this event.
|
93
93
|
def send_presampled
|
94
94
|
raise ArgumentError.new("No metrics added to event. Won't send empty event.") if self.data.length == 0
|
95
|
-
raise ArgumentError.new("No APIHost for Honeycomb. Can't send to the Great Unknown.") if self.api_host == ""
|
96
|
-
raise ArgumentError.new("No WriteKey specified. Can't send event.") if self.writekey == ""
|
97
|
-
raise ArgumentError.new("No Dataset for Honeycomb. Can't send datasetless.") if self.dataset == ""
|
98
|
-
|
99
95
|
@libhoney.send_event(self)
|
100
96
|
self
|
101
97
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Libhoney
|
2
|
+
# For testing use: a mock version of TransmissionClient that retains all
|
3
|
+
# events in an in-memory queue for inspection (and does not send them to
|
4
|
+
# Honeycomb, or perform any network activity).
|
5
|
+
#
|
6
|
+
# @note This class is intended for use in tests, for example if you want to
|
7
|
+
# verify what events your instrumented code is sending. Use in
|
8
|
+
# production is not recommended.
|
9
|
+
class MockTransmissionClient
|
10
|
+
def initialize
|
11
|
+
@events = []
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Array<Event>] the recorded events
|
15
|
+
attr_reader :events
|
16
|
+
|
17
|
+
# Records an event
|
18
|
+
def add(event)
|
19
|
+
@events.push(event)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Does nothing.
|
23
|
+
def close(drain)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -26,6 +26,10 @@ module Libhoney
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def add(event)
|
29
|
+
raise ArgumentError, "No APIHost for Honeycomb. Can't send to the Great Unknown." if event.api_host == ""
|
30
|
+
raise ArgumentError, "No WriteKey specified. Can't send event." if event.writekey == ""
|
31
|
+
raise ArgumentError, "No Dataset for Honeycomb. Can't send datasetless." if event.dataset == ""
|
32
|
+
|
29
33
|
begin
|
30
34
|
@send_queue.enq(event, !@block_on_send)
|
31
35
|
rescue ThreadError
|
data/lib/libhoney/version.rb
CHANGED
data/lib/libhoney.rb
CHANGED
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.
|
4
|
+
version: 1.4.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: 2017-
|
11
|
+
date: 2017-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/libhoney/builder.rb
|
128
128
|
- lib/libhoney/client.rb
|
129
129
|
- lib/libhoney/event.rb
|
130
|
+
- lib/libhoney/mock_transmission.rb
|
130
131
|
- lib/libhoney/response.rb
|
131
132
|
- lib/libhoney/transmission.rb
|
132
133
|
- lib/libhoney/version.rb
|
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
152
|
version: '0'
|
152
153
|
requirements: []
|
153
154
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.7.2
|
155
156
|
signing_key:
|
156
157
|
specification_version: 4
|
157
158
|
summary: send data to Honeycomb
|