sapience 2.3.5 → 2.4.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: 439902e12b2cb4d1967a2e2bf1d89b5c779a67a5
4
- data.tar.gz: 89f60374e6412c6b94c6325c597d9b55d7f548c5
3
+ metadata.gz: 242e44a2d89e27ec8aa394c77164599aaea34da7
4
+ data.tar.gz: dc875d0fd20dc77d838e67e7d7e1052efae3102f
5
5
  SHA512:
6
- metadata.gz: 1a63d295f92bfd1aa6ccc792e1ab7ea706bfbe16abaffc2227b950a81520dedbbc09d8379be516053047599ae3dd5a71228aa5cbf0808fb15cad49b821d92026
7
- data.tar.gz: eb4ed3b886846ae8c752631f181e462302025374a39d79a887342430af478a1f5c70ce848dacaf1ee051739ccc7d2d5efde32542f6b9f637dbd14082cfdd78a9
6
+ metadata.gz: ae00691b82ab10345121193832cb0a2f9616d7a78ac86abfae1b1982c8a3d7474f44960b8e5d114b61c4fe3d48df18112c3ab6dd7bf02f642161023862f19b84
7
+ data.tar.gz: bb38d039a741e6f92371735fafa2f29cdade79aa43c755c8137c0b2d08d60f3db51fc9fb5eee5acd2c30380f9a01ef629b555cea54285192afa67f92be99ce9d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## v2.4.0
2
+
3
+ - Add shortcut metrics
4
+ - `Sapience.metrics.success(module_name<string>, action<string>, opts<hash>)`
5
+ - `Sapience.metrics.error(module_name<string>, action<string>, opts<hash>)`
6
+ - `Sapience.metrics.exception(module_name<string>, action<string>, opts<hash>)`
7
+
1
8
  ## v2.3.5
2
9
 
3
10
  - Set Sapience.config.app_name when APP_NAME environment variable is set
@@ -23,8 +23,9 @@ module Sapience
23
23
  # dsn: [String]
24
24
  # Url to configure Sentry-Raven.
25
25
  # Default: nil
26
- def initialize(options = {})
27
- fail ArgumentError, "Options should be a Hash" unless options.is_a?(Hash)
26
+ def initialize(opts = {})
27
+ fail ArgumentError, "Options should be a Hash" unless opts.is_a?(Hash)
28
+ options = opts.dup
28
29
 
29
30
  options[:level] ||= :error
30
31
  @sentry_logger_level = options[:level]
@@ -135,6 +135,18 @@ module Sapience
135
135
  provider.event(title, text, opts)
136
136
  end
137
137
 
138
+ def success(module_name, action, opts = {})
139
+ increment("success", add_tags(module_name, action, opts))
140
+ end
141
+
142
+ def error(module_name, action, opts = {})
143
+ increment("error", add_tags(module_name, action, opts))
144
+ end
145
+
146
+ def exception(module_name, action, opts = {})
147
+ increment("exception", add_tags(module_name, action, opts))
148
+ end
149
+
138
150
  def namespace
139
151
  ns = Sapience.namify(Sapience.app_name)
140
152
  ns << ".#{Sapience.namify(Sapience.environment)}" if Sapience.environment
@@ -147,6 +159,23 @@ module Sapience
147
159
  tags: @tags,
148
160
  }
149
161
  end
162
+
163
+ private
164
+
165
+ def add_tags(module_name, action, opts)
166
+ tags = opts.fetch(:tags, [])
167
+ clean_up_tags(tags, :module, module_name)
168
+ clean_up_tags(tags, :action, action)
169
+ tags << "module:#{module_name}" << "action:#{action}"
170
+ opts[:tags] = tags
171
+ opts
172
+ end
173
+
174
+ def clean_up_tags(tags, key, value)
175
+ old_tags = tags.dup
176
+ tags.delete_if { |a| a =~ /^#{key}:/ }
177
+ ::Sapience.logger.warn("WARNING: tag '#{key}' already exist, overwritten with #{value}") if tags != old_tags
178
+ end
150
179
  end
151
180
  end
152
181
  end
@@ -1,3 +1,3 @@
1
1
  module Sapience
2
- VERSION = "2.3.5"
2
+ VERSION = "2.4.0"
3
3
  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.3.5
4
+ version: 2.4.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-06-28 00:00:00.000000000 Z
12
+ date: 2017-07-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby