honeycomb-beeline 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ee35a2e5343568aa60e59d26e6a8b6cf390b24c
4
+ data.tar.gz: afbc1a425601869194ca72ff59a3ef0271c5f896
5
+ SHA512:
6
+ metadata.gz: b4b42d2928d1b1342ab25c85cfeea3a393efa8e906a4c6e80cf882842e7b369241ce87df3a99badb21b8cbe635f64426f358b10f6c72f932579861ecb2544ab5
7
+ data.tar.gz: 0f8304a7321454ae1282f537e9e4ada27e4bdfc08399bef34ba53da1d366f042b63f5ca5875d4c8ea6af645a5ac83919abca0da787bd16556afde5808ea8a539
@@ -0,0 +1,13 @@
1
+ # Main entrypoint for the 'honeycomb-beeline' gem (see also
2
+ # lib/honeycomb-beeline/automagic.rb for an alternative entrypoint).
3
+
4
+ require 'libhoney'
5
+
6
+ require 'honeycomb/client'
7
+ require 'honeycomb/span'
8
+
9
+ require 'activerecord-honeycomb'
10
+ require 'faraday-honeycomb'
11
+
12
+ module Honeycomb
13
+ end
@@ -0,0 +1,48 @@
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
@@ -0,0 +1,6 @@
1
+ module Honeycomb
2
+ module Beeline
3
+ GEM_NAME = 'honeycomb-beeline'
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
@@ -0,0 +1,60 @@
1
+ require 'honeycomb/beeline/version'
2
+
3
+ module Honeycomb
4
+ USER_AGENT_SUFFIX = "#{Beeline::GEM_NAME}/#{Beeline::VERSION}"
5
+
6
+ class << self
7
+ attr_reader :client
8
+
9
+ def init(writekey:, dataset:, logger: nil, without: [], **options)
10
+ options = options.merge(writekey: writekey, dataset: dataset)
11
+ @logger = logger
12
+ @without = without
13
+ options = {user_agent_addition: USER_AGENT_SUFFIX}.merge(options)
14
+ @client = Libhoney::Client.new(options)
15
+
16
+ after_init_hooks.each do |label, block|
17
+ @logger.debug "Running hook '#{label}' after Honeycomb.init" if @logger
18
+ run_hook(label, block)
19
+ end
20
+ end
21
+
22
+ def after_init(label, &block)
23
+ raise ArgumentError unless block_given?
24
+
25
+ hook = if block.arity == 0
26
+ ->(_) { block.call }
27
+ elsif block.arity > 1
28
+ raise ArgumentError, 'Honeycomb.after_init block should take 1 argument'
29
+ else
30
+ block
31
+ end
32
+
33
+ if @initialized
34
+ @logger.debug "Running hook '#{label}' as Honeycomb already initialized" if @logger
35
+ run_hook(label, hook)
36
+ else
37
+ after_init_hooks << [label, hook]
38
+ end
39
+ end
40
+
41
+ private
42
+ def after_init_hooks
43
+ @after_init_hooks ||= []
44
+ end
45
+
46
+ def run_hook(label, block)
47
+ if @without.include?(label)
48
+ @logger.debug "Skipping hook '#{label}' due to opt-out" if @logger
49
+ else
50
+ block.call @client
51
+ end
52
+ rescue => e
53
+ warn "Honeycomb.init hook '#{label}' raised #{e.class}: #{e}"
54
+ end
55
+ end
56
+
57
+ after_init :log do
58
+ @logger.info "Honeycomb inited" if @logger
59
+ end
60
+ end
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,55 @@
1
+ require 'securerandom'
2
+
3
+ module Honeycomb
4
+ module Span
5
+ end
6
+
7
+ class << self
8
+ def with_trace_id(trace_id = SecureRandom.uuid)
9
+ Thread.current[:honeycomb_trace_id] = trace_id
10
+ yield trace_id
11
+ ensure
12
+ Thread.current[:honeycomb_trace_id] = nil
13
+ end
14
+
15
+ def trace_id
16
+ Thread.current[:honeycomb_trace_id]
17
+ end
18
+
19
+ def with_span_id(span_id)
20
+ parent_span_id = Thread.current[:honeycomb_span_id]
21
+ Thread.current[:honeycomb_span_id] = span_id
22
+ yield parent_span_id
23
+ ensure
24
+ Thread.current[:honeycomb_span_id] = parent_span_id
25
+ end
26
+
27
+ def span(service_name:, name:, span_id: SecureRandom.uuid)
28
+ event = client.event
29
+
30
+ event.add_field :traceId, trace_id if trace_id
31
+ event.add_field :serviceName, service_name
32
+ event.add_field :name, name
33
+ event.add_field :id, span_id
34
+
35
+ start = Time.now
36
+ with_span_id(span_id) do |parent_span_id|
37
+ event.add_field :parentId, parent_span_id if parent_span_id
38
+ yield
39
+ end
40
+ rescue Exception => e
41
+ if event
42
+ event.add_field :exception_class, e.class.name
43
+ event.add_field :exception_message, e.message
44
+ end
45
+ raise
46
+ ensure
47
+ if start && event
48
+ finish = Time.now
49
+ duration = finish - start
50
+ event.add_field :durationMs, duration * 1000
51
+ event.send
52
+ end
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: honeycomb-beeline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sam Stokes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: libhoney
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord-honeycomb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-honeycomb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday-honeycomb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sequel-honeycomb
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bump
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: " TO DO *is* a description\n"
140
+ email:
141
+ - sam@honeycomb.io
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - lib/honeycomb-beeline.rb
147
+ - lib/honeycomb-beeline/auto_install.rb
148
+ - lib/honeycomb/beeline/version.rb
149
+ - lib/honeycomb/client.rb
150
+ - lib/honeycomb/env_config.rb
151
+ - lib/honeycomb/span.rb
152
+ homepage: https://github.com/honeycombio/beeline-ruby
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.6.11
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Instrument your Ruby apps with Honeycomb
176
+ test_files: []