honeycomb-beeline 0.3.0 → 0.4.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/README.md +31 -21
- data/lib/honeycomb-beeline.rb +6 -0
- data/lib/honeycomb/beeline/version.rb +1 -1
- data/lib/honeycomb/client.rb +68 -26
- data/lib/honeycomb/span.rb +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e21add8b0fa6f602b348665ff15ef2d0c254323da4a7032d5b87affc31b39c4a
|
4
|
+
data.tar.gz: 265cafe498fcaa56d66d9014bccce32df4cbac1aad2ed855f506fdad44dc2640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db0566fdbb0d953efe40d1daf0eb86f8d4e0670afc4a5db4e63ee8ff6c67233d34aee5a0f6bd837810d686537b1310b3dfa9b1aec9dd5361c7cb92b0a8cdb7da
|
7
|
+
data.tar.gz: 59789661ec027435c01a45ee1aa79c9ff31ea8649a52b10cfc75da665076cb9ab0618b6ac92dd1632251ef0f27bea6ff4b3cd0571fe87233ee3871e30b4e45fe
|
data/README.md
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# Honeycomb Beeline for Ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
instruments them to send useful events to Honeycomb.
|
3
|
+
[](https://travis-ci.org/honeycombio/beeline-ruby)
|
4
|
+
[](https://badge.fury.io/rb/honeycomb-beeline)
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
The Honeycomb Beeline for Ruby is an easy way to instrument your Ruby web
|
7
|
+
application for observability. It understands the common packages you use and
|
8
|
+
automatically instruments them to send useful events to
|
9
|
+
[Honeycomb](https://www.honeycomb.io).
|
10
|
+
|
11
|
+
Requires Ruby 2.2 or later. Sign up for a [Honeycomb
|
12
|
+
trial](https://ui.honeycomb.io/signup) to obtain an API key before starting.
|
9
13
|
|
10
14
|
## Installation
|
11
15
|
|
@@ -18,19 +22,19 @@ Now run `bundle install` to install the gem.
|
|
18
22
|
|
19
23
|
## Setup
|
20
24
|
|
21
|
-
In your app's startup script - e.g.
|
22
|
-
|
25
|
+
In your app's startup script - e.g. config.ru or app.rb - add the following
|
26
|
+
code:
|
23
27
|
|
24
28
|
```ruby
|
25
29
|
require 'honeycomb-beeline'
|
26
30
|
|
27
|
-
Honeycomb.init
|
31
|
+
Honeycomb.init # pulls configuration from the environment - see below
|
28
32
|
```
|
29
33
|
|
30
34
|
## Configuration
|
31
35
|
|
32
|
-
You'll need to configure your Honeycomb
|
33
|
-
identify itself to Honeycomb. You can find your
|
36
|
+
You'll need to configure your Honeycomb API key so that your app can
|
37
|
+
identify itself to Honeycomb. You can find your API key on [your Account
|
34
38
|
page](https://ui.honeycomb.io/account).
|
35
39
|
|
36
40
|
You'll also need to configure the name of a dataset in your Honeycomb account to
|
@@ -41,7 +45,7 @@ passing arguments to `Honeycomb.init`:
|
|
41
45
|
|
42
46
|
### Configuration via environment variables
|
43
47
|
|
44
|
-
* `HONEYCOMB_WRITEKEY` - specifies the
|
48
|
+
* `HONEYCOMB_WRITEKEY` - specifies the API key (aka "write key")
|
45
49
|
* `HONEYCOMB_DATASET` - specifies the dataset
|
46
50
|
* `HONEYCOMB_SERVICE` - specifies the name of your app (defaults to the dataset
|
47
51
|
name)
|
@@ -49,11 +53,17 @@ passing arguments to `Honeycomb.init`:
|
|
49
53
|
### Configuration via code
|
50
54
|
|
51
55
|
```ruby
|
52
|
-
Honeycomb.init(
|
56
|
+
Honeycomb.init(
|
57
|
+
writekey: '<MY HONEYCOMB API KEY>',
|
58
|
+
dataset: 'my-app',
|
59
|
+
service_name: 'my-app'
|
60
|
+
)
|
53
61
|
```
|
54
62
|
|
55
|
-
Note that
|
56
|
-
|
63
|
+
Note that Honeycomb API keys have the ability to create and delete data, and
|
64
|
+
should be managed in the same way as your other application secrets. For example
|
65
|
+
you might prefer to configure production API keys via environment variables,
|
66
|
+
rather than checking them into version control.
|
57
67
|
|
58
68
|
## Example questions
|
59
69
|
|
@@ -159,7 +169,8 @@ the listed packages:
|
|
159
169
|
aren't seeing any events for processing web requests, you can install the
|
160
170
|
[middleware](https://www.rubydoc.info/gems/rack-honeycomb) manually: e.g.
|
161
171
|
`use Rack::Honeycomb::Middleware`.
|
162
|
-
* Rails apps
|
172
|
+
* Rails apps should work after installing the middleware as above, but are
|
173
|
+
currently better supported by our dedicated [Rails
|
163
174
|
integration](https://github.com/honeycombio/honeycomb-rails).
|
164
175
|
* Alternative concurrency models such as EventMachine or Celluloid are not
|
165
176
|
currently supported.
|
@@ -197,18 +208,17 @@ detail about what it's doing, you can pass a logger object (compliant with the
|
|
197
208
|
```ruby
|
198
209
|
require 'logger'
|
199
210
|
logger = Logger.new($stderr)
|
200
|
-
logger.level =
|
211
|
+
logger.level = Logger::INFO # determine how much detail you want to see
|
201
212
|
Honeycomb.init(logger: logger)
|
202
213
|
```
|
203
214
|
|
204
|
-
A level of
|
205
|
-
whereas a level of
|
215
|
+
A level of `Logger::DEBUG` will show you detail about each library being instrumented,
|
216
|
+
whereas a level of `Logger::INFO` will just print a few progress messages.
|
206
217
|
|
207
218
|
### Get in touch
|
208
219
|
|
209
220
|
This beeline is still young, so please reach out to
|
210
221
|
[support@honeycomb.io](mailto:support@honeycomb.io) or ping us with the chat
|
211
|
-
bubble on [our website](https://www.honeycomb.io)
|
212
|
-
|
213
|
-
reports](https://github.com/honeycombio/beeline-ruby/issues) and
|
222
|
+
bubble on [our website](https://www.honeycomb.io) for assistance. We also
|
223
|
+
welcome [bug reports](https://github.com/honeycombio/beeline-ruby/issues) and
|
214
224
|
[contributions](https://github.com/honeycombio/beeline-ruby/blob/master/CONTRIBUTING.md).
|
data/lib/honeycomb-beeline.rb
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'libhoney'
|
4
4
|
|
5
|
+
# Namespace for the Honeycomb Beeline.
|
6
|
+
#
|
7
|
+
# Call {.init} to initialize the Honeycomb Beeline at app startup.
|
8
|
+
module Honeycomb
|
9
|
+
end
|
10
|
+
|
5
11
|
require 'honeycomb/client'
|
6
12
|
require 'honeycomb/instrumentations'
|
7
13
|
require 'honeycomb/span'
|
data/lib/honeycomb/client.rb
CHANGED
@@ -10,8 +10,45 @@ module Honeycomb
|
|
10
10
|
|
11
11
|
class << self
|
12
12
|
attr_reader :client
|
13
|
+
attr_reader :logger
|
13
14
|
attr_reader :service_name
|
14
15
|
|
16
|
+
# Initialize the Honeycomb Beeline. You should call this only once, as
|
17
|
+
# early as possible in your app's startup process, to automatically
|
18
|
+
# instrument your app and prepare to send events.
|
19
|
+
#
|
20
|
+
# @example Providing config in code
|
21
|
+
# Honeycomb.init(
|
22
|
+
# writekey: '0123face4567cafe8901beef2345feed',
|
23
|
+
# dataset: 'myapp-development',
|
24
|
+
# service_name: 'myapp'
|
25
|
+
# )
|
26
|
+
# @example Providing config via environment variables
|
27
|
+
# # Assumes environment variables e.g.
|
28
|
+
# # HONEYCOMB_WRITEKEY=0123face4567cafe8901beef2345feed
|
29
|
+
# # HONEYCOMB_DATASET=myapp-development
|
30
|
+
# # HONEYCOMB_SERVICE=myapp
|
31
|
+
#
|
32
|
+
# Honeycomb.init
|
33
|
+
#
|
34
|
+
# @param writekey [String] (required) the Honeycomb API key (aka "write
|
35
|
+
# key") - get yours from your {https://ui.honeycomb.io/account Account
|
36
|
+
# Page}. Can also be specified via the HONEYCOMB_WRITEKEY environment
|
37
|
+
# variable.
|
38
|
+
# @param dataset [String] (required) the name of the Honeycomb
|
39
|
+
# {https://docs.honeycomb.io/getting-data-in/datasets/best-practices/
|
40
|
+
# dataset} your app should send events to. Can also be specified via the
|
41
|
+
# HONEYCOMB_DATASET environment variable.
|
42
|
+
# @param service_name [String] the name of your app, included in all events
|
43
|
+
# your app will send. Defaults to the dataset name if not specified. Can
|
44
|
+
# also be specified via the HONEYCOMB_SERVICE environment variable.
|
45
|
+
# @param debug [Boolean] if true, your app will not send any events to
|
46
|
+
# Honeycomb, but will instead print them to your app's standard error.
|
47
|
+
# It will also log diagnostic messages to standard error.
|
48
|
+
# @param logger [Logger] provide a logger to receive diagnostic messages,
|
49
|
+
# e.g. to override the default logging device or verbosity. By default
|
50
|
+
# warnings and above will be logged to standard error; under normal
|
51
|
+
# operation nothing will be logged.
|
15
52
|
def init(
|
16
53
|
writekey: ENV['HONEYCOMB_WRITEKEY'],
|
17
54
|
dataset: ENV['HONEYCOMB_DATASET'],
|
@@ -42,6 +79,37 @@ module Honeycomb
|
|
42
79
|
@initialized = true
|
43
80
|
end
|
44
81
|
|
82
|
+
# Call at app shutdown to ensure all pending events have been sent to
|
83
|
+
# Honeycomb.
|
84
|
+
def shutdown
|
85
|
+
if defined?(@client) && @client
|
86
|
+
@client.close
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Reset the Beeline to a pristine state, ready to be `.init`ed again.
|
91
|
+
# Intended for testing purposes only.
|
92
|
+
#
|
93
|
+
# @api private
|
94
|
+
def reset
|
95
|
+
# TODO encapsulate all this into a Beeline object so we don't need
|
96
|
+
# explicit cleanup
|
97
|
+
|
98
|
+
shutdown
|
99
|
+
|
100
|
+
@logger = nil
|
101
|
+
@without = nil
|
102
|
+
@service_name = nil
|
103
|
+
@debug = nil
|
104
|
+
@client = nil
|
105
|
+
@initialized = false
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
def after_init_hooks
|
110
|
+
@after_init_hooks ||= []
|
111
|
+
end
|
112
|
+
|
45
113
|
def new_client(options)
|
46
114
|
client = options.delete :client
|
47
115
|
|
@@ -85,32 +153,6 @@ module Honeycomb
|
|
85
153
|
end
|
86
154
|
end
|
87
155
|
|
88
|
-
def shutdown
|
89
|
-
if defined?(@client) && @client
|
90
|
-
@client.close
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
# @api private
|
95
|
-
def reset
|
96
|
-
# TODO encapsulate all this into a Beeline object so we don't need
|
97
|
-
# explicit cleanup
|
98
|
-
|
99
|
-
shutdown
|
100
|
-
|
101
|
-
@logger = nil
|
102
|
-
@without = nil
|
103
|
-
@service_name = nil
|
104
|
-
@debug = nil
|
105
|
-
@client = nil
|
106
|
-
@initialized = false
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
def after_init_hooks
|
111
|
-
@after_init_hooks ||= []
|
112
|
-
end
|
113
|
-
|
114
156
|
def run_hook(label, block)
|
115
157
|
if @without.include?(label)
|
116
158
|
@logger.debug "Skipping hook '#{label}' due to opt-out" if @logger
|
data/lib/honeycomb/span.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
|
3
3
|
module Honeycomb
|
4
|
-
module Span
|
5
|
-
end
|
6
|
-
|
7
4
|
class << self
|
5
|
+
# @api private
|
8
6
|
def with_trace_id(trace_id = SecureRandom.uuid)
|
9
7
|
Thread.current[:honeycomb_trace_id] = trace_id
|
10
8
|
yield trace_id
|
@@ -12,10 +10,12 @@ module Honeycomb
|
|
12
10
|
Thread.current[:honeycomb_trace_id] = nil
|
13
11
|
end
|
14
12
|
|
13
|
+
# @api private
|
15
14
|
def trace_id
|
16
15
|
Thread.current[:honeycomb_trace_id]
|
17
16
|
end
|
18
17
|
|
18
|
+
# @api private
|
19
19
|
def with_span_id(span_id)
|
20
20
|
parent_span_id = Thread.current[:honeycomb_span_id]
|
21
21
|
Thread.current[:honeycomb_span_id] = span_id
|
@@ -24,7 +24,7 @@ module Honeycomb
|
|
24
24
|
Thread.current[:honeycomb_span_id] = parent_span_id
|
25
25
|
end
|
26
26
|
|
27
|
-
#
|
27
|
+
# @api private
|
28
28
|
def span(service_name:, name:, span_id: SecureRandom.uuid)
|
29
29
|
event = client.event
|
30
30
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: honeycomb-beeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Stokes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libhoney
|
@@ -239,7 +239,7 @@ description: |2
|
|
239
239
|
Ruby apps. It understands the common packages you use and automatically
|
240
240
|
instruments them to send useful events to Honeycomb.
|
241
241
|
email:
|
242
|
-
-
|
242
|
+
- support@honeycomb.io
|
243
243
|
executables: []
|
244
244
|
extensions: []
|
245
245
|
extra_rdoc_files: []
|