scout_apm_sampler 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 075bbdbacb17f3987b92093b6298c71a5f7af5ba0294f848221f2c5efe13033d
4
+ data.tar.gz: 1825f950472d33c44273f2cdb48dd8df62f9d20a2d599fda6f7ed133fd658d87
5
+ SHA512:
6
+ metadata.gz: 31c6fc355b493253418116826eb34ed693861a775bac20c3f4049fb9ace99a329efa3772a461909704082ed5dce6f87d46290d35cc429b7715c937a47abd50b0
7
+ data.tar.gz: be4c27c79bfe3026b58f868f3f33898c346df5a8c4d91c1319959f1d488d3291f552a9fd9fefd0fc740682e9495ad0879950712b8c41eb0ffb02e5a5a3a919e6
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # scout_apm_sampler
2
+
3
+ Instrument only a percentage of your Rails app's web requests and background jobs in Scout APM so you can subscribe to an affordable plan in Scout APM
4
+
5
+ ## Why
6
+
7
+ 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.
8
+
9
+
10
+ ## Installation
11
+
12
+ Add `scout_apm_sampler` to your Rails app's Gemfile
13
+
14
+ ```
15
+ gem "scout_apm_sampler"
16
+ ```
17
+
18
+ and bundle install
19
+
20
+ ```
21
+ bundle install
22
+ ```
23
+
24
+ Now, in an initializer, configure `scout_apm_sampler` to only send a percentage of web requests and background jobs to Scout APM
25
+
26
+ ```ruby
27
+ # config/initializers/scout_apm_sampler.rb
28
+
29
+ ScoutApmSampler.configure do |config|
30
+ config.web_request_sampling_rate = 0.1
31
+ config.background_job_sampling_rate = 0.05
32
+ end
33
+ ```
34
+
35
+ ## Todos
36
+
37
+ - Support other background job systems in addition to Sidekiq
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require_relative "lib/scout_apm_sampler/version"
2
+
3
+ task :publish do
4
+ `gem build scout_apm_sampler.gemspec`
5
+ current_version = ScoutApmSampler::VERSION
6
+ gem_push_command = "gem push scout_apm_sampler-#{current_version}.gem"
7
+ system(gem_push_command)
8
+ end
@@ -0,0 +1,18 @@
1
+ module ScoutApmSampler
2
+ class BackgroundJobSampler
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 < ScoutApmSampler.config.background_job_sampling_rate
12
+ end
13
+
14
+ def disable_scout_instrumentation
15
+ ScoutApm::Transaction.ignore!
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ module ScoutApmSampler
2
+ class Config
3
+ attr_accessor :web_request_sampling_rate
4
+ attr_accessor :background_job_sampling_rate
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module ScoutApmSampler
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ module ScoutApmSampler
2
+ module WebRequestSampler
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 < ScoutApmSampler.config.web_request_sampling_rate
17
+ end
18
+
19
+ def disable_scout_instrumentation
20
+ ScoutApm::Transaction.ignore!
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ require "scout_apm_sampler/version"
2
+ require "scout_apm_sampler/config"
3
+ require "scout_apm_sampler/instrument_a_percentage_of_background_jobs_in_scout_apm"
4
+ require "scout_apm_sampler/instrument_a_percentage_of_web_requests_in_scout_apm"
5
+
6
+ module ScoutApmSampler
7
+ class << self
8
+ def configure
9
+ yield config
10
+
11
+ ApplicationController.class_eval do
12
+ include ScoutApmSampler::WebRequestSampler
13
+ end
14
+
15
+ Sidekiq.configure_server do |config|
16
+ config.server_middleware do |chain|
17
+ chain.add ScoutApmSampler::BackgroundJobSampler
18
+ end
19
+ end
20
+ end
21
+
22
+ def config
23
+ @config ||= Config.new
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scout_apm_sampler
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: 2022-12-25 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 affordable plan that's commensurate with your company's revenue
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_sampler.rb
80
+ - lib/scout_apm_sampler/background_job_sampler.rb
81
+ - lib/scout_apm_sampler/config.rb
82
+ - lib/scout_apm_sampler/version.rb
83
+ - lib/scout_apm_sampler/web_request_sampler.rb
84
+ homepage: https://github.com/nisanthchunduru/scout_apm_sampler
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.6
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Send a percentage of web requests and background jobs to Scout APM
107
+ test_files: []