libhoney 1.14.0 → 1.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +4 -4
- data/Gemfile.lock +9 -4
- data/lib/libhoney/cleaner.rb +62 -0
- data/lib/libhoney/transmission.rb +8 -1
- data/lib/libhoney/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2373830c8e1db77f91d3246c8e0f70f014d18f3ddf385f7a47eaff425e5750df
|
4
|
+
data.tar.gz: a40a3eef2910a08fad7c23302ad15ed42764e9dea1dce589a4f75473ed7a4adb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47d18ab9a49b10f8277508048eaf0736ca36547918181c02b94d8ea7a5c6c2e9c068b63972446cc90a0e1adc4c6a4f900671e6644d869798f687b019356233f3
|
7
|
+
data.tar.gz: f356d9b7428041fa5e6fbfaafded29b4c84aa78eaecbc61f04a9472162a796d9934d3c1912d60182cbb8696dc4d77e3c2d4fc1642f5d7c11017802625ea4f4d3
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -14,17 +14,17 @@ Lint/HandleExceptions:
|
|
14
14
|
|
15
15
|
# Offense count: 7
|
16
16
|
Metrics/AbcSize:
|
17
|
-
Max:
|
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:
|
23
|
+
Max: 30
|
24
24
|
|
25
25
|
# Offense count: 2
|
26
26
|
Metrics/CyclomaticComplexity:
|
27
|
-
Max:
|
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:
|
36
|
+
Max: 10
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
libhoney (1.14.
|
4
|
+
libhoney (1.14.1)
|
5
5
|
addressable (~> 2.0)
|
6
6
|
http (>= 2.0, < 5.0)
|
7
7
|
|
@@ -17,16 +17,21 @@ GEM
|
|
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.11.2)
|
21
|
+
ffi-compiler (1.0.1)
|
22
|
+
ffi (>= 1.0.0)
|
23
|
+
rake
|
20
24
|
hashdiff (1.0.0)
|
21
|
-
http (4.
|
25
|
+
http (4.2.0)
|
22
26
|
addressable (~> 2.3)
|
23
27
|
http-cookie (~> 1.0)
|
24
28
|
http-form_data (~> 2.0)
|
25
|
-
|
29
|
+
http-parser (~> 1.2.0)
|
26
30
|
http-cookie (1.0.3)
|
27
31
|
domain_name (~> 0.5)
|
28
32
|
http-form_data (2.1.1)
|
29
|
-
|
33
|
+
http-parser (1.2.1)
|
34
|
+
ffi-compiler (>= 1.0, < 2.0)
|
30
35
|
jaro_winkler (1.5.3)
|
31
36
|
minitest (5.11.3)
|
32
37
|
multi_json (1.13.1)
|
@@ -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
|
@@ -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,
|
@@ -63,6 +66,7 @@ module Libhoney
|
|
63
66
|
begin
|
64
67
|
http = http_clients[api_host]
|
65
68
|
body = serialize_batch(batch)
|
69
|
+
|
66
70
|
next if body.nil?
|
67
71
|
|
68
72
|
headers = {
|
@@ -179,11 +183,14 @@ module Libhoney
|
|
179
183
|
payload = []
|
180
184
|
batch.map! do |event|
|
181
185
|
begin
|
186
|
+
data = clean_data(event.data)
|
187
|
+
|
182
188
|
e = {
|
183
189
|
time: event.timestamp.iso8601(3),
|
184
190
|
samplerate: event.sample_rate,
|
185
|
-
data:
|
191
|
+
data: data
|
186
192
|
}
|
193
|
+
|
187
194
|
payload << JSON.generate(e)
|
188
195
|
|
189
196
|
event
|
data/lib/libhoney/version.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.14.
|
4
|
+
version: 1.14.1
|
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-
|
11
|
+
date: 2019-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bump
|
@@ -219,6 +219,7 @@ files:
|
|
219
219
|
- example/factorial.rb
|
220
220
|
- lib/libhoney.rb
|
221
221
|
- lib/libhoney/builder.rb
|
222
|
+
- lib/libhoney/cleaner.rb
|
222
223
|
- lib/libhoney/client.rb
|
223
224
|
- lib/libhoney/event.rb
|
224
225
|
- lib/libhoney/log_client.rb
|