libhoney 1.14.7 → 1.18.0
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 +4 -4
- data/.circleci/config.yml +129 -81
- data/.editorconfig +1 -1
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +55 -0
- data/README.md +8 -5
- data/lib/libhoney/client.rb +45 -34
- data/lib/libhoney/response.rb +10 -2
- data/lib/libhoney/transmission.rb +42 -11
- data/lib/libhoney/version.rb +1 -1
- data/libhoney.gemspec +2 -1
- metadata +21 -7
- data/Gemfile.lock +0 -103
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 33a687ebf8ae87e69cf6a53b50c4e2cd926f9938af709635d42a209ec2e6c93e
|
|
4
|
+
data.tar.gz: fd3f558a15f872c9f63fc6451722c3e9e21b7cba5ebe8d7816ec0cb08064318b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 36efc5d9734e125cd141e21dd60edbc6cf23350334bf431dead264c375dfd11b54bcf286f5509d5e97633ee4ce2d4fc689ebf5033d472237d5b6e7e2f2d0cb81
|
|
7
|
+
data.tar.gz: 5d5147a6e9f3fc1055a94932943c5915c99f43ad550d4dd5f20955d2dad023c41a1939e6f8037b38856375a10dcdc51557b06e3d56b454296a1596c7dd62b74c
|
data/.circleci/config.yml
CHANGED
|
@@ -1,67 +1,63 @@
|
|
|
1
|
-
version: 2.
|
|
1
|
+
version: 2.1
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
12
|
-
- restore_cache:
|
|
13
|
-
keys:
|
|
14
|
-
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
|
15
|
-
# fallback to using the latest cache if no exact match is found
|
|
16
|
-
- v1-dependencies-
|
|
17
|
-
- run:
|
|
18
|
-
name: install dependencies
|
|
19
|
-
command: |
|
|
20
|
-
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
|
21
|
-
- save_cache:
|
|
22
|
-
paths:
|
|
23
|
-
- ./vendor/bundle
|
|
24
|
-
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
|
25
|
-
- run:
|
|
26
|
-
name: run rubocop
|
|
27
|
-
command: bundle exec rake rubocop
|
|
28
|
-
- run:
|
|
29
|
-
name: run tests
|
|
30
|
-
command: bundle exec rake test
|
|
3
|
+
# YAML Anchors to reduce copypasta
|
|
31
4
|
|
|
32
|
-
#
|
|
33
|
-
|
|
5
|
+
# This is necessary for job to run when a tag is created
|
|
6
|
+
filters_always: &filters_always
|
|
34
7
|
filters:
|
|
35
|
-
|
|
36
|
-
|
|
8
|
+
tags:
|
|
9
|
+
only: /.*/
|
|
37
10
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
ruby
|
|
11
|
+
# Restrict running to only be on tags starting with vNNNN
|
|
12
|
+
filters_publish: &filters_publish
|
|
13
|
+
filters:
|
|
14
|
+
tags:
|
|
15
|
+
only: /^v[0-9].*/
|
|
16
|
+
branches:
|
|
17
|
+
ignore: /.*/
|
|
18
|
+
|
|
19
|
+
matrix_rubyversions: &matrix_rubyversions
|
|
20
|
+
matrix:
|
|
21
|
+
parameters:
|
|
22
|
+
rubyversion: ["2.2", "2.3", "2.4", "2.5", "2.6", "2.7"]
|
|
23
|
+
|
|
24
|
+
# Default version of ruby to use for lint and publishing
|
|
25
|
+
default_rubyversion: &default_rubyversion "2.7"
|
|
26
|
+
|
|
27
|
+
executors:
|
|
28
|
+
ruby:
|
|
29
|
+
parameters:
|
|
30
|
+
rubyversion:
|
|
31
|
+
type: string
|
|
32
|
+
default: *default_rubyversion
|
|
56
33
|
docker:
|
|
57
|
-
- image: circleci/ruby
|
|
58
|
-
|
|
59
|
-
publish:
|
|
34
|
+
- image: circleci/ruby:<< parameters.rubyversion >>
|
|
35
|
+
github:
|
|
60
36
|
docker:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
37
|
+
- image: cibuilds/github:0.13.0
|
|
38
|
+
|
|
39
|
+
commands:
|
|
40
|
+
publish_github:
|
|
41
|
+
steps:
|
|
42
|
+
- attach_workspace:
|
|
43
|
+
at: ~/
|
|
44
|
+
- run:
|
|
45
|
+
name: "Artifacts being published"
|
|
46
|
+
command: |
|
|
47
|
+
echo "about to publish to tag ${CIRCLE_TAG}"
|
|
48
|
+
ls -l ~/artifacts/*
|
|
49
|
+
- run:
|
|
50
|
+
name: "GHR Draft"
|
|
51
|
+
command: ghr -draft -n ${CIRCLE_TAG} -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ${CIRCLE_TAG} ~/artifacts
|
|
52
|
+
publish_rubygems:
|
|
64
53
|
steps:
|
|
54
|
+
- attach_workspace:
|
|
55
|
+
at: ~/
|
|
56
|
+
- run:
|
|
57
|
+
name: "Artifacts being published"
|
|
58
|
+
command: |
|
|
59
|
+
echo "about to publish to tag ${CIRCLE_TAG}"
|
|
60
|
+
ls -l ~/artifacts/*
|
|
65
61
|
- checkout
|
|
66
62
|
- run:
|
|
67
63
|
name: Setup Rubygems
|
|
@@ -69,11 +65,66 @@ jobs:
|
|
|
69
65
|
- run:
|
|
70
66
|
name: Publish to Rubygems
|
|
71
67
|
command: |
|
|
72
|
-
gem
|
|
73
|
-
|
|
68
|
+
gem push ~/artifacts/*.gem
|
|
69
|
+
|
|
70
|
+
jobs:
|
|
71
|
+
test:
|
|
72
|
+
parameters:
|
|
73
|
+
rubyversion:
|
|
74
|
+
type: string
|
|
75
|
+
default: *default_rubyversion
|
|
76
|
+
executor:
|
|
77
|
+
name: ruby
|
|
78
|
+
rubyversion: "<< parameters.rubyversion >>"
|
|
79
|
+
steps:
|
|
80
|
+
- checkout
|
|
81
|
+
- restore_cache:
|
|
82
|
+
keys:
|
|
83
|
+
- v1-dependencies-{{ checksum "libhoney.gemspec" }}
|
|
84
|
+
# fallback to using the latest cache if no exact match is found
|
|
85
|
+
- v1-dependencies-
|
|
86
|
+
- run:
|
|
87
|
+
name: install dependencies
|
|
88
|
+
command: |
|
|
89
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
|
90
|
+
- save_cache:
|
|
91
|
+
paths:
|
|
92
|
+
- ./vendor/bundle
|
|
93
|
+
key: v1-dependencies-{{ checksum "libhoney.gemspec" }}
|
|
94
|
+
- run:
|
|
95
|
+
name: run rubocop
|
|
96
|
+
command: bundle exec rake rubocop
|
|
97
|
+
- run:
|
|
98
|
+
name: run tests
|
|
99
|
+
command: bundle exec rake test
|
|
100
|
+
|
|
101
|
+
build_artifacts:
|
|
102
|
+
executor:
|
|
103
|
+
name: ruby
|
|
104
|
+
steps:
|
|
105
|
+
- checkout
|
|
106
|
+
- run: mkdir -p ~/artifacts
|
|
107
|
+
- run: gem build libhoney.gemspec
|
|
108
|
+
- run: cp libhoney-*.gem ~/artifacts/
|
|
109
|
+
- persist_to_workspace:
|
|
110
|
+
root: ~/
|
|
111
|
+
paths:
|
|
112
|
+
- artifacts
|
|
113
|
+
- store_artifacts:
|
|
114
|
+
path: ~/artifacts
|
|
115
|
+
|
|
116
|
+
publish_github:
|
|
117
|
+
executor: github
|
|
118
|
+
steps:
|
|
119
|
+
- publish_github
|
|
120
|
+
|
|
121
|
+
publish_rubygems:
|
|
122
|
+
executor:
|
|
123
|
+
name: ruby
|
|
124
|
+
steps:
|
|
125
|
+
- publish_rubygems
|
|
74
126
|
|
|
75
127
|
workflows:
|
|
76
|
-
version: 2
|
|
77
128
|
nightly:
|
|
78
129
|
triggers:
|
|
79
130
|
- schedule:
|
|
@@ -83,27 +134,24 @@ workflows:
|
|
|
83
134
|
only:
|
|
84
135
|
- main
|
|
85
136
|
jobs:
|
|
86
|
-
-
|
|
87
|
-
|
|
88
|
-
- ruby-2.5: *tag_filters
|
|
89
|
-
- ruby-2.6: *tag_filters
|
|
90
|
-
- ruby-2.7: *tag_filters
|
|
137
|
+
- test:
|
|
138
|
+
<<: *matrix_rubyversions
|
|
91
139
|
build:
|
|
92
140
|
jobs:
|
|
93
|
-
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
-
|
|
97
|
-
|
|
98
|
-
- publish:
|
|
141
|
+
- test:
|
|
142
|
+
<<: *filters_always
|
|
143
|
+
<<: *matrix_rubyversions
|
|
144
|
+
- build_artifacts:
|
|
145
|
+
<<: *filters_always
|
|
99
146
|
requires:
|
|
100
|
-
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
147
|
+
- test
|
|
148
|
+
- publish_github:
|
|
149
|
+
<<: *filters_publish
|
|
150
|
+
context: Honeycomb Secrets for Public Repos
|
|
151
|
+
requires:
|
|
152
|
+
- build_artifacts
|
|
153
|
+
- publish_rubygems:
|
|
154
|
+
<<: *filters_publish
|
|
155
|
+
context: Honeycomb Secrets for Public Repos
|
|
156
|
+
requires:
|
|
157
|
+
- build_artifacts
|
data/.editorconfig
CHANGED
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# libhoney-rb changelog
|
|
2
|
+
|
|
3
|
+
## changes pending release
|
|
4
|
+
|
|
5
|
+
## 1.18.0
|
|
6
|
+
|
|
7
|
+
### Improvements
|
|
8
|
+
|
|
9
|
+
- replace HTTP client library to reduce external dependencies (#81)
|
|
10
|
+
|
|
11
|
+
### Deprecations
|
|
12
|
+
|
|
13
|
+
- `Libhoney::Client.new(proxy_config: _)`: the `proxy_config` parameter for client
|
|
14
|
+
creation will no longer accept an Array in the next major version. The recommended
|
|
15
|
+
way to configure the client for operation behind forwarding web proxies is to set
|
|
16
|
+
http/https/no_proxy environment variables appropriately.
|
|
17
|
+
|
|
18
|
+
## 1.17.0
|
|
19
|
+
|
|
20
|
+
### Fixes:
|
|
21
|
+
|
|
22
|
+
- Allow Ruby 3.0.0 (removes overly-pessimistic exception) (#79)
|
|
23
|
+
|
|
24
|
+
## 1.16.1
|
|
25
|
+
|
|
26
|
+
### Fixes:
|
|
27
|
+
|
|
28
|
+
- Fix closing down the client when no threads have been started. (#74 & #76)
|
|
29
|
+
|
|
30
|
+
## 1.16.0
|
|
31
|
+
|
|
32
|
+
### Fixes:
|
|
33
|
+
|
|
34
|
+
- Don't moneypatch Class (#70)
|
|
35
|
+
|
|
36
|
+
### Maintenance:
|
|
37
|
+
|
|
38
|
+
- Add lockfile to gitignore (#71)
|
|
39
|
+
|
|
40
|
+
## 1.15.0
|
|
41
|
+
|
|
42
|
+
### Improvements:
|
|
43
|
+
|
|
44
|
+
- Do not attempt to send invalid events (#67)
|
|
45
|
+
|
|
46
|
+
### Maintenance:
|
|
47
|
+
|
|
48
|
+
- Modernize circle, include github publishing (#64)
|
|
49
|
+
- Update .editorconfig to add new lines to end of files (#68)
|
|
50
|
+
|
|
51
|
+
### Misc
|
|
52
|
+
|
|
53
|
+
- Added CHANGELOG.md
|
|
54
|
+
- Updates to CI configuration and documentation
|
|
55
|
+
- Updated version management.
|
data/README.md
CHANGED
|
@@ -4,8 +4,8 @@ Ruby gem for sending events to [Honeycomb](https://www.honeycomb.io), a service
|
|
|
4
4
|
|
|
5
5
|
Requires Ruby 2.2 or greater.
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
7
|
+
- [Usage and Examples](https://docs.honeycomb.io/sdk/ruby/)
|
|
8
|
+
- [API Reference](https://www.rubydoc.info/gems/libhoney)
|
|
9
9
|
|
|
10
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).
|
|
11
11
|
|
|
@@ -20,8 +20,11 @@ All contributions will be released under the Apache License 2.0.
|
|
|
20
20
|
### Releasing a new version
|
|
21
21
|
|
|
22
22
|
CircleCI will automatically upload tagged releases to Rubygems. To release a new
|
|
23
|
-
version,
|
|
23
|
+
version, update the version using `bump`.
|
|
24
|
+
|
|
24
25
|
```
|
|
25
|
-
bump patch
|
|
26
|
-
git push --follow-tags
|
|
26
|
+
bump patch # Or bump minor, etc.
|
|
27
27
|
```
|
|
28
|
+
|
|
29
|
+
Then, after the version change has been merged into `main`, follow our usual instructions
|
|
30
|
+
for tagging and updating the github release.
|
data/lib/libhoney/client.rb
CHANGED
|
@@ -1,31 +1,10 @@
|
|
|
1
|
+
require 'addressable/uri'
|
|
1
2
|
require 'time'
|
|
2
3
|
require 'json'
|
|
3
|
-
require '
|
|
4
|
+
require 'forwardable'
|
|
4
5
|
|
|
5
6
|
require 'libhoney/null_transmission'
|
|
6
7
|
|
|
7
|
-
# Define a few additions that proxy access through Client's builder. Makes Client much tighter.
|
|
8
|
-
class Class
|
|
9
|
-
def builder_attr_accessor(*args)
|
|
10
|
-
args.each do |arg|
|
|
11
|
-
class_eval("def #{arg};@builder.#{arg};end", __FILE__, __LINE__)
|
|
12
|
-
class_eval("def #{arg}=(val);@builder.#{arg}=val;end", __FILE__, __LINE__)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def builder_attr_reader(*args)
|
|
17
|
-
args.each do |arg|
|
|
18
|
-
class_eval("def #{arg};@builder.#{arg};end", __FILE__, __LINE__)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def builder_attr_writer(*args)
|
|
23
|
-
args.each do |arg|
|
|
24
|
-
class_eval("def #{arg}=(val);@builder.#{arg}=val;end", __FILE__, __LINE__)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
8
|
module Libhoney
|
|
30
9
|
##
|
|
31
10
|
# This is a library to allow you to send events to Honeycomb from within your
|
|
@@ -52,6 +31,8 @@ module Libhoney
|
|
|
52
31
|
# evt.send
|
|
53
32
|
#
|
|
54
33
|
class Client
|
|
34
|
+
extend Forwardable
|
|
35
|
+
|
|
55
36
|
API_HOST = 'https://api.honeycomb.io/'.freeze
|
|
56
37
|
|
|
57
38
|
# Instantiates libhoney and prepares it to send events to Honeycomb.
|
|
@@ -70,6 +51,13 @@ module Libhoney
|
|
|
70
51
|
# @param block_on_responses [Boolean] if true, block if there is no thread reading from the response queue
|
|
71
52
|
# @param pending_work_capacity [Fixnum] defaults to 1000. If the queue of
|
|
72
53
|
# pending events exceeds 1000, this client will start dropping events.
|
|
54
|
+
# @param proxy_config [String, Array, nil] proxy connection information
|
|
55
|
+
# nil: (default, recommended) connection proxying will be determined from any http_proxy, https_proxy, and no_proxy environment
|
|
56
|
+
# variables set for the process.
|
|
57
|
+
# String: the value must be the URI for connecting to a forwarding web proxy. Must be parsable by stdlib URI.
|
|
58
|
+
# Array: (deprecated, removal in v2.0) the value must have one and at most four elements: e.g. ['host', port, 'username', 'password'].
|
|
59
|
+
# The assumption is that the TCP connection will be tunneled via HTTP, so the assumed scheme is 'http://'
|
|
60
|
+
# 'host' is required. 'port' is optional (default:80), unless a 'username' is included. 'password' is optional.
|
|
73
61
|
# rubocop:disable Metrics/ParameterLists
|
|
74
62
|
def initialize(writekey: nil,
|
|
75
63
|
dataset: nil,
|
|
@@ -89,7 +77,7 @@ module Libhoney
|
|
|
89
77
|
raise Exception, 'libhoney: max_concurrent_batches must be greater than 0' if max_concurrent_batches < 1
|
|
90
78
|
raise Exception, 'libhoney: sample rate must be greater than 0' if sample_rate < 1
|
|
91
79
|
|
|
92
|
-
unless Gem::Dependency.new('ruby', '
|
|
80
|
+
unless Gem::Dependency.new('ruby', '>= 2.2').match?('ruby', RUBY_VERSION)
|
|
93
81
|
raise Exception, 'libhoney: Ruby versions < 2.2 are not supported'
|
|
94
82
|
end
|
|
95
83
|
|
|
@@ -121,22 +109,15 @@ module Libhoney
|
|
|
121
109
|
@pending_work_capacity = pending_work_capacity
|
|
122
110
|
@responses = SizedQueue.new(2 * @pending_work_capacity)
|
|
123
111
|
@lock = Mutex.new
|
|
124
|
-
@proxy_config = proxy_config
|
|
112
|
+
@proxy_config = parse_proxy_config(proxy_config)
|
|
125
113
|
end
|
|
126
114
|
|
|
127
|
-
builder_attr_accessor :writekey, :dataset, :sample_rate, :api_host
|
|
128
|
-
|
|
129
115
|
attr_reader :block_on_send, :block_on_responses, :max_batch_size,
|
|
130
116
|
:send_frequency, :max_concurrent_batches,
|
|
131
117
|
:pending_work_capacity, :responses
|
|
132
118
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def builder(fields = {}, dyn_fields = {})
|
|
138
|
-
@builder.builder(fields, dyn_fields)
|
|
139
|
-
end
|
|
119
|
+
def_delegators :@builder, :event, :writekey, :writekey=, :dataset, :dataset=,
|
|
120
|
+
:sample_rate, :sample_rate=, :api_host, :api_host=, :builder
|
|
140
121
|
|
|
141
122
|
# Nuke the queue and wait for inflight requests to complete before returning.
|
|
142
123
|
# If you set drain=false, all queued requests will be dropped on the floor.
|
|
@@ -250,5 +231,35 @@ module Libhoney
|
|
|
250
231
|
def should_drop(sample_rate)
|
|
251
232
|
rand(1..sample_rate) != 1
|
|
252
233
|
end
|
|
234
|
+
|
|
235
|
+
private
|
|
236
|
+
|
|
237
|
+
# @api private
|
|
238
|
+
def parse_proxy_config(config)
|
|
239
|
+
case config
|
|
240
|
+
when nil then nil
|
|
241
|
+
when String
|
|
242
|
+
URI.parse(config)
|
|
243
|
+
when Array
|
|
244
|
+
warn <<-WARNING
|
|
245
|
+
DEPRECATION WARNING: #{self.class.name} the proxy_config parameter will require a String value, not an Array in libhoney 2.0.
|
|
246
|
+
To resolve:
|
|
247
|
+
+ recommended: set http/https_proxy environment variables, which take precedence over any option set here, then remove proxy_config parameter from client initialization
|
|
248
|
+
+ set proxy_config to a String containing the forwarding proxy URI (only used if http/https_proxy are not set)
|
|
249
|
+
WARNING
|
|
250
|
+
host, port, user, password = config
|
|
251
|
+
|
|
252
|
+
parsed_config = URI::HTTP.build(host: host, port: port).tap do |uri|
|
|
253
|
+
uri.userinfo = "#{user}:#{password}" if user
|
|
254
|
+
end
|
|
255
|
+
redacted_config = parsed_config.dup.tap do |uri|
|
|
256
|
+
uri.password = 'REDACTED' unless uri.password.nil? || uri.password.empty?
|
|
257
|
+
end
|
|
258
|
+
warn "The array config given has been assumed to mean: #{redacted_config}"
|
|
259
|
+
parsed_config
|
|
260
|
+
end
|
|
261
|
+
rescue URI::Error => e
|
|
262
|
+
warn "#{self.class.name}: unable to parse proxy_config. Detail: #{e.class}: #{e.message}"
|
|
263
|
+
end
|
|
253
264
|
end
|
|
254
265
|
end
|
data/lib/libhoney/response.rb
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
require 'http'
|
|
1
|
+
require 'http/response/status'
|
|
2
2
|
|
|
3
3
|
module Libhoney
|
|
4
4
|
class Response
|
|
5
|
+
# The response status from HTTP calls to a Honeycomb API endpoint.
|
|
6
|
+
#
|
|
7
|
+
# For most of the life of this client, this response object has been
|
|
8
|
+
# a pass-through to the underlying HTTP library's response object.
|
|
9
|
+
# This class in the Libhoney namespace now owns the interface for
|
|
10
|
+
# API responses.
|
|
11
|
+
class Status < HTTP::Response::Status; end
|
|
12
|
+
|
|
5
13
|
attr_accessor :duration, :status_code, :metadata, :error
|
|
6
14
|
|
|
7
15
|
def initialize(duration: 0,
|
|
@@ -9,7 +17,7 @@ module Libhoney
|
|
|
9
17
|
metadata: nil,
|
|
10
18
|
error: nil)
|
|
11
19
|
@duration = duration
|
|
12
|
-
@status_code =
|
|
20
|
+
@status_code = Status.new(status_code)
|
|
13
21
|
@metadata = metadata
|
|
14
22
|
@error = error
|
|
15
23
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'addressable/uri'
|
|
2
|
+
require 'excon'
|
|
1
3
|
require 'json'
|
|
2
4
|
require 'timeout'
|
|
3
5
|
require 'libhoney/response'
|
|
@@ -40,6 +42,8 @@ module Libhoney
|
|
|
40
42
|
end
|
|
41
43
|
|
|
42
44
|
def add(event)
|
|
45
|
+
return unless event_valid(event)
|
|
46
|
+
|
|
43
47
|
begin
|
|
44
48
|
@batch_queue.enq(event, !@block_on_send)
|
|
45
49
|
rescue ThreadError
|
|
@@ -49,6 +53,26 @@ module Libhoney
|
|
|
49
53
|
ensure_threads_running
|
|
50
54
|
end
|
|
51
55
|
|
|
56
|
+
def event_valid(event)
|
|
57
|
+
invalid = []
|
|
58
|
+
invalid.push('api host') if event.api_host.nil? || event.api_host.empty?
|
|
59
|
+
invalid.push('write key') if event.writekey.nil? || event.writekey.empty?
|
|
60
|
+
invalid.push('dataset') if event.dataset.nil? || event.dataset.empty?
|
|
61
|
+
|
|
62
|
+
unless invalid.empty?
|
|
63
|
+
e = StandardError.new("#{self.class.name}: nil or empty required fields (#{invalid.join(', ')})"\
|
|
64
|
+
'. Will not attempt to send.')
|
|
65
|
+
Response.new(error: e).tap do |error_response|
|
|
66
|
+
error_response.metadata = event.metadata
|
|
67
|
+
enqueue_response(error_response)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
return false
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
true
|
|
74
|
+
end
|
|
75
|
+
|
|
52
76
|
def send_loop
|
|
53
77
|
http_clients = build_http_clients
|
|
54
78
|
|
|
@@ -71,7 +95,7 @@ module Libhoney
|
|
|
71
95
|
}
|
|
72
96
|
|
|
73
97
|
response = http.post(
|
|
74
|
-
"/1/batch/#{Addressable::URI.escape(dataset)}",
|
|
98
|
+
path: "/1/batch/#{Addressable::URI.escape(dataset)}",
|
|
75
99
|
body: body,
|
|
76
100
|
headers: headers
|
|
77
101
|
)
|
|
@@ -81,6 +105,8 @@ module Libhoney
|
|
|
81
105
|
# because this is effectively the top-level exception handler for the
|
|
82
106
|
# sender threads, and we don't want those threads to die (leaving
|
|
83
107
|
# nothing consuming the queue).
|
|
108
|
+
warn "#{self.class.name}: 💥 " + e.message if %w[debug trace].include?(ENV['LOG_LEVEL'])
|
|
109
|
+
warn e.backtrace.join("\n").to_s if ['trace'].include?(ENV['LOG_LEVEL'])
|
|
84
110
|
begin
|
|
85
111
|
batch.each do |event|
|
|
86
112
|
# nil events in the batch should already have had an error
|
|
@@ -114,7 +140,7 @@ module Libhoney
|
|
|
114
140
|
end
|
|
115
141
|
|
|
116
142
|
@batch_queue.enq(nil)
|
|
117
|
-
@batch_thread.join
|
|
143
|
+
@batch_thread.join unless @batch_thread.nil?
|
|
118
144
|
|
|
119
145
|
# send @threads.length number of nils so each thread will fall out of send_loop
|
|
120
146
|
@threads.length.times { @send_queue << nil }
|
|
@@ -165,7 +191,7 @@ module Libhoney
|
|
|
165
191
|
|
|
166
192
|
def process_response(http_response, before, batch)
|
|
167
193
|
index = 0
|
|
168
|
-
|
|
194
|
+
JSON.parse(http_response.body).each do |event|
|
|
169
195
|
index += 1 while batch[index].nil? && index < batch.size
|
|
170
196
|
break unless (batched_event = batch[index])
|
|
171
197
|
|
|
@@ -234,14 +260,19 @@ module Libhoney
|
|
|
234
260
|
|
|
235
261
|
def build_http_clients
|
|
236
262
|
Hash.new do |h, api_host|
|
|
237
|
-
client =
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
263
|
+
client = ::Excon.new(
|
|
264
|
+
api_host,
|
|
265
|
+
persistent: true,
|
|
266
|
+
read_timeout: @send_timeout,
|
|
267
|
+
write_timeout: @send_timeout,
|
|
268
|
+
connect_timeout: @send_timeout,
|
|
269
|
+
proxy: @proxy_config,
|
|
270
|
+
headers: {
|
|
271
|
+
'User-Agent' => @user_agent,
|
|
272
|
+
'Content-Type' => 'application/json'
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
|
|
245
276
|
h[api_host] = client
|
|
246
277
|
end
|
|
247
278
|
end
|
data/lib/libhoney/version.rb
CHANGED
data/libhoney.gemspec
CHANGED
|
@@ -29,10 +29,11 @@ Gem::Specification.new do |spec|
|
|
|
29
29
|
spec.add_development_dependency 'rubocop', '< 0.69'
|
|
30
30
|
spec.add_development_dependency 'sinatra'
|
|
31
31
|
spec.add_development_dependency 'sinatra-contrib'
|
|
32
|
-
spec.add_development_dependency 'spy'
|
|
32
|
+
spec.add_development_dependency 'spy', '1.0.0'
|
|
33
33
|
spec.add_development_dependency 'webmock', '~> 3.4'
|
|
34
34
|
spec.add_development_dependency 'yard'
|
|
35
35
|
spec.add_development_dependency 'yardstick', '~> 0.9'
|
|
36
36
|
spec.add_dependency 'addressable', '~> 2.0'
|
|
37
|
+
spec.add_dependency 'excon'
|
|
37
38
|
spec.add_dependency 'http', '>= 2.0', '< 5.0'
|
|
38
39
|
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.
|
|
4
|
+
version: 1.18.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:
|
|
11
|
+
date: 2021-01-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bump
|
|
@@ -112,16 +112,16 @@ dependencies:
|
|
|
112
112
|
name: spy
|
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
|
114
114
|
requirements:
|
|
115
|
-
- -
|
|
115
|
+
- - '='
|
|
116
116
|
- !ruby/object:Gem::Version
|
|
117
|
-
version:
|
|
117
|
+
version: 1.0.0
|
|
118
118
|
type: :development
|
|
119
119
|
prerelease: false
|
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
121
|
requirements:
|
|
122
|
-
- -
|
|
122
|
+
- - '='
|
|
123
123
|
- !ruby/object:Gem::Version
|
|
124
|
-
version:
|
|
124
|
+
version: 1.0.0
|
|
125
125
|
- !ruby/object:Gem::Dependency
|
|
126
126
|
name: webmock
|
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -178,6 +178,20 @@ dependencies:
|
|
|
178
178
|
- - "~>"
|
|
179
179
|
- !ruby/object:Gem::Version
|
|
180
180
|
version: '2.0'
|
|
181
|
+
- !ruby/object:Gem::Dependency
|
|
182
|
+
name: excon
|
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
|
184
|
+
requirements:
|
|
185
|
+
- - ">="
|
|
186
|
+
- !ruby/object:Gem::Version
|
|
187
|
+
version: '0'
|
|
188
|
+
type: :runtime
|
|
189
|
+
prerelease: false
|
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
191
|
+
requirements:
|
|
192
|
+
- - ">="
|
|
193
|
+
- !ruby/object:Gem::Version
|
|
194
|
+
version: '0'
|
|
181
195
|
- !ruby/object:Gem::Dependency
|
|
182
196
|
name: http
|
|
183
197
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -211,9 +225,9 @@ files:
|
|
|
211
225
|
- ".gitignore"
|
|
212
226
|
- ".rubocop.yml"
|
|
213
227
|
- ".rubocop_todo.yml"
|
|
228
|
+
- CHANGELOG.md
|
|
214
229
|
- CONTRIBUTORS
|
|
215
230
|
- Gemfile
|
|
216
|
-
- Gemfile.lock
|
|
217
231
|
- LICENSE
|
|
218
232
|
- NOTICE
|
|
219
233
|
- README.md
|
data/Gemfile.lock
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
libhoney (1.14.7)
|
|
5
|
-
addressable (~> 2.0)
|
|
6
|
-
http (>= 2.0, < 5.0)
|
|
7
|
-
|
|
8
|
-
GEM
|
|
9
|
-
remote: https://rubygems.org/
|
|
10
|
-
specs:
|
|
11
|
-
addressable (2.7.0)
|
|
12
|
-
public_suffix (>= 2.0.2, < 5.0)
|
|
13
|
-
ast (2.4.0)
|
|
14
|
-
backports (3.16.0)
|
|
15
|
-
bump (0.8.0)
|
|
16
|
-
crack (0.4.3)
|
|
17
|
-
safe_yaml (~> 1.0.0)
|
|
18
|
-
domain_name (0.5.20190701)
|
|
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
|
|
24
|
-
hashdiff (1.0.0)
|
|
25
|
-
http (4.4.1)
|
|
26
|
-
addressable (~> 2.3)
|
|
27
|
-
http-cookie (~> 1.0)
|
|
28
|
-
http-form_data (~> 2.2)
|
|
29
|
-
http-parser (~> 1.2.0)
|
|
30
|
-
http-cookie (1.0.3)
|
|
31
|
-
domain_name (~> 0.5)
|
|
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)
|
|
42
|
-
ast (~> 2.4.0)
|
|
43
|
-
public_suffix (4.0.3)
|
|
44
|
-
rack (2.1.4)
|
|
45
|
-
rack-protection (2.0.8.1)
|
|
46
|
-
rack
|
|
47
|
-
rainbow (3.0.0)
|
|
48
|
-
rake (12.3.3)
|
|
49
|
-
rubocop (0.68.1)
|
|
50
|
-
jaro_winkler (~> 1.5.1)
|
|
51
|
-
parallel (~> 1.10)
|
|
52
|
-
parser (>= 2.5, != 2.5.1.1)
|
|
53
|
-
rainbow (>= 2.2.2, < 4.0)
|
|
54
|
-
ruby-progressbar (~> 1.7)
|
|
55
|
-
unicode-display_width (>= 1.4.0, < 1.6)
|
|
56
|
-
ruby-progressbar (1.10.1)
|
|
57
|
-
ruby2_keywords (0.0.2)
|
|
58
|
-
safe_yaml (1.0.5)
|
|
59
|
-
sinatra (2.0.8.1)
|
|
60
|
-
mustermann (~> 1.0)
|
|
61
|
-
rack (~> 2.0)
|
|
62
|
-
rack-protection (= 2.0.8.1)
|
|
63
|
-
tilt (~> 2.0)
|
|
64
|
-
sinatra-contrib (2.0.8.1)
|
|
65
|
-
backports (>= 2.8.2)
|
|
66
|
-
multi_json
|
|
67
|
-
mustermann (~> 1.0)
|
|
68
|
-
rack-protection (= 2.0.8.1)
|
|
69
|
-
sinatra (= 2.0.8.1)
|
|
70
|
-
tilt (~> 2.0)
|
|
71
|
-
spy (1.0.0)
|
|
72
|
-
tilt (2.0.10)
|
|
73
|
-
unf (0.1.4)
|
|
74
|
-
unf_ext
|
|
75
|
-
unf_ext (0.0.7.7)
|
|
76
|
-
unicode-display_width (1.5.0)
|
|
77
|
-
webmock (3.8.1)
|
|
78
|
-
addressable (>= 2.3.6)
|
|
79
|
-
crack (>= 0.3.2)
|
|
80
|
-
hashdiff (>= 0.4.0, < 2.0.0)
|
|
81
|
-
yard (0.9.24)
|
|
82
|
-
yardstick (0.9.9)
|
|
83
|
-
yard (~> 0.8, >= 0.8.7.2)
|
|
84
|
-
|
|
85
|
-
PLATFORMS
|
|
86
|
-
ruby
|
|
87
|
-
|
|
88
|
-
DEPENDENCIES
|
|
89
|
-
bump (~> 0.5)
|
|
90
|
-
bundler
|
|
91
|
-
libhoney!
|
|
92
|
-
minitest (~> 5.0)
|
|
93
|
-
rake (~> 12.3)
|
|
94
|
-
rubocop (< 0.69)
|
|
95
|
-
sinatra
|
|
96
|
-
sinatra-contrib
|
|
97
|
-
spy
|
|
98
|
-
webmock (~> 3.4)
|
|
99
|
-
yard
|
|
100
|
-
yardstick (~> 0.9)
|
|
101
|
-
|
|
102
|
-
BUNDLED WITH
|
|
103
|
-
2.1.4
|