sapience 2.0.5 → 2.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
  SHA1:
3
- metadata.gz: 85f907c18a21df4ca3ef9505ee38c1bb7509c4a0
4
- data.tar.gz: 1fa7b7505c45f0934153d3765a5f1721718ad582
3
+ metadata.gz: 7af7111709b92aaa1a65d94c9f8033c75bec80ad
4
+ data.tar.gz: 5de17972d7e7c4c6dd0ff51501df9a67a417df8d
5
5
  SHA512:
6
- metadata.gz: db0ebb6ef294981e68d284afc2902c5455879b4edeb681f09eabd365661fc713907aa869e9578d9079c03923a9e0f64c148a71f8a04038d43c307017135c1873
7
- data.tar.gz: 6cc66a7b88e17131b6e1d2f2b42f3395efe4e269a554b5f799bd5856db8ec0d00e55349b8c112b668aee0ae4f621a1ca8ecabd96bae3c3cd4fac788385583ebf
6
+ metadata.gz: fa1e5cffa6779704c9521b987ad85499d728537162f2eb4a7fa098436380929ee5c56fa392d660447001c0008856decbf30778c745b2dc4d9d36cb667a663776
7
+ data.tar.gz: 47c9b58310c9777e2746138c4037b4ee1f42cb52e49f8910028b526ee166a9940d42d1137240bfe8a469593d39364961fb0c1d9965ab6ec3c00d03503acd5f04
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v2.1.0
2
+
3
+ - Add `Sapience::ErrorHandler:Sentry#capture`
4
+ - Add `Sapience::ErrorHandler:Sentry#capture!`
5
+
1
6
  ## v2.0.5
2
7
 
3
8
  - Add "flush" as an instance method in logger.
data/docs/metrics.md CHANGED
@@ -9,7 +9,7 @@ You can configure datadog through "sapience.yml", using the "metrics" section sh
9
9
  ```yml
10
10
  production:
11
11
  log_level: info
12
-
12
+
13
13
  metrics:
14
14
  datadog:
15
15
  url: <%= ENV.fetch("STATSD_URL", "udp://localhost:8125") %>
@@ -22,7 +22,7 @@ Sapience.metrics = { datadog: { url: ENV["STATSD_URL"] } }
22
22
 
23
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
24
 
25
- Then you can send error metrics to Datadog using the following methods:
25
+ Then you can send metrics to Datadog using the following methods:
26
26
  ```ruby
27
27
  timing(metric, duration = 0, options = {})
28
28
  increment(metric, options = {})
@@ -38,14 +38,50 @@ event(title, text, options = {})
38
38
  As in the examples below:
39
39
  ```ruby
40
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", {})
41
+ metrics.timing("metric-key", 100)
42
+ metrics.increment("metric-key")
43
+ metrics.decrement("metric-key")
44
+ metrics.count("metric-key", -3)
45
+ metrics.histogram("metric-key", 2_500)
46
+ metrics.gauge("metric-key", 1_000, {})
47
+ metrics.event("metric-key", "description about event", {})
47
48
  metrics.batch do
48
- metrics.event("company/project/metric-name", "description about event", {})
49
- metrics.increment("company/project/another-metric-name", 2)
49
+ metrics.event("metric-key", "description about event", {})
50
+ metrics.increment("another-metric-key", 2)
50
51
  end
51
- ```
52
+ ```
53
+
54
+ ### Metric keys and tags
55
+
56
+ The metric key argument used in all tracking methods can be arbitrary string however we recommend to use combination of names
57
+ identifying component of your system joined by dots. All the metric keys are automatically prefixed with `app_name.environment`.
58
+
59
+ We use two different schema for key that can be combined in one app:
60
+
61
+ #### Fully specified key
62
+
63
+ ```
64
+ app_name.environment.module.(component)*.event
65
+ ```
66
+
67
+ The key fully identify the source of event and is useful in cases where you don't need to aggregate events
68
+ occurred in one component, module or whole app. Example:
69
+
70
+ ```ruby
71
+ metrics.increment('authentication.sign_in') # full key: booking_app.production.authentication.sign_in
72
+ ```
73
+
74
+ #### Partially specified key in combination with tags
75
+
76
+ ```
77
+ key: app_name.environment.event_type
78
+ tags: event:name, module:name, component:name
79
+ ```
80
+
81
+ The key itself doesn't identify the source of tracked event and is useful in cases where you want to aggregate events
82
+ occurred in one component, module or whole app. It's handy for event types that can occur in all modules of an app.
83
+ We use it mainly for error metrics. Example:
84
+
85
+ ```ruby
86
+ metrics.increment('error', tags: %w(error_class:AccessDenied module:authentication component:permissions))
87
+ ```
@@ -37,13 +37,22 @@ module Sapience
37
37
  end
38
38
 
39
39
  def capture_exception(exception, payload = {})
40
- capture(exception, payload)
40
+ capture_type(exception, payload)
41
41
  end
42
42
 
43
43
  def capture_message(message, payload = {})
44
- capture(message, payload)
44
+ capture_type(message, payload)
45
45
  end
46
46
 
47
+ def user_context(options = {})
48
+ Raven.user_context(options)
49
+ end
50
+
51
+ def tags_context(options = {})
52
+ Raven.tags_context(options)
53
+ end
54
+ alias_method :tags=, :tags_context
55
+
47
56
  def configured?
48
57
  @configured == true
49
58
  end
@@ -58,9 +67,42 @@ module Sapience
58
67
  @configured = true
59
68
  end
60
69
 
70
+ # Capture, process and reraise any exceptions from the given block.
71
+ #
72
+ # @example
73
+ # Raven.capture do
74
+ # MyApp.run
75
+ # end
76
+ def capture!(options = {})
77
+ fail ArgumentError unless block_given?
78
+
79
+ begin
80
+ yield
81
+ rescue StandardError => e
82
+ capture_type(e, options)
83
+ raise
84
+ end
85
+ end
86
+
87
+ # Capture, process and not reraise any exceptions from the given block.
88
+ #
89
+ # @example
90
+ # Raven.capture do
91
+ # MyApp.run
92
+ # end
93
+ def capture(options = {})
94
+ fail ArgumentError unless block_given?
95
+
96
+ begin
97
+ yield
98
+ rescue StandardError => e
99
+ capture_type(e, options)
100
+ end
101
+ end
102
+
61
103
  private
62
104
 
63
- def capture(data, payload)
105
+ def capture_type(data, payload)
64
106
  return false unless valid?
65
107
  configure_sentry
66
108
 
@@ -1,3 +1,3 @@
1
1
  module Sapience
2
- VERSION = "2.0.5"
2
+ VERSION = "2.1.0"
3
3
  end
data/sapience.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = "Hasslefree autoconfiguration for logging, metrics and exception collection."
13
13
  spec.description = "Hasslefree autoconfiguration for logging, metrics and exception collection."
14
- spec.homepage = "https://github.com/reevoo/sapience"
14
+ spec.homepage = "https://github.com/reevoo/sapience-rb"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
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.5
4
+ version: 2.1.0
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-23 00:00:00.000000000 Z
12
+ date: 2017-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -365,7 +365,7 @@ files:
365
365
  - lib/sapience/version.rb
366
366
  - lib/tasks/coverage.rake
367
367
  - sapience.gemspec
368
- homepage: https://github.com/reevoo/sapience
368
+ homepage: https://github.com/reevoo/sapience-rb
369
369
  licenses:
370
370
  - MIT
371
371
  metadata: