sapience 2.2.3 → 2.3.3

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: e548f9ac78525b4bdc14737a9351027a4e61ad16
4
- data.tar.gz: baf8e6f1ba2ba1d62fb94175568d60f84537a20f
3
+ metadata.gz: 45cf15c8cd01eccd3169eec6a03022ad719cb869
4
+ data.tar.gz: 554f7d8d2050b1700d8ad625a9ae9a0c3d891fa8
5
5
  SHA512:
6
- metadata.gz: e87aff1fbda64a208ed11b4b5783977f68c3af0d4d1c7b3e409e746d6aaf41a6fe1617472cf8884565249da862e1a6c0635c7d3f7d6d3bd423c7c7bc4c417fc8
7
- data.tar.gz: d9d0154a073a774a69b3666a2dd2a283ed07b6b1518d88c38dc88da89288df1fe21c2307a91a9d3180905519a7e7728d641b4fd5e65b64167f19cf9638ed5c3f
6
+ metadata.gz: 137cc64c62b9205a8cf0ee79f9268fe0393b95e6416455590f6487b96005e789dce97bc599aa0deb774652cecb98444a5fbf1e1fe2a9b48d6ed853d28630c9fd
7
+ data.tar.gz: ae743a5713cf3743f1e835c80b7838ea83299a6e51cd287d67f50486652f90af0d26cafd6d69b51fc44824cdca78782b285dade3f955b896f866fb900a08f058
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## v2.3.3
2
+
3
+ - Put back single_thread_executor and leave immediate_executor only for test environment
4
+
5
+
6
+ ## v2.3.2
7
+
8
+ - Changing the log level of ActiveRecord has the side effect of changing the
9
+ log level of Rails.logger. We don't want that therefore we remove the
10
+ assignment.
11
+
12
+ ## v2.3.1
13
+
14
+ - Add namespaced events
15
+
1
16
  ## v2.2.3
2
17
 
3
18
  - Set immediate_executor by default to avoid Errno::EIO error for multithreaded processes.
data/README.md CHANGED
@@ -104,7 +104,6 @@ Add a `config/sapience.yml` file to you appplication. Or if you, like us, have m
104
104
  default:
105
105
  app_name: My Application
106
106
  log_level: debug
107
- log_level_active_record: info
108
107
  appenders:
109
108
  - stream:
110
109
  io: STDOUT
@@ -159,7 +158,6 @@ production:
159
158
  Sapience.configure(force: true) do |config|
160
159
  config.app_name = "My Application"
161
160
  config.default_level = :info
162
- config.log_level_active_record = :info
163
161
  config.backtrace_level = :error
164
162
  config.filter_parameters = %w(password password_confirmation)
