moesif_rack 1.0.3 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f51cfc0456d2c898d431068cd68005dc755fcca2
4
- data.tar.gz: 43fb1009abcf3c9a9f505cc6278a974c6c5c0a17
3
+ metadata.gz: 5ed5bc8ec291e937b9bcb0bcf51718eb50bb52e9
4
+ data.tar.gz: b1a58fcde2a75a2e66c98b880d7c11950c19ff38
5
5
  SHA512:
6
- metadata.gz: 61d38475fcfa488153cab0726cdfc776d459cfc67709b66f12644d279db370abe124f2157e4d687e8512a1c03ffaf76d5854ff0752632b09b318937d81d2f1cb
7
- data.tar.gz: 30111231d1298b6e99ed2cdd07c44d77c0727f381b42b5fe9eabd678f3f3a4cbe4986a3dfe26d2bb83ec6a34b3138636261c307f2b3bbb4474d5afbe45c659d9
6
+ metadata.gz: 78a04e6c691d1159e4663d40fbc56f1567c762ea850e3e36d6bd67996b361801bc8ab26556a1279d66f32497034d5f0be0ed1287ace7790bf521f901a8a1d5c6
7
+ data.tar.gz: 55cc196b84495efa264e3ade047ebe4ada5c1628cfebd1e2d14a7e01d53ea9aa86c87a3a8ae50257b82e26c2b5102104a936132efccfda8319d7ef7893ca5851
data/README.md CHANGED
@@ -1,23 +1,27 @@
1
- Moesif Middleware for Ruby on Rails and Rack
2
- =============================================
1
+ # Moesif Middleware for Ruby on Rails and Rack
3
2
 
4
- Middleware that logs APIs built on Ruby on Rails and Rack.
3
+ Rack Middleware that logs _incoming_ API calls to Moesif for advanced error analysis for apps built on Ruby on Rails / Rack.
5
4
 
