rack-honeycomb 0.0.18 → 0.1.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: d8462b0a0923efce44eddd081ebe87f528cbd23cc1bd9086a5401183adbc9ee1
4
- data.tar.gz: f35eeb477ade70d60e1e059429041fdbb33ff43b026d8f12b9f997159b096d97
3
+ metadata.gz: e14df43e7812c1c6c4943e872d9fc71f653336d46ba04d97e15dcad5c8ef1b55
4
+ data.tar.gz: 58e4a3cb98d1e9ecdcbf4f4175693d0783c175810e317b9dc80f10952abee9d0
5
5
  SHA512:
6
- metadata.gz: 291f4e3801f073249d29d2076f3eeb45a4bfc73aadf8ccddd3dce290055f032228e6ed490a9b47caf82f25ad234c2ae5dbb986d7f63b2a2cee64eadae3e2e333
7
- data.tar.gz: da0269e7f6577d88e86562c445161b0e88ad47b9d018ea4944e1b5c9b17334cbbb1c743d9c6d588945c9ed88bb7f599c0732ac021b875f853479881ebe21be6c
6
+ metadata.gz: 68d18614019d1d0d16a95c8bd09b0a0f137ae7c838ebd2a0377d9c2d4a455a9f330eba458521ebd4fba836b328c89fd5b1aca79c8fcc7fc988a660873fe08ec3
7
+ data.tar.gz: 8fd87ec1879faf03a28e85ece8a27a58de2a8d777f8d1df45ca9c7126c9b962a613cd3f42e8f1082d342a01f217e3df80c6c8a00b491cd499e8651f5ac299a7f
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bump/tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+
5
+ YARD::Rake::YardocTask.new(:doc)
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
@@ -1,19 +1,24 @@
1
1
  require "libhoney"
2
2
 
3
+ require 'rack'
3
4
  require "rack/honeycomb/version"
4
5
 
5
6
  module Rack
6
7
  module Honeycomb
7
- # Prefix for attaching arbitrary metadata to the `env`. Will be deleted from
8
+ # Prefix for attaching custom fields to the `env`. Will be deleted from
8
9
  # the `env` once it's pulled off of the `env` and onto a Honeycomb event.
9
10
  ENV_PREFIX = "honeycomb."
10
11
 
12
+ # Custom fields added via the `env` will be added to the Honeycomb
13
+ # event under this namespace prefix
14
+ APP_FIELD_NAMESPACE = 'app'.freeze
15
+
16
+ RACK_VERSION = ::Rack::VERSION.join('.').freeze
17
+
11
18
  class Middleware
12
19
  ENV_REGEX = /^#{ Regexp.escape ENV_PREFIX }/
13
20
  USER_AGENT_SUFFIX = "rack-honeycomb/#{VERSION}"
14
-
15
- attr_reader :app
16
- attr_reader :options
21
+ EVENT_TYPE = 'http_request'.freeze
17
22
 
18
23
  ##
19
24
  # @param [#call] app
@@ -24,88 +29,88 @@ module Rack
24
29
  def initialize(app, options = {})
25
30
  @app, @options = app, options
26
31
 
27
- @honeycomb = if client = options.delete(:client)
32
+ honeycomb = if client = options.delete(:client)
28
33
  client
29
34
  elsif defined?(::Honeycomb.client)
30
35
  ::Honeycomb.client
31
36
  else
32
37
  Libhoney::Client.new(options.merge(user_agent_addition: USER_AGENT_SUFFIX))
33
38
  end
39
+ @builder = honeycomb.builder.
40
+ add(
41
+ 'meta.package' => 'rack',
42
+ 'meta.package_version' => RACK_VERSION,
43
+ 'type' => EVENT_TYPE,
44
+ 'local_hostname' => Socket.gethostname,
45
+ )
34
46
 
35
47
  @service_name = options.delete(:service_name) || :rack
36
48
  end
37
49
 
38
- def add_field(ev, field, value)
39
- ev.add_field(field, value) if value != nil && value != ''
40
- end
50
+ def call(env)
51
+ ev = @builder.event
41
52
 
42
- def add_env(ev, env, field)
43
- add_field(ev, field, env[field])
44
- end
53
+ add_request_fields(ev, env)
45
54
 