165
163
  config.appenders = [
data/config/default.yml CHANGED
@@ -3,7 +3,7 @@ default:
3
3
  filter_parameters:
4
4
  - password
5
5
  - password_confirmation
6
- log_executor: immediate_executor
6
+ log_executor: single_thread_executor
7
7
  log_level: info
8
8
  appenders:
9
9
  - stream:
@@ -12,6 +12,7 @@ default:
12
12
 
13
13
  test:
14
14
  log_level: warn
15
+ log_executor: immediate_executor
15
16
  appenders:
16
17
  - stream:
17
18
  file_name: log/test.log
data/docs/metrics.md CHANGED
@@ -45,6 +45,7 @@ metrics.count("metric-key", -3)
45
45
  metrics.histogram("metric-key", 2_500)
46
46
  metrics.gauge("metric-key", 1_000, {})
47
47
  metrics.event("metric-key", "description about event", {})
48
+ metrics.event("metric-key", "description about event", {namespace: true})
48
49
  metrics.batch do
49
50
  metrics.event("metric-key", "description about event", {})
50
51
  metrics.increment("another-metric-key", 2)
@@ -85,3 +86,24 @@ We use it mainly for error metrics. Example:
85
86
  ```ruby
86
87
  metrics.increment('error', tags: %w(error_class:AccessDenied module:authentication component:permissions))
87
88
  ```
89
+
90
+ ### Event Metric
91
+
92
+ For the `event` metric the first parameter is `title` - string.
93
+ By default it is not namespaced, however with option `namespace: true` it will automatically namespace it.
94
+
95
+
96
+ ```ruby
97
+ metrics.event("metric-key", "description about event", {namespace: true})
98
+
99
+ ```
100
+ Output: `app_name.environment.metric-key`
101
+
102
+ #### Event Grouping
103
+
104
+ In order to group similar events, use option: `aggregation_key`
105
+
106
+ ```ruby
107
+ metrics.event("metric-key", "description about event", {namespace: true, aggregation_key:true})
108
+
109
+ ```
@@ -4,14 +4,13 @@ module Sapience
4
4
 
5
5
  # rubocop:disable ClassVars
6
6
  class Configuration
7
- attr_reader :default_level, :log_level_active_record, :backtrace_level, :backtrace_level_index
7
+ attr_reader :default_level, :backtrace_level, :backtrace_level_index
8
8
  attr_writer :host
9
9
  attr_accessor :app_name, :ap_options, :appenders, :log_executor, :filter_parameters, :metrics, :error_handler
10
10
 
11
11
  SUPPORTED_EXECUTORS = %i(single_thread_executor immediate_executor).freeze
12
12
  DEFAULT = {
13
13
  log_level: :info,
14
- log_level_active_record: :info,
15
14
  host: nil,
16
15
  ap_options: { multiline: false },
17
16
  appenders: [{ stream: { io: STDOUT, formatter: :color } }],
@@ -28,7 +27,6 @@ module Sapience
28
27
  @options[:log_executor] &&= @options[:log_executor].to_sym
29
28
  validate_log_executor!(@options[:log_executor])
30
29
  self.default_level = @options[:log_level].to_sym
31
- self.log_level_active_record = @options[:log_level_active_record].to_sym
32
30
  self.backtrace_level = @options[:log_level].to_sym
33
31
  self.host = @options[:host]
34
32
  self.app_name = @options[:app_name]
@@ -47,13 +45,6 @@ module Sapience
47
45
  @default_level_index = level_to_index(level)
48
46
  end
49
47
 
50
- # Sets the active record log level
51
- def log_level_active_record=(level)
52
- @log_level_active_record = level
53
- # For performance reasons pre-calculate the level index
54
- @log_level_active_record_index = level_to_index(level)
55
- end
56
-
57
48
  # Returns the symbolic level for the supplied level index
58
49
  def index_to_level(level_index)
59
50
  LEVELS[level_index]
@@ -18,7 +18,7 @@ module Sapience
18
18
  logger.trace "Appender thread: Flushing appender: #{appender.class.name}"
19
19
  appender.flush
20
20
  rescue StandardError => exc
21
- logger.error "Appender thread: Failed to flush appender: #{appender.inspect}", exc
21
+ $stderr.write("Appender thread: Failed to flush to appender: #{appender.inspect}\n #{exc.inspect}")
22
22
  end
23
23
  end
24
24
 
@@ -90,9 +90,48 @@ module Sapience
90
90
  provider.batch(&block)
91
91
  end
92
92
 
93
- def event(title, text, options = {})
93
+ # Create Event
94
+ #
95
+ # @param [String] title the title of the event
96
+ # @param [String] text the description
97
+ # @param [Hash] opts event options
98
+ # @option opts [Array] :namespaced_keys the keys we want to be namespaced. Valid: :title or :aggregation_key
99
+ # @option opts [String] :namespace_prefix custom namespace
100
+ # (to override default from Sapience `app_name.environment`)
101
+ # @option opts [String] :aggregation_key custom aggregation_key
102
+ # (to override default based on `title`, only applies when :aggregation_key includes in namespaced_keys option)
103
+ #
104
+ # @example Create an Event
105
+ # Sapience.metrics.event('article-published', "article #123")
106
+ #
107
+ # @example Create a namespaced Event with default namespacing
108
+ # Sapience.metrics.event('article-published', "article #123", {namespaced_keys: [:title, :aggregation_key]})
109
+ #
110
+ # @example Create a namespaced Event with custom namespacing
111
+ # Sapience.metrics.event(
112
+ # 'article-published',
113
+ # "article #123",
114
+ # {namespace_prefix: 'custom_namespace', namespaced_keys: [:title, :aggregation_key]}
115
+ # )
116
+ #
117
+ # @example Create an Event with a custom aggregation_key
118
+ # Sapience.metrics.event('article-published', "article #123", {aggregation_key: 'custom_aggregation_key')
119
+
120
+ def event(title, text = "", opts = {})
94
121
  return false unless valid?
95
- provider.event(title, text, options)
122
+ fail ArgumentError "Title must be provided" unless title
123
+ opts ||= {}
124
+
125
+ namespaced_keys = opts.delete(:namespaced_keys) || []
126
+ namespace_prefix = opts.delete(:namespace_prefix) || namespace
127
+
128
+ if namespaced_keys.include?(:aggregation_key)
129
+ aggregation_key = opts[:aggregation_key] || title
130
+ opts[:aggregation_key] = "#{namespace_prefix}.#{aggregation_key}"
131
+ end
132
+
133
+ title = "#{namespace_prefix}.#{title}" if namespaced_keys.include?(:title)
134
+ provider.event(title, text, opts)
96
135
  end
97
136
 
98
137
  def namespace
@@ -72,12 +72,7 @@ module Sapience
72
72
  Bugsnag.configure { |config| config.logger = Sapience[Bugsnag] } if defined?(Bugsnag)
73
73
  Sapience::Extensions::ActionController::LogSubscriber.attach_to :action_controller
74
74
  # Sapience::Extensions::ActiveSupport::MailerLogSubscriber.attach_to :action_mailer
75
- if defined?(ActiveRecord)
76
- Sapience::Extensions::ActiveRecord::Notifications.use
77
- ActiveRecord::Base.logger.level =
78
- Sapience.config.log_level_active_record if defined?(ActiveRecord::Base.logger.level)
79
- end
80
-
75
+ Sapience::Extensions::ActiveRecord::Notifications.use if defined?(ActiveRecord)
81
76
  Sapience::Extensions::ActionView::LogSubscriber.attach_to :action_view
82
77
  # Sapience::Extensions::ActiveJob::LogSubscriber.attach_to :active_job
83
78
  Sapience::Extensions::ActionController::Notifications.use
@@ -1,3 +1,3 @@
1
1
  module Sapience
2
- VERSION = "2.2.3"
2
+ VERSION = "2.3.3"
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.2.3
4
+ version: 2.3.3
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-08 00:00:00.000000000 Z
12
+ date: 2017-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby