honeycomb-beeline 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 933f23233b9babc6adafa6eddc7292925f6fecbd68cba8de60a77591bb14667a
4
- data.tar.gz: 7a82833864990c92193ca8066a91a48143ef78440b01c723d238ad6f95397d9f
3
+ metadata.gz: d8226a2444f449e489670d844e544ec8986ff40b32016ae9199031ae2fef1df8
4
+ data.tar.gz: 11e5d5f9dc8dcc000e6a4cdb5dbebd35f0fe332c9ff5ab0a85f4b084f428f7bd
5
5
  SHA512:
6
- metadata.gz: 5eac3fe8bb20f0094c0e649bde8661e01fbcb950701f610373916aca9abeed3c8b0660dbf4ee6b2172f8376452d48a1f6532986c573cdb3ad00597c157471203
7
- data.tar.gz: 9228ef70a625b7f0691e497335ffed7b9a0bb4f4537b283a3e059d35a57210c19fff9207eaa8dc29c73b67631b93b21abddc8a72a32b17afcf7ace2f9db7c933
6
+ metadata.gz: 5370b82bf792605cf79bcf67a5930a0430f498e84f0472e5046b3a027d52761d0fbc3410b21374a2fc32c61beb20738defa47db30a80a650b9ede888b09bc13a
7
+ data.tar.gz: c70d4cd7b0ea59c6642286db68b38bd0c637715e5468bfa096c8684486d93bcbebb0b7b037be01bb440f10c645199465a6500dfd54ab62fb602e467dea017a46
data/README.md CHANGED
@@ -6,58 +6,19 @@ instruments them to send useful events to Honeycomb.
6
6
 
7
7
  ## Setup
8
8
 
9
- Setup requires minimal changes to your app, but the approach depends on how your
10
- app loads gems at startup.
11
-
12
- ### Automatic setup for apps that call `Bundler.require`
13
-
14
- If your app calls `Bundler.require` at startup (you can verify by running `git
15
- grep 'Bundler\.require'`) then setup just requires adding one line to your
16
- Gemfile:
17
-
18
- ```ruby
19
- gem 'honeycomb-beeline', require: 'honeycomb-beeline/auto_install'
20
- ```
21
-
22
- Now run `bundle install` to install the gem.
23
-
24
- ### Automatic setup for other apps
25
-
26
- If your app does not call `Bundler.require` at startup (you can verify by
27
- running `git grep 'Bundler\.require'`) then you'll need to make two changes.
28
- First add this line to your Gemfile:
29
-
30
- ```ruby
31
- gem 'honeycomb-beeline'
32
- ```
33
-
34
- Then require the gem somewhere in your app's startup script - e.g. for a Rack app
35
- add it to your "config.ru":
36
-
37
- ```ruby
38
- require 'honeycomb-beeline/auto_install'
39
- ```
40
-
41
- Now run `bundle install` to install the gem.
42
-
43
- ### Manual setup
44
-
45
- If the automatic setup doesn't work for your app, or you prefer to choose which
46
- libraries to instrument, then you'll need to call `Honeycomb.init` manually.
47
-
48
- First add this line to your Gemfile:
9
+ Setup requires minimal changes to your app. First add this line to your Gemfile:
49
10
 
50
11
  ```ruby
51
12
  gem 'honeycomb-beeline'
52
13
  ```
53
14
 
54
- Then require and init the gem somewhere in your app's startup script - e.g. for
55
- a Rack app add it to your "config.ru":
15
+ Then in your app's startup script - e.g. for a Rack app "config.ru" is a good
16
+ place - add the following code:
56
17
 
57
18
  ```ruby
58
19
  require 'honeycomb-beeline'
59
20
 
60
- Honeycomb.init(writekey: '<MY HONEYCOMB WRITEKEY>', dataset: 'my-app')
21
+ Honeycomb.init
61
22
  ```
62
23
 
63
24
  Now run `bundle install` to install the gem.
@@ -68,17 +29,18 @@ You'll need to configure your Honeycomb writekey so that your app can
68
29
  identify itself to Honeycomb. You can find your writekey on [your Account
69
30
  page](https://ui.honeycomb.io/account).
70
31
 
71
- You can also configure which dataset in your Honeycomb account to send events
72
- to. If you don't, the gem will guess the dataset name based on the name of the
73
- current directory.
32
+ You'll also need to configure the name of a dataset in your Honeycomb account to
33
+ send events to. The name of your app is a good choice.
74
34
 
75
35
  You can specify the configuration either via environment variables, or by
76
- calling `Honeycomb.init` explicitly:
36
+ passing arguments to `Honeycomb.init`:
77
37
 
78
38
  ### Configuration via environment variables
79
39
 
80
40
  * `HONEYCOMB_WRITEKEY` - specifies the writekey
81
41
  * `HONEYCOMB_DATASET` - specifies the dataset
42
+ * `HONEYCOMB_SERVICE` - specifies the name of your app (defaults to the dataset
43
+ name)
82
44
 
83
45
  ### Configuration via code
84
46
 
@@ -86,6 +48,9 @@ calling `Honeycomb.init` explicitly:
86
48
  Honeycomb.init(writekey: '<MY HONEYCOMB WRITEKEY>', dataset: 'my-app')
87
49
  ```
88
50
 
51
+ Note that you should not check your Honeycomb writekey into version control, as
52
+ it is sensitive and allows sending data to your Honeycomb account.
53
+
89
54
  ## Development
90
55
 
91
56
  ### Releasing a new version
@@ -1,13 +1,7 @@
1
- # Main entrypoint for the 'honeycomb-beeline' gem (see also
2
- # lib/honeycomb-beeline/automagic.rb for an alternative entrypoint).
1
+ # Main entrypoint for the 'honeycomb-beeline' gem.
3
2
 
4
3
  require 'libhoney'
5
4
 
6
5
  require 'honeycomb/client'
6
+ require 'honeycomb/instrumentations'
7
7
  require 'honeycomb/span'
8
-
9
- require 'activerecord-honeycomb'
10
- require 'faraday-honeycomb'
11
-
12
- module Honeycomb
13
- end
@@ -1,6 +1,6 @@
1
1
  module Honeycomb
2
2
  module Beeline
3
3
  GEM_NAME = 'honeycomb-beeline'
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
6
6
  end
@@ -1,4 +1,7 @@
1
1
  require 'honeycomb/beeline/version'
2
+
3
+ require 'libhoney'
4
+
2
5
  require 'socket'
3
6
 
4
7
  module Honeycomb
@@ -6,8 +9,18 @@ module Honeycomb
6
9
 
7
10
  class << self
8
11
  attr_reader :client
12
+ attr_reader :service_name
13
+
14
+ def init(
15
+ writekey: ENV['HONEYCOMB_WRITEKEY'],
16
+ dataset: ENV['HONEYCOMB_DATASET'],
17
+ service_name: ENV['HONEYCOMB_SERVICE'] || dataset,
18
+ without: [],
19
+ logger: nil,
20
+ **options
21
+ )
22
+ reset
9
23
 
10
- def init(writekey: nil, dataset: nil, service_name: dataset, logger: nil, without: [], **options)
11
24
  @logger = logger
12
25
  @without = without
13
26
  @service_name = service_name
@@ -19,22 +32,24 @@ module Honeycomb
19
32
  @logger.debug "Running hook '#{label}' after Honeycomb.init" if @logger
20
33
  run_hook(label, block)
21
34
  end
35
+
36
+ @initialized = true
22
37
  end
23
38
 
24
39
  def new_client(options)
25
- @client = options.delete :client
40
+ client = options.delete :client
26
41
 
27
42
  options = {user_agent_addition: USER_AGENT_SUFFIX}.merge(options)
28
- @client ||= begin
43
+ client ||= begin
29
44
  unless options[:writekey] && options[:dataset]
30
45
  raise ArgumentError, "must specify writekey and dataset"
31
46
  end
32
47
  Libhoney::Client.new(options)
33
48
  end
34
- @client.add_field 'meta.beeline_version', Beeline::VERSION
35
- @client.add_field 'meta.local_hostname', Socket.gethostname rescue nil
36
- @client.add_field 'service_name', @service_name
37
- @client
49
+ client.add_field 'meta.beeline_version', Beeline::VERSION
50
+ client.add_field 'meta.local_hostname', Socket.gethostname rescue nil
51
+ client.add_field 'service_name', @service_name
52
+ client
38
53
  end
39
54
 
40
55
  def after_init(label, &block)
@@ -48,7 +63,7 @@ module Honeycomb
48
63
  block
49
64
  end
50
65
 
51
- if @initialized
66
+ if defined?(@initialized)
52
67
  @logger.debug "Running hook '#{label}' as Honeycomb already initialized" if @logger
53
68
  run_hook(label, hook)
54
69
  else
@@ -56,6 +71,26 @@ module Honeycomb
56
71
  end
57
72
  end
58
73
 
74
+ def shutdown
75
+ if defined?(@client) && @client
76
+ @client.close
77
+ end
78
+ end
79
+
80
+ # @api private
81
+ def reset
82
+ # TODO encapsulate all this into a Beeline object so we don't need
83
+ # explicit cleanup
84
+
85
+ shutdown
86
+
87
+ @logger = nil
88
+ @without = nil
89
+ @service_name = nil
90
+ @client = nil
91
+ @initialized = false
92
+ end
93
+
59
94
  private
60
95
  def after_init_hooks
61
96
  @after_init_hooks ||= []
@@ -0,0 +1,25 @@
1
+ require 'honeycomb/client'
2
+
3
+ require 'activerecord-honeycomb/auto_install'
4
+ require 'faraday-honeycomb/auto_install'
5
+ require 'rack-honeycomb/auto_install'
6
+ require 'sequel-honeycomb/auto_install'
7
+
8
+ module Honeycomb
9
+ INSTRUMENTATIONS = [
10
+ ActiveRecord::Honeycomb,
11
+ Faraday::Honeycomb,
12
+ Rack::Honeycomb,
13
+ Sequel::Honeycomb,
14
+ ].freeze
15
+
16
+ INSTRUMENTATIONS.each do |instrumentation|
17
+ auto = instrumentation::AutoInstall
18
+ if auto.available?
19
+ hook_label = instrumentation.name.sub(/::Honeycomb$/, '').downcase.to_sym
20
+ after_init(hook_label) do |client|
21
+ auto.auto_install!(honeycomb_client: client, logger: @logger)
22
+ end
23
+ end
24
+ end
25
+ end
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.1.0
4
+ version: 0.2.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-05-24 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libhoney
@@ -246,10 +246,9 @@ extra_rdoc_files: []
246
246
  files:
247
247
  - README.md
248
248
  - lib/honeycomb-beeline.rb
249
- - lib/honeycomb-beeline/auto_install.rb
250
249
  - lib/honeycomb/beeline/version.rb
251
250
  - lib/honeycomb/client.rb
252
- - lib/honeycomb/env_config.rb
251
+ - lib/honeycomb/instrumentations.rb
253
252
  - lib/honeycomb/span.rb
254
253
  homepage: https://github.com/honeycombio/beeline-ruby
255
254
  licenses:
@@ -1,48 +0,0 @@
1
- # Alternative entrypoint for the 'honeycomb-beeline' gem that detects libraries
2
- # we can instrument and automagically instrument them.
3
-
4
- require 'libhoney'
5
-
6
- require 'honeycomb/client'
7
- require 'honeycomb/span'
8
-
9
- require 'activerecord-honeycomb/auto_install'
10
- require 'faraday-honeycomb/auto_install'
11
- require 'rack-honeycomb/auto_install'
12
- require 'sequel-honeycomb/auto_install'
13
-
14
- require 'honeycomb/env_config'
15
-
16
- module Honeycomb
17
- module Beeline
18
- LOGGER = if Honeycomb::DEBUG
19
- require 'logger'
20
- Logger.new($stderr).tap do |l|
21
- l.level = Logger::Severity.const_get(Honeycomb::DEBUG)
22
- end
23
- end
24
-
25
- INSTRUMENTATIONS = [
26
- ActiveRecord::Honeycomb,
27
- Faraday::Honeycomb,
28
- Rack::Honeycomb,
29
- Sequel::Honeycomb,
30
- ].freeze
31
-
32
- INSTRUMENTATIONS.each do |instrumentation|
33
- auto = instrumentation::AutoInstall
34
- if auto.available?(logger: LOGGER)
35
- hook_label = instrumentation.name.sub(/::Honeycomb$/, '').downcase.to_sym
36
- Honeycomb.after_init(hook_label) do |client|
37
- auto.auto_install!(honeycomb_client: client, logger: LOGGER)
38
- end
39
- else
40
- LOGGER.debug "Not autoinitialising #{instrumentation.name}" if LOGGER
41
- end
42
- end
43
- end
44
- end
45
-
46
- if Honeycomb::ENV_CONFIG
47
- Honeycomb.init(logger: Honeycomb::Beeline::LOGGER, **Honeycomb::ENV_CONFIG)
48
- end
@@ -1,17 +0,0 @@
1
- module Honeycomb
2
- ENV_CONFIG = begin
3
- writekey = ENV['HONEYCOMB_WRITEKEY']
4
- dataset = ENV['HONEYCOMB_DATASET'] || ENV['PWD'].split('/').last
5
-
6
- withouts = ENV['HONEYCOMB_WITHOUT'] || ''
7
- without = withouts.split(',').map(&:to_sym)
8
-
9
- if writekey
10
- {writekey: writekey, dataset: dataset, without: without}.freeze
11
- end
12
- end
13
-
14
- DEBUG = if ENV.key?('HONEYCOMB_DEBUG')
15
- ENV['HONEYCOMB_DEBUG'].upcase.to_sym
16
- end
17
- end