scout_apm_savemoney 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: db024a1f4a67d8ab49b67abf11a2da233883f062a546b9e1cc12e9b84b237c4f
4
+ data.tar.gz: 22c25b68e14f4e00c0e2b7e13d8deaeab7797adaddfeb93dd8d59c209ed19054
5
+ SHA512:
6
+ metadata.gz: 9588763b3688ab0fb6960249b03b0368a99d47c9d153180dfcefcb50c85e5cacde23bc7bfb89817142b2e7c2df22a65d0d8ec3d208fbb86f6a9b7df263bd94f3
7
+ data.tar.gz: bae1dcfe5d1f266cf9e92c70a46d9c8cc06da2498a24ae505e8c708c8ff927def59d2a675542764a77323c55afd4bf43c10219e5a222bcc2e1d6cdcb773fb123
@@ -0,0 +1,36 @@
1
+ # scout_apm_savemoney
2
+
3
+ Instrument only a percentage of your Rails app's web requests and background jobs in Scout APM so you can subscribe to a lower plan in Scout APM and save money
4
+
5
+ ## Installation
6
+
7
+ Add `scout_apm_savemoney` to your Rails app's Gemfile
8
+
9
+ ```
10
+ gem "scout_apm_savemoney"
11
+ ```
12
+
13
+ and bundle install
14
+
15
+ ```
16
+ bundle install
17
+ ```
18
+
19
+ Now, in an initializer, configure `scout_apm_savemoney` to only send a percentage of web requests and background jobs to Scout APM
20
+
21
+ ```ruby
22
+ # config/initializers/scout_apm_savemoney.rb
23
+
24
+ ScoutApmSaveMoney.configure do |config|
25
+ config.web_requests_instrumentation_percentage = 10
26
+ config.background_jobs_instrumentation_percentage = 10
27
+ end
28
+ ```
29
+
30
+ ## Why
31
+
32
+ Application Performance Management (APM) tools are often expensive. This forces many startups to forego using an APM tool. This gem helps you instrument only a percentage of your Rails app's web requests and background jobs in Scout APM so you can subscribe to a plan that's affordable for you now and later upgrade as your revenue grows.
33
+
34
+ ## Todos
35
+
36
+ - Support other background job systems in addition to Sidekiq
@@ -0,0 +1,7 @@
1
+ # @example
2
+ # GEM_HOST_API_KEY="our_rubygems_api_key" bundle exec rake publish_to_rubygems
3
+ task :publish_to_rubygems do
4
+ `gem build scout_apm_savemoney.gemspec`
5
+ require_relative "lib/scout_apm_savemoney/version"
6
+ `gem push scout_apm_savemoney-#{ScoutApmSaveMoney::VERSION}.gem`
7
+ end
@@ -0,0 +1,26 @@
1
+ require "scout_apm_savemoney/version"
2
+ require "scout_apm_savemoney/config"
3
+ require "scout_apm_savemoney/instrument_a_percentage_of_background_jobs_in_scout_apm"
4
+ require "scout_apm_savemoney/instrument_a_percentage_of_web_requests_in_scout_apm"
5
+
6
+ module ScoutApmSaveMoney
7
+ class << self
8
+ def configure
9
+ yield config
10
+
11
+ ApplicationController.class_eval do
12
+ include ScoutApmSaveMoney::InstrumentAPercentageOfWebRequestsInScoutApm
13
+ end
14
+
15
+ Sidekiq.configure_server do |config|
16
+ config.server_middleware do |chain|
17
+ chain.add ScoutApmSaveMoney::InstrumentAPercentageOfBackgroundJobsInScoutApm
18
+ end
19
+ end
20
+ end
21
+
22
+ def config
23
+ @config ||= Config.new
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ module ScoutApmSaveMoney
2
+ class Config
3
+ attr_accessor :web_requests_instrumentation_percentage
4
+ attr_accessor :background_jobs_instrumentation_percentage
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ module ScoutApmSaveMoney
2
+ class InstrumentAPercentageOfBackgroundJobsInScoutApm
3
+ def call(worker, msg, queue)
4
+ disable_scout_instrumentation unless instrument_job?
5
+ yield
6
+ end
7
+
8
+ private
9
+
10
+ def instrument_job?
11
+ rand < (ScoutApmSaveMoney.config.background_jobs_instrumentation_percentage / 100.0)
12
+ end
13
+
14
+ def disable_scout_instrumentation
15
+ ScoutApm::Transaction.ignore!
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module ScoutApmSaveMoney
2
+ module InstrumentAPercentageOfWebRequestsInScoutApm
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action :instrument_a_percentage_of_web_requests_in_scout
7
+ end
8
+
9
+ def scout_instrument_a_percentage_of_requests
10
+ disable_scout_instrumentation unless instrument_request?
11
+ end
12
+
13
+ private
14
+
15
+ def instrument_request?
16
+ rand < (ScoutApmSaveMoney.config.web_requests_instrumentation_percentage / 100.0)
17
+ end
18
+
19
+ def disable_scout_instrumentation
20
+ ScoutApm::Transaction.ignore!
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module ScoutApmSaveMoney
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scout_apm_savemoney
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nisanth Chunduru
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: scout_apm
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Send a percentage of web requests and background jobs to Scout APM so
70
+ you can subscribe to a lower plan and save money
71
+ email:
72
+ - nisanth074@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - README.md
78
+ - Rakefile
79
+ - lib/scout_apm_savemoney.rb
80
+ - lib/scout_apm_savemoney/config.rb
81
+ - lib/scout_apm_savemoney/instrument_a_percentage_of_background_jobs_in_scout_apm.rb
82
+ - lib/scout_apm_savemoney/instrument_a_percentage_of_web_requests_in_scout_apm.rb
83
+ - lib/scout_apm_savemoney/version.rb
84
+ homepage: https://github.com/nisanth074/scout_apm_savemoney
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubygems_version: 3.1.4
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Send a percentage of web requests and background jobs to Scout APM
107
+ test_files: []