zuora_observability 0.1.0.pre.a → 0.1.0.pre.b

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
  SHA256:
3
- metadata.gz: c7e3a6c154d518f30f5a95e1be272b96b1853b46df0300d4fa45ca8e17f04451
4
- data.tar.gz: 0c510e0da92d8b7139586e60bd048bc91f18cc61a9cfe8165f4f44676c223180
3
+ metadata.gz: f3c6f15e5345dd32d8ada993579cf90efa2a2382573fe86f608f598be3f69f9e
4
+ data.tar.gz: 38035565943c737e2f5ac59032780b6ce0c9e2eed0d039870d9b31b4780f7629
5
5
  SHA512:
6
- metadata.gz: 3948b6dacece27853e9df426c81d6f475c1b8b5417131c4318eeac8b88c8ffa4c4f625036f95cc5b73ed78ed53352f182c2f7efb16800e313b797a7416372b3b
7
- data.tar.gz: f67b67d6bbbf2ff33c30433f32f321bf28109540bbf54250764509332de9caba0dbcf94917439882ea7a0f8d6e1bc437eae221134ceb4adfac00933dddadd1f6
6
+ metadata.gz: c51373a4c25bebde5158c57e035a4363895f67c6f991fc7dbcd9a0741496e65ae07d7f6f65da86f8de14c4ef86ea509f0ba110d9fd7e3d29dcaa83e19117bbd6
7
+ data.tar.gz: ca248b0270c959804ded1396591e6bacde2abaa2f478ea3b12c2a8265716562ddf0f8f87ddbd90f1ba228657568c337258936faaccebb9540dcbdff59e2903f9
data/README.md CHANGED
@@ -3,9 +3,27 @@
3
3
  A ruby gem to enable observability into rails applications
4
4
 
5
5
  ## Usage
6
- How to use my plugin.
6
+
7
+ ### Configuration
8
+
9
+ Observability can be configured through an initializer as shown below.
10
+
11
+ ```ruby
12
+ # config/initializers/zuora_observability.rb
13
+ ZuoraObservability.configure do |config|
14
+ config.enable_metrics = true
15
+ end
16
+ ```
17
+
18
+ | Configuration Field | Default Value | Description |
19
+ | ------------------- | ---------------------------------------------------------------- | ------------------------------------ |
20
+ | `enable_metrics` | `false` | Enables writing metrics to telegraf |
21
+ | `telegraf_endpoint` | `'udp://telegraf-app-metrics.monitoring.svc.cluster.local:8094'` | The URL to send telegraf metrics to |
22
+ | `telegraf_debug` | `false` | Log info about data sent to telegraf |
23
+ | `json_logging` | `false` in development/test, `true` otherwise | Use structured JSON logging for ZuoraObservability::Logger. **This configuration option cannot be changed in an initializer, but can be set to `true` with the presence of `ZUORA_JSON_LOGGING` environment variable** |
7
24
 
8
25
  ## Installation
26
+
9
27
  Add this line to your application's Gemfile:
10
28
 
11
29
  ```ruby
@@ -13,14 +31,17 @@ gem 'zuora_observability'
13
31
  ```
14
32
 
15
33
  And then execute:
34
+
16
35
  ```bash
17
36
  $ bundle
18
37
  ```
19
38
 
20
39
  Or install it yourself as:
40
+
21
41
  ```bash
22
42
  $ gem install zuora_observability
23
43
  ```
24
44
 
25
45
  ## License
46
+
26
47
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ if defined?(Resque.logger)
4
+ Resque.logger = ZuoraObservability::Logger.custom_logger(name: 'Resque', type: 'Monologger', level: MonoLogger::INFO)
5
+ if defined?(Resque::Scheduler)
6
+ Resque::Scheduler.logger = ZuoraObservability::Logger.custom_logger(name: 'ResqueScheduler')
7
+ end
8
+ end
9
+
10
+ if defined?(Delayed::Worker.logger)
11
+ Delayed::Worker.logger = ZuoraObservability::Logger.custom_logger(
12
+ name: 'DelayedJob', type: 'Monologger', level: MonoLogger::INFO
13
+ )
14
+ end
15
+
16
+ if defined?(Makara)
17
+ Makara::Logging::Logger.logger = ZuoraObservability::Logger.custom_logger(name: 'Makara')
18
+ end
19
+
20
+ if defined?(ElasticAPM) && ElasticAPM.running?
21
+ ElasticAPM.agent.config.logger = ZuoraObservability::Logger.custom_logger(name: 'ElasticAPM', level: MonoLogger::WARN)
22
+ end
23
+
24
+ if defined?(ActionMailer)
25
+ ActionMailer::Base.logger = ZuoraObservability::Logger.custom_logger(name: 'ActionMailer', type: 'Monologger')
26
+ end
@@ -10,7 +10,9 @@ module ZuoraObservability
10
10
  @enable_metrics = false
11
11
  @telegraf_endpoint = 'udp://telegraf-app-metrics.monitoring.svc.cluster.local:8094'
12
12
  @telegraf_debug = false
13
- @json_logging = false
13
+ # NOTE(hartley): this checks the var for presence rather than value to
14
+ # align with how Rails does RAILS_LOG_TO_STDOUT
15
+ @json_logging = ENV['ZUORA_JSON_LOGGING'].present? ? true : !(Rails.env.development? || Rails.env.test?)
14
16
  end
15
17
  end
16
18
  end
@@ -1,19 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'zuora_observability/metrics/page_request'
4
+
3
5
  module ZuoraObservability
4
6
  # The ZuoraObservability Engine is mounted to hook into Rails
5
7
  class Engine < ::Rails::Engine
