sapience 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.simplecov +6 -2
  3. data/.travis.yml +8 -25
  4. data/CODE_OF_CONDUCT.md +1 -1
  5. data/Gemfile +5 -5
  6. data/README.md +146 -15
  7. data/Rakefile +2 -1
  8. data/config/default.yml +29 -0
  9. data/dev-entrypoint.sh +10 -0
  10. data/docker-compose.yml +42 -0
  11. data/lib/sapience/appender/datadog.rb +100 -0
  12. data/lib/sapience/appender/file.rb +11 -22
  13. data/lib/sapience/appender/sentry.rb +61 -55
  14. data/lib/sapience/appender/wrapper.rb +5 -4
  15. data/lib/sapience/base.rb +21 -13
  16. data/lib/sapience/config_loader.rb +66 -0
  17. data/lib/sapience/configuration/grape.rb +9 -0
  18. data/lib/sapience/configuration.rb +32 -22
  19. data/lib/sapience/core_ext/hash.rb +25 -0
  20. data/lib/sapience/core_ext/thread.rb +2 -2
  21. data/lib/sapience/extensions/action_cable/tagged_logger_proxy.rb +6 -0
  22. data/lib/sapience/extensions/action_controller/live.rb +6 -0
  23. data/lib/sapience/extensions/action_controller/log_subscriber.rb +127 -0
  24. data/lib/sapience/extensions/action_controller/log_subscriber_processing.rb +24 -0
  25. data/lib/sapience/extensions/action_dispatch/debug_exceptions.rb +11 -0
  26. data/lib/sapience/extensions/action_view/log_subscriber.rb +9 -0
  27. data/lib/sapience/extensions/action_view/streaming_template_renderer.rb +11 -0
  28. data/lib/sapience/extensions/active_job/logging.rb +14 -0
  29. data/lib/sapience/extensions/active_model_serializers/logging.rb +14 -0
  30. data/lib/sapience/extensions/active_record/log_subscriber.rb +35 -0
  31. data/lib/sapience/extensions/grape/middleware/logging.rb +91 -0
  32. data/lib/sapience/extensions/grape/timings.rb +25 -0
  33. data/lib/sapience/extensions/rails/rack/logger.rb +11 -0
  34. data/lib/sapience/extensions/rails/rack/logger_info_as_debug.rb +24 -0
  35. data/lib/sapience/formatters/color.rb +3 -3
  36. data/lib/sapience/formatters/default.rb +1 -1
  37. data/lib/sapience/grape.rb +25 -0
  38. data/lib/sapience/log.rb +8 -6
  39. data/lib/sapience/loggable.rb +19 -17
  40. data/lib/sapience/logger.rb +46 -126
  41. data/lib/sapience/rails.rb +65 -8
  42. data/lib/sapience/sapience.rb +74 -73
  43. data/lib/sapience/subscriber.rb +5 -1
  44. data/lib/sapience/version.rb +1 -1
  45. data/lib/sapience.rb +4 -1
  46. data/sapience.gemspec +7 -4
  47. data/test_app/Gemfile +5 -1
  48. data/test_app/Rakefile +5 -1
  49. data/test_app/app/controllers/posts_controller.rb +12 -11
  50. data/test_app/config/application.rb +0 -1
  51. data/test_app/spec/controllers/posts_controller_spec.rb +1 -1
  52. data/test_app/spec/fixtures/sapience.yml +14 -0
  53. data/test_app/spec/helpers/posts_helper_spec.rb +1 -1
  54. data/test_app/spec/integration/sapience_spec.rb +14 -0
  55. data/test_app/spec/models/post_spec.rb +1 -1
  56. data/test_app/spec/models/user_spec.rb +1 -1
  57. data/test_app/spec/rails_helper.rb +15 -0
  58. data/test_app/spec/requests/posts_spec.rb +1 -1
  59. data/test_app/spec/routing/posts_routing_spec.rb +8 -10
  60. data/test_app/spec/spec_helper.rb +0 -44
  61. metadata +76 -11
  62. data/lib/sapience/appender/statsd.rb +0 -68
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sapience
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-12 00:00:00.000000000 Z
12
+ date: 2016-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: '1.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: '1.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -137,7 +137,49 @@ dependencies:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
- description: Write a longer description or delete this line.
140
+ - !ruby/object:Gem::Dependency
141
+ name: codeclimate-test-reporter
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: coveralls
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: gem-release
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ description: Hasslefree autoconfiguration for logging, metrics and exception collection.
141
183
  email:
142
184
  - mika@reevoo.com
143
185
  - alex.malkov@reevoo.com
@@ -160,21 +202,42 @@ files:
160
202
  - Rakefile
161
203
  - bin/console
162
204
  - bin/setup
205
+ - config/default.yml
206
+ - dev-entrypoint.sh
207
+ - docker-compose.yml
163
208
  - lib/sapience.rb
164
209
  - lib/sapience/ansi_colors.rb
210
+ - lib/sapience/appender/datadog.rb
165
211
  - lib/sapience/appender/file.rb
166
212
  - lib/sapience/appender/sentry.rb
167
- - lib/sapience/appender/statsd.rb
168
213
  - lib/sapience/appender/wrapper.rb
169
214
  - lib/sapience/base.rb
170
215
  - lib/sapience/concerns/compatibility.rb
216
+ - lib/sapience/config_loader.rb
171
217
  - lib/sapience/configuration.rb
