sapience 2.0.3 → 2.0.4

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: a496d597a7e40d5578684eb7c6cb8dcd95f52e7e
4
- data.tar.gz: 0f040171526449771d60df6b210bcefb0872a1db
3
+ metadata.gz: 5ff125a3d5585789c2c8b1ffbd82b54c1b8b73f1
4
+ data.tar.gz: ed7db99c18a59d7c9f5373bb1ad380fb3f9f00e3
5
5
  SHA512:
6
- metadata.gz: b9a04aedb193c4a03b77e137c26c866b14961448c376a602301ce96cf5f30e70ef0d551f75aec3eef82c43a262b05529c79d4f2d3e42d04059d79467be334a1a
7
- data.tar.gz: 0f3e82c77af85a5a2acd9554811ddd833c6cdbe38939ddc643637a28305eb7491057e0c8448401eab68fbb80f8cc689b08375aa5c2be883d73451a67090bcfed
6
+ metadata.gz: 8d0c2d599305507f04bc0174dacbbf0dc1e1b19429d2240b2162c26278dc3055c9b6e5e462dc2325c0db01d0f9b728a43b11a1d0ea4863a8054819a67412b5a8
7
+ data.tar.gz: 3e4053c56cb085397b24df71b3a8ee0de28c0713e2565ba44416f153cb056350c22807878ad69a78301774d1098e5ba4453ef3834f3193c778ed423cfb39bbf3
data/.travis.yml CHANGED
@@ -22,7 +22,9 @@ before_script:
22
22
  script:
23
23
  - bundle exec rake reevoocop
24
24
  - docker-compose run rspec
25
- - docker-compose run rails
25
+ - docker-compose run rails32
26
+ - docker-compose run rails42
27
+ - docker-compose run rails50
26
28
  - docker-compose run grape
27
29
 
28
30
  after_success:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v2.0.4
2
+
3
+ - Fix Sapience.logger. From now it logs into all configured Stream appenders.
4
+
1
5
  ## v2.0.3
2
6
 
3
7
  - Ability to configure ActiveRecord log level independently
data/README.md CHANGED
@@ -12,7 +12,7 @@ This project aims to make it easier to centralise the configuration of these thr
12
12
 
