libhoney 1.14.0 → 1.14.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acad70fa5327549aaf1faca4fff6eeab79cdc72e7bab0cd3b6eb44fad49f2333
4
- data.tar.gz: 15fb1bdfaa6770ebe836764217a24f7f4410a38096409b7c3c64b775b4116349
3
+ metadata.gz: 02c56fa15226ad661c0d1a4e3d2f461a7f0037f0b1b1abe536d88592e998974b
4
+ data.tar.gz: f2b08f84d02ada29ee8d546a7afb6c95a911e717ee3e799c7682715b018b13f1
5
5
  SHA512:
6
- metadata.gz: e7a813d6e5b8a0f25f70f3e978a9b9a42e169f62d9b740829e784cf4f92c48531800fc93b69aa8f1aee4f6acebef0f648405db66418ca38e39c46042d02214d8
7
- data.tar.gz: 4d764b9c4bfb0b244bb5bf97275730b77c5e70d7720bfeac2cac39ae5d2a858b9fe5ed935379a08ee77a827b29262f787c9fd8ad1ae5ae529efa20fa8a03626e
6
+ metadata.gz: b9d152b6ec888487e465e3e2dab280859104c73be09ff600983999896db866e050a0047348008042d1a08bda2d96921236d0720b44ba2a420662d4cd06bba7ff
7
+ data.tar.gz: a95954263471061d71ad2b367bb515561a124e9ae8bc25096343dc992897b414ffeaa5a8a5612da44e697ff38fb2cb5390f46dd1d184861c2926ec65fb978fb7
@@ -2,6 +2,13 @@ version: 2.0
2
2
 
3
3
  test_steps: &test_steps
4
4
  - checkout
5
+ - run:
6
+ name: Force Bundler Version
7
+ command: |
8
+ sudo gem update --system
9
+ echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
10
+ source $BASH_ENV
11
+ gem install bundler
5
12
  - restore_cache:
6
13
  keys:
7
14
  - v1-dependencies-{{ checksum "Gemfile.lock" }}
@@ -45,10 +52,14 @@ jobs:
45
52
  docker:
46
53
  - image: circleci/ruby:2.6
47
54
  steps: *test_steps
55
+ ruby-2.7:
56
+ docker:
57
+ - image: circleci/ruby:2.7
58
+ steps: *test_steps
48
59
  publish:
49
60
  docker:
50
61
  # Just randomly pick one recent ruby version
51
- - image: circleci/ruby:2.6
62
+ - image: circleci/ruby:2.7
52
63
  working_directory: ~/repo
53
64
  steps:
54
65
  - checkout
@@ -63,18 +74,34 @@ jobs:
63
74
 
64
75
  workflows:
65
76
  version: 2
77
+ nightly:
78
+ triggers:
79
+ - schedule:
80
+ cron: "0 0 * * *"
81
+ filters:
82
+ branches:
83
+ only:
84
+ - main
85
+ jobs:
86
+ - ruby-2.3: *tag_filters
87
+ - ruby-2.4: *tag_filters
88
+ - ruby-2.5: *tag_filters
89
+ - ruby-2.6: *tag_filters
90
+ - ruby-2.7: *tag_filters
66
91
  build:
67
92
  jobs:
68
93
  - ruby-2.3: *tag_filters
69
94
  - ruby-2.4: *tag_filters
70
95
  - ruby-2.5: *tag_filters
71
96
  - ruby-2.6: *tag_filters
97
+ - ruby-2.7: *tag_filters
72
98
  - publish:
73
99
  requires:
74
100
  - ruby-2.3
75
101
  - ruby-2.4
76
102
  - ruby-2.5
77
103
  - ruby-2.6
104
+ - ruby-2.7
78
105
  filters:
79
106
  tags:
80
107
  only: /^v.*/