46
- def call(env)
47
- ev = @honeycomb.event
48
- request_started_at = Time.now
49
- status, headers, response = adding_span_metadata_if_available(ev, env) do
55
+ start = Time.now
56
+ status, headers, body = adding_span_metadata_if_available(ev, env) do
50
57
  @app.call(env)
51
58
  end
52
- request_ended_at = Time.now
53
59
 
54
- ev.add(headers)
55
- if headers['Content-Length'] != nil
56
- # Content-Length (if present) is a string. let's change it to an int.
57
- ev.add_field('Content-Length', headers['Content-Length'].to_i)
58
- end
59
- add_field(ev, 'HTTP_STATUS', status)
60
- add_field(ev, 'durationMs', (request_ended_at - request_started_at) * 1000)
60
+ add_app_fields(ev, env)
61
61
 
62
- # Pull arbitrary metadata off `env` if the caller attached anything
63
- # inside the Rack handler.
64
- env.each_pair do |k, v|
65
- if k.is_a?(String) && k.match(ENV_REGEX)
66
- add_field(ev, k.sub(ENV_REGEX, ''), v)
67
- env.delete(k)
68
- end
69
- end
62
+ add_response_fields(ev, status, headers, body)
70
63
 
71
- # we can't use `ev.add(env)` because json serialization fails.
72
- # pull out some interesting and potentially useful fields.
73
- add_env(ev, env, 'rack.version')
74
- add_env(ev, env, 'rack.multithread')
75
- add_env(ev, env, 'rack.multiprocess')
76
- add_env(ev, env, 'rack.run_once')
77
- add_env(ev, env, 'SCRIPT_NAME')
78
- add_env(ev, env, 'QUERY_STRING')
79
- add_env(ev, env, 'SERVER_PROTOCOL')
80
- add_env(ev, env, 'SERVER_SOFTWARE')
81
- add_env(ev, env, 'GATEWAY_INTERFACE')
82
- add_env(ev, env, 'REQUEST_METHOD')
83
- add_env(ev, env, 'REQUEST_PATH')
84
- add_env(ev, env, 'REQUEST_URI')
85
- add_env(ev, env, 'HTTP_VERSION')
86
- add_env(ev, env, 'HTTP_HOST')
87
- add_env(ev, env, 'HTTP_CONNECTION')
88
- add_env(ev, env, 'HTTP_CACHE_CONTROL')
89
- add_env(ev, env, 'HTTP_UPGRADE_INSECURE_REQUESTS')
90
- add_env(ev, env, 'HTTP_USER_AGENT')
91
- add_env(ev, env, 'HTTP_ACCEPT')
92
- add_env(ev, env, 'HTTP_ACCEPT_LANGUAGE')
93
- add_env(ev, env, 'REMOTE_ADDR')
94
-
95
- [status, headers, response]
64
+ [status, headers, body]
96
65
  rescue Exception => e
97
66
  if ev
98
- ev.add_field('exception_class', e.class.name)
99
- ev.add_field('exception_message', e.message)
67
+ ev.add_field('request.error', e.class.name)
68
+ ev.add_field('request.error_detail', e.message)
100
69
  end
101
70
  raise
102
71
  ensure
103
- if ev
72
+ if ev && start
73
+ finish = Time.now
74
+ ev.add_field('duration_ms', (finish - start) * 1000)
75
+
104
76
  ev.send
105
77
  end
106
78
  end
107
79
 
108
80
  private
81
+ def add_request_fields(event, env)
82
+ event.add_field('name', "#{env['REQUEST_METHOD']} #{env['PATH_INFO']}")
83
+
84
+ event.add_field('request.method', env['REQUEST_METHOD'])
85
+ event.add_field('request.path', env['PATH_INFO'])
86
+ event.add_field('request.protocol', env['rack.url_scheme'])
87
+
88
+ if env['QUERY_STRING'] && !env['QUERY_STRING'].empty?
89
+ event.add_field('request.query_string', env['QUERY_STRING'])
90
+ end
91
+
92
+ event.add_field('request.http_version', env['HTTP_VERSION'])
93
+ event.add_field('request.host', env['HTTP_HOST'])
94
+ event.add_field('request.remote_addr', env['REMOTE_ADDR'])
95
+ event.add_field('request.header.user_agent', env['HTTP_USER_AGENT'])
96
+ end
97
+
98
+ def add_app_fields(event, env)
99
+ # Pull arbitrary metadata off `env` if the caller attached
100
+ # anything inside the Rack handler.
101
+ env.each_pair do |k, v|
102
+ if k.is_a?(String) && k.match(ENV_REGEX)
103
+ namespaced_k = "#{APP_FIELD_NAMESPACE}.#{k.sub(ENV_REGEX, '')}"
104
+ event.add_field(namespaced_k, v)
105
+ env.delete(k)
106
+ end
107
+ end
108
+ end
109
+
110
+ def add_response_fields(event, status, headers, body)
111
+ event.add_field('response.status_code', status)
112
+ end
113
+
109
114
  def adding_span_metadata_if_available(event, env)