6
5
  [Source Code on GitHub](https://github.com/moesif/moesif-rack)
7
6
 
8
- __Check out Moesif's
9
- [Ruby developer documentation](https://www.moesif.com/developer-documentation/?ruby) to learn more__
7
+ [Ruby Gem](https://rubygems.org/gems/moesif_rack)
10
8
 
11
- Install from RubyGems
12
- =====================
9
+ ## How to install
13
10
 
14
11
  ```bash
15
12
  gem install moesif_rack
16
13
  ```
17
- How to use:
18
- ===========
19
14
 
20
- Create the options
15
+ and if you have a `Gemfile` in your project, please add this line to
16
+
17
+ ```
18
+ gem 'moesif_rack', '~> 1.1.0'
19
+
20
+ ```
21
+
22
+ ## How to use
23
+
24
+ ### Create the options
21
25
 
22
26
  ```ruby
23
27
  moesif_options = {
@@ -25,8 +29,9 @@ moesif_options = {
25
29
  }
26
30
  ```
27
31
 
28
- Add to Middleware
32
+ You can find your Application Id from [_Moesif Dashboard_](https://www.moesif.com/) -> _Top Right Menu_ -> _App Setup_
29
33
 
34
+ ### Add to middleware
30
35
 
31
36
  within `config/application.rb`
32
37
 
@@ -43,24 +48,44 @@ within `config/application.rb`
43
48
 
44
49
  ```
45
50
 
51
+ #### Order of Middleware Matters
52
+
53
+ Since Moesif Rack is basically a logging middleware, the ordering of middleware matters for accuracy and completeness.
54
+ Many middleware are installed by default by rails.
55
+
56
+ To see the list of the middleware that your system already have, type this into the bash.
57
+
58
+ ```bash
59
+ bin/rails middleware
60
+ ```
61
+
62
+ The best place for MoesifMidleware is on top as possible (so it captures the data closest to the wire).
63
+ Typically, right above the default logger of Rails apps, "Rails::Rack::Logger" is a good spot.
64
+
65
+ You should use the following line of code to insert the middleware into the right spot.
66
+
67
+ ```ruby
68
+
69
+ config.middleware.insert_before "Rails::Rack::Logger", "MoesifRack::MoesifMiddleware", moesif_options
46
70
 
47
- How to configure:
48
- =================
71
+ ```
49
72
 
50
- options is a hash with these possible key value pairs.
73
+ ## Configuration options
51
74
 
52
- #### application_id
75
+ The options is a hash with these possible key value pairs.
76
+
77
+ #### __`application_id`__
53
78
 
54
79
  Required. String. This is the Moesif application_id under settings
55
80
  from your [Moesif account.](https://www.moesif.com)
56
81
 
57
82
 
58
- #### api_version
83
+ #### __`api_version`__
59
84
 
60
85
  Optional. String. Tag requests with the version of your API.
61
86
 
62
87
 
63
- #### identify_user
88
+ #### __`identify_user`__
64
89
 
65
90
  Optional.
66
91
  identify_user is a Proc that takes env, headers, and body as arguments and returns a user_id string. This helps us attribute requests to unique users. Even though Moesif can automatically retrieve the user_id without this, this is highly recommended to ensure accurate attribution.
@@ -76,7 +101,7 @@ moesif_options['identify_user'] = Proc.new { |env, headers, body|
76
101
 
77
102
  ```
78
103
 
79
- #### identify_session
104
+ #### __`identify_session`__
80
105
 
81
106
  Optional. A Proc that takes env, headers, body and returns a string.
82
107
 
@@ -91,7 +116,7 @@ moesif_options['identify_session'] = Proc.new { |env, headers, body|
91
116
 
92
117
  ```
93
118
 
94
- #### mask_data
119
+ #### __`mask_data`__
95
120
 
96
121
  Optional. A Proc that takes event_model as an argument and returns event_model.
97
122
  With mask_data, you can make modifications to headers or body of the event before it is sent to Moesif.
@@ -109,7 +134,7 @@ moesif_options['mask_data'] = Proc.new { |event_model|
109
134
 
110
135
  For details for the spec of event model, please see the [moesifapi-ruby git](https://github.com/Moesif/moesifapi-ruby)
111
136
 
112
- #### skip
137
+ #### __`skip`__
113
138
 
114
139
  Optional. A Proc that takes env, headers, body and returns a boolean.
115
140
 
@@ -124,11 +149,14 @@ moesif_options['skip'] = Proc.new { |env, headers, body|
124
149
 
125
150
  ```
126
151
 
127
- For details for the spec of event model, please see the [moesifapi-ruby git](https://github.com/Moesif/moesifapi-ruby)
152
+ For details for the spec of event model, please see the [Moesif Ruby API Documentation](https://www.moesif.com/docs/api?ruby)
128
153
 
129
154
 
155
+ #### __`debug`__
130
156
 
157
+ Optional. Boolean. Default false. If true, it will print out debug messages. In debug mode, the processing is not done in backend thread.
131
158
 
132
- #### debug
133
159
 
134
- Optional. Boolean. Default false. If true, it will print out debug messages. In debug mode, the processing is not done in backend thread.
160
+ ## Other integrations
161
+
162
+ To view more more documentation on integration options, please visit __[the Integration Options Documentation](https://www.moesif.com/docs/getting-started/integration-options/).__
@@ -1,6 +1,7 @@
1
1
  require 'moesif_api'
2
2
  require 'json'
3
3
  require 'time'
4
+ require 'base64'
4
5
 
5
6
  module MoesifRack
6
7
 
@@ -42,40 +43,28 @@ module MoesifRack
42
43
 
43
44
  req_body_string = req.body.read
44
45
  req.body.rewind
46
+ req_body_transfer_encoding = nil
45
47
 
46
48
  if req_body_string && req_body_string.length != 0
47
49
  begin
48
50
  req_body = JSON.parse(req_body_string)
49
51
  rescue
50
- req_body = {
51
- 'moesif_error' => {
52
- 'code': 'json_parse_error',
53
- 'src': 'moesif-rack',
54
- 'msg' => ['Body is not a JSON Object or JSON Array'],
55
- 'args' => [req_body_string]
56
- }
57
- }
52
+ req_body = Base64.encode64(req_body_string)
53
+ req_body_transfer_encoding = 'base64'
58
54
  end
59
55
  end
60
56
 
61
57
  rsp_headers = headers.dup
62
58
 
63
- content_type = rsp_headers['Content-Type'];
59
+ rsp_body_string = get_response_body(body);
60
+ rsp_body_transfer_encoding = nil
64
61
 
65
- if body && body.body
62
+ if rsp_body_string && rsp_body_string.length != 0
66
63
  begin
67
- rsp_body = JSON.parse(body.body)
64
+ rsp_body = JSON.parse(rsp_body_string)
68
65
  rescue
69
- if content_type && (content_type.include? "json")
70
- rsp_body = {
71
- 'moesif_error' => {
72
- 'code': 'json_parse_error',
73
- 'src': 'moesif-rack',
74
- 'msg' => ['Body is not a JSON Object or JSON Array'],
75
- 'args' => [body.body]
76
- }
77
- }
78
- end
66
+ rsp_body = Base64.encode64(rsp_body_string)
67
+ rsp_body_transfer_encoding = 'base64'
79
68
  end
80
69
  end
81
70
 
@@ -90,12 +79,14 @@ module MoesifRack
90
79
  event_req.ip_address = req.ip
91
80
  event_req.headers = req_headers
92
81
  event_req.body = req_body
82
+ event_req.transfer_encoding = req_body_transfer_encoding
93
83
 
94
84
  event_rsp = MoesifApi::EventResponseModel.new()
95
85
  event_rsp.time = end_time
96
86
  event_rsp.status = status
97
87
  event_rsp.headers = rsp_headers
98
88
  event_rsp.body = rsp_body
89
+ event_rsp.transfer_encoding = rsp_body_transfer_encoding
99
90
 
100
91
  event_model = MoesifApi::EventModel.new()
101
92
  event_model.request = event_req
@@ -146,5 +137,12 @@ module MoesifRack
146
137
 
147
138
  [status, headers, body]
148
139
  end
140
+
141
+ def get_response_body(response)
142
+ body = response.respond_to?(:body) ? response.body : response
143
+ body = body.inject("") { |i, a| i << a } if body.respond_to?(:each)
144
+ body.to_s
145
+ end
146
+
149
147
  end
150
148
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moesif_rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moesif, Inc
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-05 00:00:00.000000000 Z
12
+ date: 2017-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-unit
@@ -59,14 +59,14 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: 1.0.4
62
+ version: 1.1.1
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 1.0.4
69
+ version: 1.1.1
70
70
  description: Collection/Data Ingestion SDK for Rack (also Rails) Middleware / RoR
71
71
  email: xing@moesif.com
72
72
  executables: []