218
+ - lib/sapience/configuration/grape.rb
219
+ - lib/sapience/core_ext/hash.rb
172
220
  - lib/sapience/core_ext/thread.rb
221
+ - lib/sapience/extensions/action_cable/tagged_logger_proxy.rb
222
+ - lib/sapience/extensions/action_controller/live.rb
223
+ - lib/sapience/extensions/action_controller/log_subscriber.rb
224
+ - lib/sapience/extensions/action_controller/log_subscriber_processing.rb
225
+ - lib/sapience/extensions/action_dispatch/debug_exceptions.rb
226
+ - lib/sapience/extensions/action_view/log_subscriber.rb
227
+ - lib/sapience/extensions/action_view/streaming_template_renderer.rb
228
+ - lib/sapience/extensions/active_job/logging.rb
229
+ - lib/sapience/extensions/active_model_serializers/logging.rb
230
+ - lib/sapience/extensions/active_record/log_subscriber.rb
231
+ - lib/sapience/extensions/grape/middleware/logging.rb
232
+ - lib/sapience/extensions/grape/timings.rb
233
+ - lib/sapience/extensions/rails/rack/logger.rb
234
+ - lib/sapience/extensions/rails/rack/logger_info_as_debug.rb
173
235
  - lib/sapience/formatters/base.rb
174
236
  - lib/sapience/formatters/color.rb
175
237
  - lib/sapience/formatters/default.rb
176
238
  - lib/sapience/formatters/json.rb
177
239
  - lib/sapience/formatters/raw.rb
240
+ - lib/sapience/grape.rb
178
241
  - lib/sapience/log.rb
179
242
  - lib/sapience/loggable.rb
180
243
  - lib/sapience/logger.rb
@@ -261,7 +324,9 @@ files:
261
324
  - test_app/public/favicon.ico
262
325
  - test_app/public/robots.txt
263
326
  - test_app/spec/controllers/posts_controller_spec.rb
327
+ - test_app/spec/fixtures/sapience.yml
264
328
  - test_app/spec/helpers/posts_helper_spec.rb
329
+ - test_app/spec/integration/sapience_spec.rb
265
330
  - test_app/spec/models/post_spec.rb
266
331
  - test_app/spec/models/user_spec.rb
267
332
  - test_app/spec/rails_helper.rb
@@ -270,7 +335,7 @@ files:
270
335
  - test_app/spec/spec_helper.rb
271
336
  - test_app/tmp/.keep
272
337
  - test_app/vendor/assets/stylesheets/.keep
273
- homepage: https://sapience.github.io
338
+ homepage: https://github.com/reevoo/sapience
274
339
  licenses:
275
340
  - MIT
276
341
  metadata:
@@ -291,8 +356,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
291
356
  version: '0'
292
357
  requirements: []
293
358
  rubyforge_project:
294
- rubygems_version: 2.6.6
359
+ rubygems_version: 2.5.1
295
360
  signing_key:
296
361
  specification_version: 4
297
- summary: Write a short summary, because Rubygems requires one.
362
+ summary: Hasslefree autoconfiguration for logging, metrics and exception collection.
298
363
  test_files: []
@@ -1,68 +0,0 @@
1
- require "uri"
2
- begin
3
- require "statsd-ruby"
4
- rescue LoadError
5
- raise 'Gem statsd-ruby is required for logging metrics. Please add the gem "statsd-ruby" to your Gemfile.'
6
- end
7
-
8
- # Example:
9
- # Sapience.add_appender(:statsd, {url: "udp://localhost:2222"})
10
- #
11
- class Sapience::Appender::Statsd < Sapience::Subscriber
12
- # Create Appender
13
- #
14
- # Parameters:
15
- # url: [String]
16
- # Valid URL to post to.
17
- # Example:
18
- # udp://localhost:8125
19
- # Example, send all metrics to a particular namespace:
20
- # udp://localhost:8125/namespace
21
- # Default: udp://localhost:8125
22
- def initialize(options = {}, &block)
23
- options = options.is_a?(Hash) ? options.dup : { level: options }
24
- url = options.delete(:url) || "udp://localhost:8125"
25
- uri = URI.parse(url)
26
- fail('Statsd only supports udp. Example: "udp://localhost:8125"') if uri.scheme != "udp"
27
-
28
- @statsd = ::Statsd.new(uri.host, uri.port)
29
- path = uri.path.chomp("/")
30
- @statsd.namespace = path.sub("/", "") if path != ""
31
-
32
- super(options, &block)
33
- end
34
-
35
- # Send an error notification to sentry
36
- def log(log)
37
- metric = log.metric
38
- return false unless metric
39
-
40
- if log.duration
41
- timing(metric, log.duration)
42
- else
43
- amount = (log.metric_amount || 1).round
44
- if amount < 0
45
- decrement(metric, amount)
46
- else
47
- increment(metric, amount)
48
- end
49
- end
50
- true
51
- end
52
-
53
- def timing(metric, duration)
54
- @statsd.timing(metric, duration)
55
- end
56
-
57
- def increment(metric, amount)
58
- @statsd.batch do
59
- amount.times { @statsd.increment(metric) }
60
- end
61
- end
62
-
63
- def decrement(metric, amount)
64
- @statsd.batch do
65
- amount.abs.times { @statsd.decrement(metric) }
66
- end
67
- end
68
- end