6
8
  isolate_namespace ZuoraObservability
7
9
 
10
+ REQUEST_HEADERS_TO_IGNORE = %w[
11
+ RAW_POST_DATA
12
+ REQUEST_METHOD
13
+ REQUEST_URI
14
+ REQUEST_PATH
15
+ PATH_INFO
16
+ CONTENT_TYPE
17
+ ORIGINAL_FULLPATH
18
+ QUERY_STRING
19
+ ].freeze
20
+
8
21
  config.generators do |g|
9
22
  g.test_framework :rspec
10
23
  end
11
24
 
25
+ # hook to process_action
26
+ ActiveSupport::Notifications.subscribe(
27
+ 'process_action.action_controller',
28
+ ZuoraObservability::Metrics::PageRequest.new
29
+ )
30
+
12
31
  initializer(:rails_stdout_logging, before: :initialize_logger) do
13
32
  require 'lograge'
14
33
 
15
34
  Rails.configuration.logger = ZuoraObservability::Logger.custom_logger(name: "Rails")
16
- if !Rails.env.test? && !Rails.env.development?
35
+
36
+ if ZuoraObservability.configuration.json_logging
17
37
  Rails.configuration.lograge.enabled = true
18
38
  Rails.configuration.colorize_logging = false
19
39
  end
@@ -5,8 +5,11 @@ require 'mono_logger'
5
5
  module ZuoraObservability
6
6
  # A configurable logger that can be used for Rails and additional libraries
7
7
  module Logger
8
- # NOTE(hartley): potentially change Logger module to delegate methods to
9
- # value returned from custom_logger (so it ends up being a pure wrapper)
8
+ # NOTE(hartley): replace this with a subclass of Ougai Logger
9
+ # - enable silence method for Rails 5.2 asset requests
10
+ # https://github.com/tilfin/ougai/wiki/Use-as-Rails-logger
11
+ # - potentially integrate with MonoLogger so no conditional is needed
12
+ # https://github.com/tilfin/ougai/issues/74
10
13
  def self.custom_logger(name: "", level: Rails.logger.present? ? Rails.logger.level : MonoLogger::INFO, type: :ougai)
11
14
  #puts name + ' - ' + {Logger::WARN => 'Logger::WARN', Logger::ERROR => 'Logger::ERROR', Logger::DEBUG => 'Logger::DEBUG', Logger::INFO => 'Logger::INFO' }[level] + ' - '
12
15
  if type == :ougai
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZuoraObservability
4
+ module Metrics
5
+ # Object of this class is passed to the ActiveSupport::Notification hook
6
+ class PageRequest
7
+ # This method is triggered when a non error page is loaded (not 404)
8
+ def call(_name, started, finished, unique_id, payload)
9
+ # If the url contains any css or JavaScript files then do not collect metrics for them
10
+ return nil if %w[css assets jpg png jpeg ico].any? { |word| payload[:path].include?(word) }
11
+
12
+ # Getting the endpoint and the content_type
13
+ content_hash = { :html => 'text/html', :js => 'application/javascript', :json => 'application/json', :csv => 'text/csv' }
14
+ content_type = content_hash.key?(payload[:format]) ? content_hash[payload[:format]] : payload[:format]
15
+ content_type = content_type.to_s.gsub('text/javascript', 'application/javascript')
16
+
17
+ # payloads with 500 requests do not have status as it is not set by the controller
18
+ # https://github.com/rails/rails/issues/33335
19
+ # status_code = payload[:status] ? payload[:status] : payload[:exception_object].present? ? 500 : ""
20
+ if payload[:exception].present?
21
+ status_code, exception = [500, payload[:exception].first]
22
+ else
23
+ status_code, exception = [payload[:status], nil]
24
+ end
25
+
26
+ tags = { method: payload[:method], status: status_code, error_type: exception, content_type: content_type, controller: payload[:controller], action: payload[:action] }.compact
27
+
28
+ values = { view_time: payload[:view_runtime], db_time: payload[:db_runtime], response_time: ((finished - started) * 1000) }.compact
29
+ values = values.map { |k, v| [k, v.round(2)] }.to_h
30
+
31
+ ZuoraObservability::Metrics.write_to_telegraf(direction: :inbound, tags: tags, values: values)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZuoraObservability
4
- VERSION = '0.1.0-a'
4
+ VERSION = '0.1.0-b'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_observability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.a
4
+ version: 0.1.0.pre.b
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hartley McGuire
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-25 00:00:00.000000000 Z
11
+ date: 2020-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lograge
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mono_logger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: ougai
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +66,6 @@ dependencies:
52
66
  - - '='
53
67
  - !ruby/object:Gem::Version
54
68
  version: 1.0.0
55
- - !ruby/object:Gem::Dependency
56
- name: mono_logger
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rails
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -253,6 +253,7 @@ files:
253
253
  - app/mailers/zuora_observability/application_mailer.rb
254
254
  - app/models/zuora_observability/application_record.rb
255
255
  - app/views/layouts/zuora_observability/application.html.erb
256
+ - config/initializers/loggers.rb
256
257
  - config/routes.rb
257
258
  - lib/tasks/zuora_observability_tasks.rake
258
259
  - lib/zuora_observability.rb
@@ -262,6 +263,7 @@ files:
262
263
  - lib/zuora_observability/logger.rb
263
264
  - lib/zuora_observability/logging/formatter.rb
264
265
  - lib/zuora_observability/metrics.rb
266
+ - lib/zuora_observability/metrics/page_request.rb
265
267
  - lib/zuora_observability/metrics/point_value.rb
266
268
  - lib/zuora_observability/metrics/telegraf.rb
267
269
  - lib/zuora_observability/version.rb