13
13
  We have taken a great deal of inspiration from the amazing [Semantic Logger](https://github.com/rocketjob/semantic_logger) and implemented something similar to [Rubocop](https://github.com/bbatsov/rubocop) for handling and overriding how to find configuration. If you want some inspiration for how we do something similar for our projects for Rubocop check: [Reevoocop](https://github.com/reevoo/reevoocop).
14
14
 
15
- ## Setup
15
+ ## Installation
16
16
 
17
17
  First of all we need to require the right file for the project. There are currently two frameworks supported (rails and grape).
18
18
 
@@ -38,7 +38,7 @@ module Aslan
38
38
  class Base < Grape::API
39
39
  use Sapience::Extensions::Grape::Middleware::Logging, logger: Sapience[self]
40
40
 
41
- # To log all requests even when no route was found add the following:
41
+ # To log all requests even when no route was found use the following:
42
42
  route :any, "*path" do
43
43
  error!({ error: "No route found" }, 404)
44
44
  end
@@ -78,234 +78,109 @@ rescue_from :all do |e|
78
78
  end
79
79
  ```
80
80
 
81
+ **Note**: if you already have got your grape applications sprinkled with calls to API.logger, and you do
82
+ not want to have to replace all those calls to Sapience.logger manually, then just re-assign your logger
83
+ after including the Sapience middleware, like below:
81
84
 
85
+ ```ruby
86
+ use Sapience::Extensions::Grape::Middleware::Logging, logger: Sapience[self]
87
+ API.logger = Sapience.logger
88
+ ```
82
89
 
83
- ### Configuration
84
90
 
85
- The sapience configuration can be controlled by a `config/sapience.yml` file or if you like us have many projects that use the same configuration you can create your own gem with a shared config. Have a look at [reevoo/reevoo_sapience-rb](https://github.com/reevoo/reevoo_sapience-rb)
91
+ **Note**: If you're using the rackup command to run your server in development, pass the -q flag to silence the default
92
+ rack logger so you don't get double logging.
86
93
 
87
- The `app_name` is required to be configured. Sapience will fail on startup if app_name isn't configured properly.
88
94
 
89
- ```ruby
90
- Sapience.configure do |config|
91
- config.default_level = :info
92
- config.log_level_active_record = :debug
93
- config.backtrace_level = :error
94
- config.appenders = [
95
- { stream: { io: STDOUT, formatter: :color } },
96
- { sentry: { dsn: "https://username:password@sentry.io/00000" } },
97
- ]
98
- config.log_executor = :single_thread_executor
99
- end
100
- ```
95
+ ## Configuration
96
+
97
+ The sapience configuration can be controlled by either a "sapience.yml" file, or a block of ruby code. Note that if you provide both, the block of ruby code will take precedence.
98
+
99
+ #### Configuration by sapience.yml file
101
100
 
102
- Sapience provides a default configuration that will be used unless another file or configuration is specified. You can provide a custom
101
+ Add a `config/sapience.yml` file to you appplication. Or if you, like us, have many projects that use the same configuration you can create your own gem with a shared .yml config. Have a look at [reevoo/reevoo_sapience-rb](https://github.com/reevoo/reevoo_sapience-rb) for an example . See below an example of how to configure "sapience.yml":
103
102
 
104
103
  ```yaml
105
- ---
106
104
  default:
105
+ app_name: My Application
106
+ log_level: debug
107
+ log_level_active_record: info
108
+ appenders:
109
+ - stream:
110
+ io: STDOUT
111
+ formatter: json
107
112
  filter_parameters:
108
113
  - password
109
114
  - password_confirmation
110
- log_executor: single_thread_executor
111
- log_level: info
115
+
116
+ development:
117
+ log_level: debug
118
+ metrics:
119
+ datadog:
120
+ url: <%= ENV.fetch("STATSD_URL", "udp://localhost:8125") %>
112
121
  appenders:
113
122
  - stream:
114
123
  io: STDOUT
115
124
  formatter: color
116
-
117
- test:
118
- log_executor: immediate_executor
119
- log_level: warn
120
- appenders:
121
125
  - stream:
122
- file_name: log/test.log
126
+ file_name: log/development.log
123
127
  formatter: color
124
-
125
- development:
126
- log_executor: single_thread_executor
127
- log_level_active_record: debug
128
- log_level: debug
128
+
129
+ staging:
130
+ log_level: info
131
+ error_handler:
132
+ sentry:
133
+ dsn: <%= ENV['SENTRY_DSN'] %>
134
+ metrics:
135
+ datadog:
136
+ url: <%= ENV.fetch("STATSD_URL", "udp://localhost:8125") %>
129
137
  appenders:
130
138
  - stream:
131
- file_name: log/development.log
132
- formatter: color
133
-
139
+ io: STDOUT
140
+ formatter: json
141
+
134
142
  production:
135
- log_executor: single_thread_executor
136
- log_level: warn
143
+ log_level: info
144
+ error_handler:
145
+ sentry:
146
+ dsn: <%= ENV['SENTRY_DSN'] %>
147
+ metrics:
148
+ datadog:
149
+ url: <%= ENV.fetch("STATSD_URL", "udp://localhost:8125") %>
137
150
  appenders:
138
151
  - stream:
139
- file_name: log/production.log
152
+ io: STDOUT
140
153
  formatter: json
141
154
  ```
142
155
 
143
-
144
- #### Configuration Inheritance
145
-
146
- We will use our default (or overriden - see [reevoo_sapience-rb](https://github.com/reevoo/reevoo_sapience-rb) for more info) configuration as a base. Any configuration specified inside a `config/sapience.yml` file will then me merged into the default or overridden config.
147
-
148
- The merge will take place not at the top level but at the environment level. This means that everything inside the environment keys will be replaced with a more specific application config.
149
-
150
- Then if a configure block is used that will take presedence.
151
-
152
- #### App name
153
-
154
- Sapience requires an application name to be set for your logs and such. We decided not to guess what name you want to give your application so there will be no magic involved here. There are 3 different ways of configuring the app_name for Sapience.
155
-
156
- ##### Environment variables
157
-
158
- This is the preferable way. If you have many environments look into using something like dotenv locally and use the power of devops and automation for your production environments.
159
-
160
- ```bash
161
- APP_NAME="My Application" bundle exec rails server -p 9000
162
- ```
163
-
164
- ##### Configuration file
165
-
166
- If you are in need of overriding the sapience default configuration an app_name can be used for any environment but we recommend you specify the app_name for the default section. That way you don't have to specify app_name for each environment and avoid some duplicated keys. Of course if you need to specify different app names for various environments by all means do.
167
-
168
- ```yaml
169
- ---
170
- default:
171
- app_name: My Application
172
- ```
173
-
174
- ##### Configuration block
175
-
176
- This will be the top priority and is the first check. The reasoning is that if someone has taken the time to use configure with a block that should override anything set in file configuration or environment.
156
+ #### Configuration by a block of Ruby code
177
157
 
178
158
  ```ruby
179
- Sapience.configure do |config|
159
+ Sapience.configure(force: true) do |config|
180
160
  config.app_name = "My Application"
161
+ config.default_level = :info
162
+ config.log_level_active_record = :info
163
+ config.backtrace_level = :error
164
+ config.filter_parameters = %w(password password_confirmation)
165
+ config.appenders = [
166
+ { stream: { io: STDOUT, formatter: :color } },
167
+ { stream: { file_name: "log/json_output.log", formatter: :json } }
168
+ ]
169
+ config.error_handler = { sentry: { dsn: ENV["SENTRY_DSN"] } }
170
+ config.metrics = { datadog: { url: ENV["STATSD_URL"] } }
171
+ config.log_executor = :single_thread_executor
181
172
  end
182
173
  ```
183
174
 
184
- #### Filtering out sensitive data
185
-
186
- **NOTE: This is intended for (and will currently only work with) Rack-like applications, which include a `params` key in their `payload` hash**
187
-
188
- You may not want to log certain parameters which have sensitive information to be in the logs, e.g. `password`. This can be set using the `filter_parameters` option when using `configure`:
189
-
190
- ```ruby
191
- Sapience.configure do |config|
192
- # Filter the value of "foo" from rack's parameter hash
193
- config.filter_parameters << 'foo'
194
- end
195
- ```
196
-
197
- Note that by default this is set to `['password', 'password_confirmation']`, so be careful when explicitly setting, as you may lose this filtering:
198
-
199
- ```ruby
200
- Sapience.configure do |config|
201
- # NOTE: password and password_confirmation will no longer be filtered
202
- config.filter_parameters = ['foo']
203
- end
204
- ```
205
-
206
- Similarly, *be particularly careful* when setting as `yaml` because this will no longer filter `password` and `password_confirmation`:
207
-
208
- ```yaml
209
- some_environment:
210
- # NOTE: password and password_confirmation will no longer be filtered if they're not included in this list
211
- filter_parameters:
212
- - foo
213
- ```
214
-
215
- Any filtered parameter will still show in the `params` field, but it's value will be `[FILTERED]`.
216
-
217
- ## Appenders
218
-
219
- One of the things that did not suit us so well with the Semantic Logger approach was that they made a distinction between metrics and appenders. In our view anything that could potentially log something somewhere should be treated as an appender.
220
-
221
- There are a number of appenders that each listen to different events and act on its data. It is possible to specify the `level` and `backtrace_level` for each appender by providing (example) `level: :error` to the add_appender method.
222
-
223
-
224
- ### Stream
225
-
226
- Stream appenders are basically a log stream. You can add as many stream appenders as you like logging to different locations.
227
-
228
- ```ruby
229
- Sapience.add_appender(:stream, file: "log/sapience.log", formatter: :json)
230
- Sapience.add_appender(:stream, io: STDOUT, formatter: :color, level: :trace)
231
- ```
232
-
233
- ### Sentry
234
-
235
- The sentry appender handles sending errors to [sentry](https://sentry.io). It's backtrace and log level can be configured by for instance `level: :info` and `backtrace_level: :debug`. The `level` configuration tells sentry to log starting at that level while the `backtrace_level` tells sentry to only collect backtrace starting at that level.
236
-
237
- ```ruby
238
- Sapience.add_appender(
239
- :sentry,
240
- dsn: "https://username:password@app.getsentry.com/00000",
241
- level: :error,
242
- backtrace_level: :error
243
- )
244
- ```
245
-
246
- #### Test exceptions
247
-
248
- If you want to quickly verify that your appenders are handling exceptions properly. You can use the following method to
249
- generate and log an exception at any given level.
250
-
251
- ```ruby
252
- Sapience.test_exception(:error)
253
- ```
254
-
255
- ### Datadog
256
-
257
- Datadog is a slightly modified version of statsd. On top of the standard statsd API it has support for events.
258
-
259
- ```ruby
260
- Sapience.add_appender(:datadog, url: "udp://localhost:8125")
261
- ```
262
-
263
- The appender will then be listening to anything that is logged with a `metric: "company/project/metric-name"` key. Details about the API can be found in [dogstatsd-ruby](https://github.com/DataDog/dogstatsd-ruby).
264
-
265
- The appender can also be used directly through: `Sapience.metrics`
266
-
267
- ```ruby
268
- metrics = Sapience.metrics
269
- metrics.timing("company/project/metric-name", 100)
270
- metrics.increment("company/project/metric-name", 10)
271
- metrics.decrement("company/project/metric-name", 5)
272
- metrics.histogram("company/project/metric-name", 2_500)
273
- metrics.gauge("company/project/metric-name", 1_000, {})
274
- metrics.event("company/project/metric-name", "description about event", {})
275
- metrics.batch do
276
- metrics.event("company/project/metric-name", "description about event", {})
277
- metrics.increment("company/project/another-metric-name", 2)
278
- end
279
- ```
280
-
175
+ For further details about "app_name", "filter_parameters", "appenders", "metrics" and "error_handler" used in both the .yml and the code configurations above, see the links below:
281
176
 
282
- ### Wrapper
177
+ - [app_name](docs/app_name.md)
178
+ - [filter_parameters](docs/filter_parameters.md)
179
+ - [appenders](docs/appenders.md)
180
+ - [metrics](docs/metrics.md)
181
+ - [error_handler](docs/error_handler.md)
182
+ - [logger](docs/logger.md)
283
183
 
284
- The wrapper is useful when you already have a logger you want to use but want to use Sapience. The wrapper appender will when called use the logger provided to store the log data.
285
-
286
- ```ruby
287
- Sapience.add_appender(:wrapper, logger: Logger.new(STDOUT))
288
- ```
289
-
290
- ## Formatters
291
-
292
- Formatters can be specified by using the key `formatter: :camelized_formatter_name`. **Note**: Only the File appender supports custom formatters.
293
-
294
- ### Color
295
-
296
- `formatter: :color` - gives colorized output. Useful for `test` and `development` environments.
297
-
298
- ### Default
299
-
300
- `formatter: :default` - logs a string. Inspired by how access logs for Nginx are logged.
301
-
302
- ### JSON
303
-
304
- `formatter: :json` - logs are saved as a single line json. Useful for production like environments.
305
-
306
- ### RAW
307
-
308
- `formatter: :raw` - logs are saved as a single line ruby hash. Useful for production like environments and is used internally for the Sentry appender.
309
184
 
310
185
  ## Running the tests
311
186
 
@@ -313,6 +188,8 @@ You need to create the test postgres db, by running the command below:
313
188
 
314
189
  `createdb rails_app_test`
315
190
 
191
+ Then you can run them with the followign command:
192
+
316
193
  `bin/tests`
317
194
 
318
195
  ## Environment variables
@@ -320,9 +197,6 @@ You need to create the test postgres db, by running the command below:
320
197
  - `APP_NAME` - If you want to provide an application name for sapience it can be done here.
321
198
  - `SAPIENCE_ENV` - For applications that don't use rack or rails
322
199
 
323
- ## Contributing
324
-
325
- Bug reports and pull requests are welcome on GitHub at https://github.com/reevoo/sapience. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
326
200
 
327
201
 
328
202
  ## License
data/docker-compose.yml CHANGED
@@ -52,24 +52,56 @@ services:
52
52
 
53
53
 
54
54
 
55
- rails:
55
+ rails32:
56
56
  extends:
57
57
  service: base
58
- working_dir: /usr/src/app/test_apps/rails
58
+ working_dir: /usr/src/app/test_apps/rails_3_2
59
59
  entrypoint: /usr/src/app/dev-entrypoint.sh
60
60
  command: bundle exec rspec
61
61
  depends_on:
62
62
  - rabbitmq
63
63
  - postgres
64
64
  environment:
65
- APP_NAME: rails_app
65
+ APP_NAME: rails_3_2
66
66
  POSTGRES_HOST: postgres
67
67
  POSTGRES_USER: sapience
68
68
  POSTGRES_PASSWORD: tests
69
69
  AMQP: amqp://sapience:tests@rabbitmq:5672
70
70
  PATH: /usr/src/app/bin:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
71
71
 
72
+ rails42:
73
+ extends:
74
+ service: base
75
+ working_dir: /usr/src/app/test_apps/rails_4_2
76
+ entrypoint: /usr/src/app/dev-entrypoint.sh
77
+ command: bundle exec rspec
78
+ depends_on:
79
+ - rabbitmq
80
+ - postgres
81
+ environment:
82
+ APP_NAME: rails_4_2
83
+ POSTGRES_HOST: postgres
84
+ POSTGRES_USER: sapience
85
+ POSTGRES_PASSWORD: tests
86
+ AMQP: amqp://sapience:tests@rabbitmq:5672
87
+ PATH: /usr/src/app/bin:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
72
88
 
89
+ rails50:
90
+ extends:
91
+ service: base
92
+ working_dir: /usr/src/app/test_apps/rails_5_0
93
+ entrypoint: /usr/src/app/dev-entrypoint.sh
94
+ command: bundle exec rspec
95
+ depends_on:
96
+ - rabbitmq
97
+ - postgres
98
+ environment:
99
+ APP_NAME: rails_5_0
100
+ POSTGRES_HOST: postgres
101
+ POSTGRES_USER: sapience
102
+ POSTGRES_PASSWORD: tests
103
+ AMQP: amqp://sapience:tests@rabbitmq:5672
104
+ PATH: /usr/src/app/bin:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
73
105
 
74
106
  grape:
75
107
  extends:
data/docs/app_name.md ADDED
@@ -0,0 +1,32 @@
1
+
2
+ #### App name
3
+
4
+ Sapience requires an application name to be set for your logs and such. We decided not to guess what name you want to give your application so there will be no magic involved here. There are 3 different ways of configuring the app_name for Sapience.
5
+
6
+ ##### Environment variables
7
+
8
+ This is the preferable way. If you have many environments look into using something like dotenv locally and use the power of devops and automation for your production environments.
9
+
10
+ ```bash
11
+ APP_NAME="My Application" bundle exec rails server -p 9000
12
+ ```
13
+
14
+ ##### Configuration file
15
+
16
+ If you are in need of overriding the sapience default configuration an app_name can be used for any environment but we recommend you specify the app_name for the default section. That way you don't have to specify app_name for each environment and avoid some duplicated keys. Of course if you need to specify different app names for various environments by all means do.
17
+
18
+ ```yaml
19
+ ---
20
+ default:
21
+ app_name: My Application
22
+ ```
23
+
24
+ ##### Configuration block
25
+
26
+ This will be the top priority and is the first check. The reasoning is that if someone has taken the time to use configure with a block that should override anything set in file configuration or environment.
27
+
28
+ ```ruby
29
+ Sapience.configure do |config|
30
+ config.app_name = "My Application"
31
+ end
32
+ ```
@@ -0,0 +1,20 @@
1
+ ## Formatters
2
+
3
+ Formatters can be specified by using the key `formatter: :camelized_formatter_name`. **Note**: Only the File appender supports custom formatters.
4
+
5
+ ### Color
6
+
7
+ `formatter: :color` - gives colorized output. Useful for `test` and `development` environments.
8
+
9
+ ### Default
10
+
11
+ `formatter: :default` - logs a string. Inspired by how access logs for Nginx are logged.
12
+
13
+ ### JSON
14
+
15
+ `formatter: :json` - logs are saved as a single line json. Useful for production like environments.
16
+
17
+ ### RAW
18
+
19
+ `formatter: :raw` - logs are saved as a single line ruby hash. Useful for production like environments and is used internally for the Sentry appender.
20
+
data/docs/appenders.md ADDED
@@ -0,0 +1,37 @@
1
+ We have two different types of appenders, see below.
2
+
3
+
4
+ ## Stream
5
+
6
+
7
+ Stream appenders are basically a log stream. You can add as many stream appenders as you like logging to different locations.
8
+
9
+ ```ruby
10
+ Sapience.add_appender(:stream, file: "log/sapience.log", formatter: :json)
11
+ Sapience.add_appender(:stream, io: STDOUT, formatter: :color, level: :trace)
12
+ ```
13
+
14
+ or using the sapience.yml file:
15
+
16
+ ```yml
17
+ appenders:
18
+ - stream:
19
+ io: STDOUT
20
+ formatter: color
21
+ - stream:
22
+ file_name: log/development.log
23
+ formatter: color
24
+ ```
25
+ You can specify the formatter for each stream, click in the link below to see the list of formatters available:
26
+
27
+ - [formatters](appenders/formatters.md)
28
+
29
+
30
+
31
+ ### Wrapper
32
+
33
+ The wrapper is useful when you already have a logger you want to use but want to use Sapience. The wrapper appender will when called use the logger provided to store the log data.
34
+
35
+ ```ruby
36
+ Sapience.add_appender(:wrapper, logger: Logger.new(STDOUT))
37
+ ```
@@ -0,0 +1,3 @@
1
+ ## Contributing
2
+
3
+ Bug reports and pull requests are welcome on GitHub at https://github.com/reevoo/sapience. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -0,0 +1,42 @@
1
+ ## Error Handling
2
+
3
+ At the moment we only support [sentry](https://sentry.io) for error alerting.
4
+
5
+ You can configure the sentry DNS through "sapience.yml", using the "error_handler" section shown in the example below.
6
+ (note that you can use an environment variable, as in the example below, or just put the DNS in plain text if you prefer).
7
+ ```yml
8
+ production:
9
+ log_level: info
10
+
11
+ error_handler:
12
+ sentry:
13
+ dsn: <%= ENV['SENTRY_DSN'] %>
14
+
15
+ ```
16
+ or through ruby code as below:
17
+
18
+ ```ruby
19
+ Sapience.error_handler = { sentry: { dsn: ENV["SENTRY_DSN"] } }
20
+ ```
21
+ Then you can send error messages to Sentry using the following two public methods in Sapience:
22
+
23
+ ```ruby
24
+ capture_exception(exception, payload = {})
25
+ capture_message(message, payload = {})
26
+ ```
27
+
28
+ As in the example below:
29
+ ```ruby
30
+ begin
31
+ (do somehting)
32
+ rescue MyException => e
33
+ Sapience.capture_exception(e)
34
+ raise e
35
+ end
36
+ ```
37
+
38
+ You can also test that you've configured the DNS correctly by using the "test_exception" method, that will send a test message to your configured Sentry project. See below.
39
+
40
+ ```ruby
41
+ Sapience.test_exception(:error)
42
+ ```
@@ -0,0 +1,32 @@
1
+ ## Filtering out sensitive data
2
+
3
+ **NOTE: This is intended for (and will currently only work with) Rack-like applications, which include a `params` key in their `payload` hash**
4
+
5
+ You may not want to log certain parameters which have sensitive information to be in the logs, e.g. `password`. This can be set using the `filter_parameters` option when using `configure`:
6
+
7
+ ```ruby
8
+ Sapience.configure do |config|
9
+ # Filter the value of "foo" from rack's parameter hash
10
+ config.filter_parameters << 'foo'
11
+ end
12
+ ```
13
+
14
+ Note that by default this is set to `['password', 'password_confirmation']`, so be careful when explicitly setting, as you may lose this filtering:
15
+
16
+ ```ruby
17
+ Sapience.configure do |config|
18
+ # NOTE: password and password_confirmation will no longer be filtered
19
+ config.filter_parameters = ['foo']
20
+ end
21
+ ```
22
+
23
+ Similarly, *be particularly careful* when setting as `yaml` because this will no longer filter `password` and `password_confirmation`:
24
+
25
+ ```yaml
26
+ some_environment:
27
+ # NOTE: password and password_confirmation will no longer be filtered if they're not included in this list
28
+ filter_parameters:
29
+ - foo
30
+ ```
31
+
32
+ Any filtered parameter will still show in the `params` field, but it's value will be `[FILTERED]`.
data/docs/logger.md ADDED
@@ -0,0 +1,42 @@
1
+ ## Logger
2
+
3
+ Our logger implementation is a little different than the standard ruby logger API provides. Our parameters are treated slightly differently and we have more methods on the logger implementation.
4
+
5
+ ### logger.fatal
6
+
7
+ ### logger.error
8
+
9
+ ### logger.warn
10
+
11
+ ### logger.info
12
+
13
+ ### logger.debug
14
+
15
+ ### logger.trace
16
+
17
+ ### logger.measure_fatal
18
+
19
+ ### logger.measure_error
20
+
21
+ ### logger.measure_warn
22
+
23
+ ### logger.measure_info
24
+
25
+ ### logger.measure_debug
26
+
27
+ ### logger.measure_trace
28
+
29
+ ### logger.benchmark_fatal
30
+
31
+ ### logger.benchmark_error
32
+
33
+ ### logger.benchmark_warn
34
+
35
+ ### logger.benchmark_info
36
+
37
+ ### logger.benchmark_debug
38
+
39
+ ### logger.benchmark_trace
40
+
41
+ ### logger.measure
42
+
data/docs/metrics.md ADDED
@@ -0,0 +1,51 @@
1
+ ## Metrics
2
+
3
+ For metrics, at the moment, we only support Datadog.
4
+
5
+ Datadog is a slightly modified version of statsd. On top of the standard statsd API it has support for events.
6
+
7
+ You can configure datadog through "sapience.yml", using the "metrics" section shown in the example below.
8
+ (note that you can use an environment variable, as in the example below, or just put the URL in plain text if you prefer).
9
+ ```yml
10
+ production:
11
+ log_level: info
12
+
13
+ metrics:
14
+ datadog:
15
+ url: <%= ENV.fetch("STATSD_URL", "udp://localhost:8125") %>
16
+ ```
17
+ or through ruby code as below:
18
+
19
+ ```ruby
20
+ Sapience.metrics = { datadog: { url: ENV["STATSD_URL"] } }
21
+ ```
22
+
23
+ Of course, whatever url you use (like for example "udp://localhost:8125"), make sure you have launched the Datadog agent listening to that host and url. See how to install a Datadog agent in the [Datadog Agent Documentation](http://docs.datadoghq.com/guides/basic_agent_usage/).
24
+
25
+ Then you can send error metrics to Datadog using the following methods:
26
+ ```ruby
27
+ timing(metric, duration = 0, options = {})
28
+ increment(metric, options = {})
29
+ decrement(metric, options = {})
30
+ histogram(metric, amount, options = {})
31
+ gauge(metric, amount, options = {})
32
+ count(metric, amount, options = {})
33
+ time(metric, options = {}, &block)
34
+ batch(&block)
35
+ event(title, text, options = {})
36
+ ```
37
+
38
+ As in the examples below:
39
+ ```ruby
40
+ metrics = Sapience.metrics
41
+ metrics.timing("company/project/metric-name", 100)
42
+ metrics.increment("company/project/metric-name", 10)
43
+ metrics.decrement("company/project/metric-name", 5)
44
+ metrics.histogram("company/project/metric-name", 2_500)
45
+ metrics.gauge("company/project/metric-name", 1_000, {})
46
+ metrics.event("company/project/metric-name", "description about event", {})
47
+ metrics.batch do
48
+ metrics.event("company/project/metric-name", "description about event", {})
49
+ metrics.increment("company/project/another-metric-name", 2)
50
+ end
51
+ ```
@@ -50,16 +50,13 @@ module Sapience
50
50
  end
51
51
 
52
52
  @@appender_thread = nil
53
+ @@logger = nil
53
54
 
54
55
  # Internal logger for Sapience
55
56
  # For example when an appender is not working etc..
56
57
  # By default logs to STDERR
57
58
  def self.logger
58
- @@logger ||= begin
59
- l = Sapience::Appender::Stream.new(io: STDERR, level: :warn)
60
- l.name = name
61
- l
62
- end
59
+ @@logger ||= Sapience[Sapience]
63
60
  end
64
61
 
65
62
  # Start the appender thread
@@ -18,7 +18,7 @@ module Sapience
18
18
  # Parameters:
19
19
  # level: :trace
20
20
  # url: [String]
21
- # Valid URL to post to.
21
+ # Valid URL to postdogstatsd-ruby to.
22
22
  # Example:
23
23
  # udp://localhost:8125
24
24
  # Example, send all metrics to a particular namespace:
@@ -217,10 +217,10 @@ module Sapience
217
217
  # logger = Sapience['Example']
218
218
  # logger.info "Hello World"
219
219
  # logger.debug("Login time", user: 'Joe', duration: 100, ip_address: '127.0.0.1')
220
- def self.add_appender(appender, options = {}, _deprecated_level = nil, &_block) # rubocop:disable AbcSize
220
+ def self.add_appender(appender_class_name, options = {}, _deprecated_level = nil, &_block) # rubocop:disable AbcSize
221
221
  fail ArgumentError, "options should be a hash" unless options.is_a?(Hash)
222
222
  options = options.dup.deep_symbolize_keyz!
223
- appender_class = constantize_symbol(appender)
223
+ appender_class = constantize_symbol(appender_class_name)
224
224
  validate_appender_class!(appender_class)
225
225
 
226
226
  appender = appender_class.new(options)
@@ -230,7 +230,6 @@ module Sapience
230
230
  # Start appender thread if it is not already running
231
231
  Sapience::Logger.start_appender_thread
232
232
  Sapience::Logger.start_invalid_appenders_task
233
- Sapience.logger = appender if appender.is_a?(Sapience::Appender::Stream)
234
233
  appender
235
234
  end
236
235
 
@@ -1,3 +1,3 @@
1
1
  module Sapience
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.4"
3
3
  end
@@ -22,7 +22,7 @@ namespace :coverage do
22
22
  require "simplecov-html"
23
23
  require "simplecov-json"
24
24
 
25
- coverage_file_pattern = "{rails,sapience,grape}/.resultset.json"
25
+ coverage_file_pattern = "{rails_3_2,rails_4_2,rails_5_0,sapience,grape}/.resultset.json"
26
26
  json_files = Dir[File.join(coverage_dir, coverage_file_pattern)]
27
27
 
28
28
  merged_hash = {}
@@ -60,9 +60,7 @@ namespace :coverage do
60
60
  ENV["CODECLIMATE_REPO_TOKEN"] = "204dc055302da6aed94379e249aa0645636d1d1794920c62db05c5fa968215de"
61
61
  resultset_file = File.join(coverage_dir, ".resultset.json")
62
62
  result_hash = JSON.parse(File.read(resultset_file))
63
- simplecov_result = SimpleCov::Result.from_hash(result_hash)
64
-
65
- CodeClimate::TestReporter::Formatter.new.format(simplecov_result)
63
+ CodeClimate::TestReporter::Formatter.new.format(result_hash)
66
64
  unhide_coverage_config
67
65
  end
68
66
  end
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: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-16 00:00:00.000000000 Z
12
+ date: 2017-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -300,6 +300,14 @@ files:
300
300
  - config/default.yml
301
301
  - dev-entrypoint.sh
302
302
  - docker-compose.yml
303
+ - docs/app_name.md
304
+ - docs/appenders.md
305
+ - docs/appenders/formatters.md
306
+ - docs/contributing/README.md
307
+ - docs/error_handler.md
308
+ - docs/filter_parameters.md
309
+ - docs/logger.md
310
+ - docs/metrics.md
303
311
  - lib/sapience.rb
304
312
  - lib/sapience/ansi_colors.rb
305
313
  - lib/sapience/appender.rb