110
115
  return yield unless defined?(::Honeycomb.with_trace_id)
111
116
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Honeycomb
3
- VERSION="0.0.18"
3
+ VERSION="0.1.0"
4
4
  end
5
5
  end
@@ -31,11 +31,9 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "bump"
32
32
  spec.add_development_dependency "bundler", "~> 1.7"
33
33
  spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "webmock", "~> 2.1"
35
- spec.add_development_dependency "minitest", "~> 5.0"
36
- spec.add_development_dependency "yardstick", "~> 0.9"
37
34
  spec.add_development_dependency 'rack', '>= 1.0.0'
38
35
  spec.add_runtime_dependency 'libhoney', '>= 1.5.0'
36
+ spec.add_development_dependency 'rspec'
39
37
  spec.add_development_dependency 'rack-test'
40
38
  spec.add_development_dependency 'yard'
41
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-honeycomb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Honeycomb.io Team
@@ -53,75 +53,47 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: webmock
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.1'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.1'
69
- - !ruby/object:Gem::Dependency
70
- name: minitest
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '5.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '5.0'
83
- - !ruby/object:Gem::Dependency
84
- name: yardstick
56
+ name: rack
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
- - - "~>"
59
+ - - ">="
88
60
  - !ruby/object:Gem::Version
89
- version: '0.9'
61
+ version: 1.0.0
90
62
  type: :development
91
63
  prerelease: false
92
64
  version_requirements: !ruby/object:Gem::Requirement
93
65
  requirements:
94
- - - "~>"
66
+ - - ">="
95
67
  - !ruby/object:Gem::Version
96
- version: '0.9'
68
+ version: 1.0.0
97
69
  - !ruby/object:Gem::Dependency
98
- name: rack
70
+ name: libhoney
99
71
  requirement: !ruby/object:Gem::Requirement
100
72
  requirements:
101
73
  - - ">="
102
74
  - !ruby/object:Gem::Version
103
- version: 1.0.0
104
- type: :development
75
+ version: 1.5.0
76
+ type: :runtime
105
77
  prerelease: false
106
78
  version_requirements: !ruby/object:Gem::Requirement
107
79
  requirements:
108
80
  - - ">="
109
81
  - !ruby/object:Gem::Version
110
- version: 1.0.0
82
+ version: 1.5.0
111
83
  - !ruby/object:Gem::Dependency
112
- name: libhoney
84
+ name: rspec
113
85
  requirement: !ruby/object:Gem::Requirement
114
86
  requirements:
115
87
  - - ">="
116
88
  - !ruby/object:Gem::Version
117
- version: 1.5.0
118
- type: :runtime
89
+ version: '0'
90
+ type: :development
119
91
  prerelease: false
120
92
  version_requirements: !ruby/object:Gem::Requirement
121
93
  requirements:
122
94
  - - ">="
123
95
  - !ruby/object:Gem::Version
124
- version: 1.5.0
96
+ version: '0'
125
97
  - !ruby/object:Gem::Dependency
126
98
  name: rack-test
127
99
  requirement: !ruby/object:Gem::Requirement
@@ -157,11 +129,13 @@ extensions: []
157
129
  extra_rdoc_files: []
158
130
  files:
159
131
  - ".gitignore"
132
+ - ".rspec"
160
133
  - ".travis.yml"
161
134
  - CONTRIBUTORS
162
135
  - Gemfile
163
136
  - LICENSE
164
137
  - README.md
138
+ - Rakefile
165
139
  - lib/rack-honeycomb.rb
166
140
  - lib/rack-honeycomb/auto_install.rb
167
141
  - lib/rack/honeycomb.rb