mnemosyne-ruby 1.1.0 → 1.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
  SHA1:
3
- metadata.gz: d3041b1bd2093674c509a9d037f7fa864a06e669
4
- data.tar.gz: 66714af6d59848f008438c18f2ac3429bdd54f23
3
+ metadata.gz: 9627e0a03b472040c3b65023a44f1e1cea612bf9
4
+ data.tar.gz: f76fea84c479995a59b4151b752af13e6a3a33c5
5
5
  SHA512:
6
- metadata.gz: 0bdb13b855926133b2250c82d607c35d397b744c4f2704deb9e27305067e79a212f66c2ef37f5556e1cbcde0d58c3618203c3fba063d18b7e87cffc851c60d88
7
- data.tar.gz: bcf5d485d708c55b286788c9c8302694bec75cee1b2f2bf30da30d785bc92cd520266586809deb2b9a51df42330572a792cb73c2955524a4ed63a787fec7e7e4
6
+ metadata.gz: 3ad571be34543f3de3437a05c1c9413f8c90be17153af484f0f3b6627c032ec455a73463452278438b44c85bcb3c92aa14800c1c355b0c307fd2e06d53bbc513
7
+ data.tar.gz: 7ed59cb08efd1066173b08b32e2c0cf67c2e80cecbabd3a4fe504e1cb9e304f0f48472cada9cba9209f1f36052e3a7c0a11a2a919832d4b671e98987ebe9c429
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0
4
+
5
+ * Collect response metadata in rack instrumentation
6
+
3
7
  ## 1.1.0
4
8
 
5
9
  * Add metadata to rack instrumentation
data/Gemfile CHANGED
@@ -13,4 +13,5 @@ end
13
13
  group :test do
14
14
  gem 'restify', require: false
15
15
  gem 'sidekiq', require: false
16
+ gem 'webmock', require: false
16
17
  end
@@ -60,27 +60,19 @@ module Mnemosyne
60
60
  ::SecureRandom.uuid
61
61
  end
62
62
 
63
- meta = {
64
- method: env['REQUEST_METHOD'],
65
- path: env['REQUEST_PATH'],
66
- query: env['QUERY_STRING'],
67
- protocol: env['SERVER_PROTOCOL'],
68
- headers: {
69
- 'Accept': env['HTTP_ACCEPT'],
70
- 'Host': env['HTTP_HOST'],
71
- 'User-Agent': env['HTTP_USER_AGENT']
72
- }
73
- }
74
-
75
63
  trace = ::Mnemosyne::Instrumenter.trace 'app.web.request.rack',
76
64
  transaction: transaction,
77
- origin: origin,
78
- meta: meta
65
+ origin: origin
79
66
 
80
67
  if trace
81
68
  trace.start!
82
69
 
70
+ scan_request(trace, env)
71
+
83
72
  response = @app.call env
73
+
74
+ scan_response(trace, response)
75
+
84
76
  response[2] = Proxy.new(response[2]) { trace.submit }
85
77
  response
86
78
  else
@@ -92,6 +84,30 @@ module Mnemosyne
92
84
  ensure
93
85
  trace.release if trace
94
86
  end
87
+
88
+ private
89
+
90
+ def scan_request(trace, env)
91
+ trace.meta[:method] = env['REQUEST_METHOD']
92
+ trace.meta[:path] = env['REQUEST_PATH']
93
+ trace.meta[:query] = env['QUERY_STRING']
94
+ trace.meta[:protocol] = env['SERVER_PROTOCOL']
95
+ trace.meta[:headers] = {
96
+ 'Accept': env['HTTP_ACCEPT'],
97
+ 'Host': env['HTTP_HOST'],
98
+ 'User-Agent': env['HTTP_USER_AGENT']
99
+ }
100
+ end
101
+
102
+ def scan_response(trace, response)
103
+ status, headers, = response
104
+
105
+ trace.meta[:status] = status
106
+
107
+ return unless headers
108
+
109
+ trace.meta[:content_type] = headers['Content-Type']
110
+ end
95
111
  end
96
112
  end
97
113
  end
@@ -6,9 +6,32 @@ module Mnemosyne
6
6
  module Base
7
7
  class Probe < ::Mnemosyne::Probe
8
8
  def setup
9
- require 'mnemosyne/middleware/restify'
9
+ ::Restify::Adapter::Base.prepend Instrumentation
10
+ end
11
+
12
+ module Instrumentation
13
+ def call(request)
14
+ if (trace = ::Mnemosyne::Instrumenter.current_trace)
15
+ meta = {url: request.uri.to_s, method: request.method}
16
+
17
+ span = ::Mnemosyne::Span.new 'external.http.restify', \
18
+ meta: meta
19
+
20
+ span.start!
21
+
22
+ request.headers['X-Mnemosyne-Transaction'] = trace.transaction
23
+ request.headers['X-Mnemosyne-Origin'] = span.uuid
10
24
 
11
- ::Restify::Adapter::Base.prepend ::Mnemosyne::Middleware::Restify
25
+ super.tap do |x|
26
+ x.add_observer do |_, _response, _err|
27
+ span.finish!
28
+ trace << span
29
+ end
30
+ end
31
+ else
32
+ super
33
+ end
34
+ end
12
35
  end
13
36
  end
14
37
  end
@@ -3,7 +3,7 @@
3
3
  module Mnemosyne
4
4
  module VERSION
5
5
  MAJOR = 1
6
- MINOR = 1
6
+ MINOR = 2
7
7
  PATCH = 0
8
8
  STAGE = nil
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mnemosyne-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-26 00:00:00.000000000 Z
11
+ date: 2017-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -133,7 +133,6 @@ files:
133
133
  - lib/mnemosyne/instrumenter.rb
134
134
  - lib/mnemosyne/middleware/acfs.rb
135
135
  - lib/mnemosyne/middleware/rack.rb
136
- - lib/mnemosyne/middleware/restify.rb
137
136
  - lib/mnemosyne/middleware/sidekiq.rb
138
137
  - lib/mnemosyne/probe.rb
139
138
  - lib/mnemosyne/probes.rb
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mnemosyne
4
- module Middleware
5
- module Restify
6
- def call(request)
7
- if (trace = ::Mnemosyne::Instrumenter.current_trace)
8
- meta = {url: request.uri.to_s, method: request.method}
9
-
10
- span = ::Mnemosyne::Span.new('external.http.restify', meta: meta)
11
- span.start!
12
-
13
- request.headers['X-Mnemosyne-Transaction'] = trace.transaction
14
- request.headers['X-Mnemosyne-Origin'] = span.uuid
15
-
16
- super.tap do |x|
17
- x.add_observer do |_, _response, _err|
18
- span.finish!
19
- trace << span
20
- end
21
- end
22
- else
23
- super
24
- end
25
- end
26
- end
27
- end
28
- end