@@ -0,0 +1,5 @@
1
+ # Code owners file.
2
+ # This file controls who is tagged for review for any given pull request.
3
+
4
+ # For anything not explicitly taken by someone else:
5
+ * @honeycombio/integrations-team @martin308
@@ -19,7 +19,7 @@ Metrics/ClassLength:
19
19
  - test/*
20
20
 
21
21
  Metrics/MethodLength:
22
- Max: 25
22
+ Max: 40
23
23
  Exclude:
24
24
  - lib/libhoney/transmission.rb
25
25
  - test/*
@@ -14,17 +14,17 @@ Lint/HandleExceptions:
14
14
 
15
15
  # Offense count: 7
16
16
  Metrics/AbcSize:
17
- Max: 35
17
+ Max: 40
18
18
 
19
19
  # Offense count: 1
20
20
  # Configuration parameters: CountComments, ExcludedMethods.
21
21
  # ExcludedMethods: refine
22
22
  Metrics/BlockLength:
23
- Max: 27
23
+ Max: 30
24
24
 
25
25
  # Offense count: 2
26
26
  Metrics/CyclomaticComplexity:
27
- Max: 8
27
+ Max: 12
28
28
 
29
29
  # Offense count: 2
30
30
  # Configuration parameters: CountKeywordArgs.
@@ -33,4 +33,4 @@ Metrics/ParameterLists:
33
33
 
34
34
  # Offense count: 1
35
35
  Metrics/PerceivedComplexity:
36
- Max: 8
36
+ Max: 10
@@ -1,42 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- libhoney (1.14.0)
4
+ libhoney (1.14.5)
5
5
  addressable (~> 2.0)
6
6
  http (>= 2.0, < 5.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.6.0)
12
- public_suffix (>= 2.0.2, < 4.0)
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
13
  ast (2.4.0)
14
- backports (3.15.0)
14
+ backports (3.16.0)
15
15
  bump (0.8.0)
16
16
  crack (0.4.3)
17
17
  safe_yaml (~> 1.0.0)
18
18
  domain_name (0.5.20190701)
19
19
  unf (>= 0.0.5, < 1.0.0)
20
+ ffi (1.13.1)
21
+ ffi-compiler (1.0.1)
22
+ ffi (>= 1.0.0)
23
+ rake
20
24
  hashdiff (1.0.0)
21
- http (4.1.1)
25
+ http (4.4.1)
22
26
  addressable (~> 2.3)
23
27
  http-cookie (~> 1.0)
24
- http-form_data (~> 2.0)
25
- http_parser.rb (~> 0.6.0)
28
+ http-form_data (~> 2.2)
29
+ http-parser (~> 1.2.0)
26
30
  http-cookie (1.0.3)
27
31
  domain_name (~> 0.5)
28
- http-form_data (2.1.1)
29
- http_parser.rb (0.6.0)
30
- jaro_winkler (1.5.3)
31
- minitest (5.11.3)
32
- multi_json (1.13.1)
33
- mustermann (1.0.3)
34
- parallel (1.17.0)
35
- parser (2.6.3.0)
32
+ http-form_data (2.3.0)
33
+ http-parser (1.2.1)
34
+ ffi-compiler (>= 1.0, < 2.0)
35
+ jaro_winkler (1.5.4)
36
+ minitest (5.14.0)
37
+ multi_json (1.14.1)
38
+ mustermann (1.1.1)
39
+ ruby2_keywords (~> 0.0.1)
40
+ parallel (1.19.1)
41
+ parser (2.7.0.2)
36
42
  ast (~> 2.4.0)
37
- public_suffix (3.1.1)
38
- rack (2.0.7)
39
- rack-protection (2.0.5)
43
+ public_suffix (4.0.3)
44
+ rack (2.1.4)
45
+ rack-protection (2.0.8.1)
40
46
  rack
41
47
  rainbow (3.0.0)
42
48
  rake (12.3.3)
@@ -48,30 +54,31 @@ GEM
48
54
  ruby-progressbar (~> 1.7)
49
55
  unicode-display_width (>= 1.4.0, < 1.6)
50
56
  ruby-progressbar (1.10.1)
57
+ ruby2_keywords (0.0.2)
51
58
  safe_yaml (1.0.5)
52
- sinatra (2.0.5)
59
+ sinatra (2.0.8.1)
53
60
  mustermann (~> 1.0)
54
61
  rack (~> 2.0)
55
- rack-protection (= 2.0.5)
62
+ rack-protection (= 2.0.8.1)
56
63
  tilt (~> 2.0)
57
- sinatra-contrib (2.0.5)
64
+ sinatra-contrib (2.0.8.1)
58
65
  backports (>= 2.8.2)
59
66
  multi_json
60
67
  mustermann (~> 1.0)
61
- rack-protection (= 2.0.5)
62
- sinatra (= 2.0.5)
63
- tilt (>= 1.3, < 3)
68
+ rack-protection (= 2.0.8.1)
69
+ sinatra (= 2.0.8.1)
70
+ tilt (~> 2.0)
64
71
  spy (1.0.0)
65
- tilt (2.0.9)
72
+ tilt (2.0.10)
66
73
  unf (0.1.4)
67
74
  unf_ext
68
- unf_ext (0.0.7.6)
75
+ unf_ext (0.0.7.7)
69
76
  unicode-display_width (1.5.0)
70
- webmock (3.6.2)
77
+ webmock (3.8.1)
71
78
  addressable (>= 2.3.6)
72
79
  crack (>= 0.3.2)
73
80
  hashdiff (>= 0.4.0, < 2.0.0)
74
- yard (0.9.20)
81
+ yard (0.9.24)
75
82
  yardstick (0.9.9)
76
83
  yard (~> 0.8, >= 0.8.7.2)
77
84
 
@@ -93,4 +100,4 @@ DEPENDENCIES
93
100
  yardstick (~> 0.9)
94
101
 
95
102
  BUNDLED WITH
96
- 1.17.3
103
+ 2.1.4
@@ -0,0 +1,62 @@
1
+ module Libhoney
2
+ module Cleaner
3
+ ENCODING_OPTIONS = { invalid: :replace, undef: :replace }.freeze
4
+ RECURSION = '[RECURSION]'.freeze
5
+ RAISED = '[RAISED]'.freeze
6
+
7
+ # Cleans an object for converting to JSON. Checks for recursion,
8
+ # exceptions generated, and non UTF8 encoded strings.
9
+ # @param data the data to clean
10
+ # @param seen [Hash] used to check for recursion
11
+ # @return the cleaned object
12
+ def clean_data(data, seen = {})
13
+ return nil if data.nil?
14
+
15
+ # check for recursion here, by tracking all of the potentially nested
16
+ # objects that we have seen before.
17
+ protection = case data
18
+ when Hash, Array, Set
19
+ # bail here if we have already seen this object
20
+ return seen[data] if seen[data]
21
+
22
+ seen[data] = RECURSION
23
+ end
24
+
25
+ value = case data
26
+ when Hash
27
+ clean_hash = {}
28
+ data.each do |key, val|
29
+ clean_hash[key] = clean_data(val, seen)
30
+ end
31
+ clean_hash
32
+ when Array, Set
33
+ data.map do |element|
34
+ clean_data(element, seen)
35
+ end
36
+ when Numeric, TrueClass, FalseClass
37
+ data
38
+ when String
39
+ clean_string(data)
40
+ else
41
+ str = begin
42
+ data.to_s
43
+ rescue StandardError
44
+ RAISED
45
+ end
46
+ clean_string(str)
47
+ end
48
+
49
+ seen[data] = value if protection
50
+ value
51
+ end
52
+
53
+ # Converts a string to UTF8 encoding if required using the ENCODING_OPTIONS
54
+ # @param str [String] the string to convert
55
+ # @return [String] the UTF8 encoded string
56
+ def clean_string(str)
57
+ return str if str.encoding == Encoding::UTF_8 && str.valid_encoding?
58
+
59
+ str.encode(Encoding::UTF_8, **ENCODING_OPTIONS)
60
+ end
61
+ end
62
+ end
@@ -121,8 +121,6 @@ module Libhoney
121
121
  #
122
122
  # @return [self] this event.
123
123
  def send_presampled
124
- raise ArgumentError, "No metrics added to event. Won't send empty event." if data.empty?
125
-
126
124
  @libhoney.send_event(self)
127
125
  self
128
126
  end
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'libhoney/cleaner'
2
3
 
3
4
  module Libhoney
4
5
  # For debugging use: a mock version of TransmissionClient that simply prints
@@ -9,6 +10,8 @@ module Libhoney
9
10
  # to verify what events your instrumented code is sending. Use in
10
11
  # production is not recommended.
11
12
  class LogTransmissionClient
13
+ include Cleaner
14
+
12
15
  def initialize(output:, verbose: false)
13
16
  @output = output
14
17
  @verbose = verbose
@@ -21,7 +24,9 @@ module Libhoney
21
24
  metadata << " (sample rate: #{event.sample_rate})" if event.sample_rate != 1
22
25
  @output.print("#{metadata} | ")
23
26
  end
24
- @output.puts(event.data.to_json)
27
+ clean_data(event.data).tap do |data|
28
+ @output.puts(data.to_json)
29
+ end
25
30
  end
26
31
 
27
32
  # Flushes the output (but does not close it)
@@ -1,10 +1,13 @@
1
1
  require 'json'
2
2
  require 'timeout'
3
3
  require 'libhoney/response'
4
+ require 'libhoney/cleaner'
4
5
 
5
6
  module Libhoney
6
7
  # @api private
7
8
  class TransmissionClient
9
+ include Cleaner
10
+
8
11
  def initialize(max_batch_size: 50,
9
12
  send_frequency: 100,
10
13
  max_concurrent_batches: 10,
@@ -37,10 +40,6 @@ module Libhoney
37
40
  end
38
41
 
39
42
  def add(event)
40
- raise ArgumentError, "No APIHost for Honeycomb. Can't send to the Great Unknown." if event.api_host == ''
41
- raise ArgumentError, "No WriteKey specified. Can't send event." if event.writekey == ''
42
- raise ArgumentError, "No Dataset for Honeycomb. Can't send datasetless." if event.dataset == ''
43
-
44
43
  begin
45
44
  @batch_queue.enq(event, !@block_on_send)
46
45
  rescue ThreadError
@@ -63,6 +62,7 @@ module Libhoney
63
62
  begin
64
63
  http = http_clients[api_host]
65
64
  body = serialize_batch(batch)
65
+
66
66
  next if body.nil?
67
67
 
68
68
  headers = {
@@ -135,9 +135,11 @@ module Libhoney
135
135
 
136
136
  loop do
137
137
  begin
138
- while (event = Timeout.timeout(@send_frequency) { @batch_queue.pop })
139
- key = [event.api_host, event.writekey, event.dataset]
140
- batched_events[key] << event
138
+ Thread.handle_interrupt(Timeout::Error => :on_blocking) do
139
+ while (event = Timeout.timeout(@send_frequency) { @batch_queue.pop })
140
+ key = [event.api_host, event.writekey, event.dataset]
141
+ batched_events[key] << event
142
+ end
141
143
  end
142
144
 
143
145
  break
@@ -179,11 +181,14 @@ module Libhoney
179
181
  payload = []
180
182
  batch.map! do |event|
181
183
  begin
184
+ data = clean_data(event.data)
185
+
182
186
  e = {
183
187
  time: event.timestamp.iso8601(3),
184
188
  samplerate: event.sample_rate,
185
- data: event.data
189
+ data: data
186
190
  }
191
+
187
192
  payload << JSON.generate(e)
188
193
 
189
194
  event
@@ -1,3 +1,3 @@
1
1
  module Libhoney
2
- VERSION = '1.14.0'.freeze
2
+ VERSION = '1.14.5'.freeze
3
3
  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.14.0
4
+ version: 1.14.5
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: 2019-09-06 00:00:00.000000000 Z
11
+ date: 2020-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump
@@ -206,6 +206,7 @@ extra_rdoc_files: []
206
206
  files:
207
207
  - ".circleci/config.yml"
208
208
  - ".circleci/setup-rubygems.sh"
209
+ - ".github/CODEOWNERS"
209
210
  - ".gitignore"
210
211
  - ".rubocop.yml"
211
212
  - ".rubocop_todo.yml"
@@ -219,6 +220,7 @@ files:
219
220
  - example/factorial.rb
220
221
  - lib/libhoney.rb
221
222
  - lib/libhoney/builder.rb
223
+ - lib/libhoney/cleaner.rb
222
224
  - lib/libhoney/client.rb
223
225
  - lib/libhoney/event.rb
224
226
  - lib/libhoney/log_client.rb
@@ -250,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
252
  - !ruby/object:Gem::Version
251
253
  version: '0'
252
254
  requirements: []
253
- rubygems_version: 3.0.3
255
+ rubygems_version: 3.1.2
254
256
  signing_key:
255
257
  specification_version: 4
256
258
  summary: send data to Honeycomb