scout_apm 6.0.1 → 6.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f7da6e5dce565451022406d4bbf06ccba3eb60cca723d391886083584595ca8
4
- data.tar.gz: a9001c043e9f4b7afb9c556474e0b50baecbb191a05bc3b308f85072443df914
3
+ metadata.gz: af813ad30f40b8cee3cb1e50c8b6ca311c8347d0431d18c6e5ce0939cda174e5
4
+ data.tar.gz: d9baccb3c23a1c45571503349ddbc4dc4de4f0e48fbf10ee7fd40ce7f7b76b2f
5
5
  SHA512:
6
- metadata.gz: 39de9f2fe98871ab474a43c784c9db73a800832e5ac6757004036065c0ea9f68955f36e953fa36249d5ce7d78c289aa9e373d8f01fe83c22c6987bd149eeab34
7
- data.tar.gz: 588d9fad7ad1fe3084ed28b2ce9565cda61eb694389bfefae3f065ace19f09b463c5de801766ab105540385350ed8d8ee2e6be545842794b8f60821cc2f0d5b1
6
+ metadata.gz: 1d08de0c4f24ca6d8385a381705134baff6c5b65463f4775d78eae4c03bdc91195acfb24edf666743cf2e3064b20780251f345b6b4e02ac658e7841633986f51
7
+ data.tar.gz: ef12b4f094e373c5769e79c55a047b1b90db1a236fdcce4a23aacd657b5703127b662549cc56e92f72172e4e5732c99a8f769376df0a231411dbcf3f7e71d253
data/CHANGELOG.markdown CHANGED
@@ -1,7 +1,17 @@
1
+ # 6.0.2
2
+ - Fix `endpoint_sample_rate` and `job_sample_rate` to support float values
3
+
1
4
  # 6.0.1
2
5
  - Fix capturing of job params for non ActiveJob
3
6
 
4
7
  # 6.0.0
8
+
9
+ **Breaking Change**
10
+ Sampling configuration options now take `float` arguments between `0.0` and `1.0`. This means
11
+ you can now set sample rates lower than one. Backwards compatibility is maintained for
12
+ existing config > 1 by converting to a percentage internally. **If your endpoint is
13
+ sampled at exactly 1%, you must now set `0.01` instead of `1`.**
14
+
5
15
  - Add Prism AutoInstruments Support (#582) (#594)
6
16
  - Add OpenSearch instrumentation (#563)
7
17
  - Add HTTPX instrumentation (#588)
@@ -2,3 +2,4 @@ eval_gemfile("../Gemfile")
2
2
 
3
3
  gem 'sqlite3', '~> 2.0'
4
4
  gem 'sidekiq', '~> 8.0'
5
+ gem 'minitest-mock'
@@ -1,3 +1,4 @@
1
1
  eval_gemfile("../Gemfile")
2
2
 
3
3
  gem "sqlite3", ">= 2.1"
4
+ gem 'minitest-mock'
@@ -213,6 +213,8 @@ module ScoutApm
213
213
 
214
214
  class SampleRateCoercion
215
215
  def coerce(val)
216
+ return nil if val.nil?
217
+ return nil if val.to_s.strip.empty?
216
218
  v = val.to_f
217
219
  # Anything above 1 is assumed a percentage for backwards compat, so convert to a decimal
218
220
  if v > 1
@@ -252,8 +254,8 @@ module ScoutApm
252
254
  'sample_rate' => SampleRateCoercion.new,
253
255
  'sample_endpoints' => JsonCoercion.new,
254
256
  'sample_jobs' => JsonCoercion.new,
255
- 'endpoint_sample_rate' => NullableIntegerCoercion.new,
256
- 'job_sample_rate' => NullableIntegerCoercion.new,
257
+ 'endpoint_sample_rate' => SampleRateCoercion.new,
258
+ 'job_sample_rate' => SampleRateCoercion.new,
257
259
  'start_resque_server_instrument' => BooleanCoercion.new,
258
260
  'timeline_traces' => BooleanCoercion.new,
259
261
  'auto_instruments' => BooleanCoercion.new,
@@ -1,3 +1,3 @@
1
1
  module ScoutApm
2
- VERSION = "6.0.1"
2
+ VERSION = "6.0.2"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -3,7 +3,7 @@ require 'simplecov'
3
3
  SimpleCov.start
4
4
 
5
5
  require 'minitest/autorun'
6
- require 'minitest/unit'
6
+ require 'minitest/mock'
7
7
  require 'minitest/pride'
8
8
  require 'mocha/minitest'
9
9
  require 'pry'
@@ -94,15 +94,24 @@ class ConfigTest < Minitest::Test
94
94
 
95
95
  def test_sample_rate_coercion
96
96
  coercion = ScoutApm::Config::SampleRateCoercion.new
97
+ # Preserves nil and empty strings
98
+ assert_nil coercion.coerce(nil)
99
+ assert_nil coercion.coerce("")
100
+ assert_nil coercion.coerce(" ")
101
+ # Float strings work
97
102
  assert_in_delta 1.0, coercion.coerce("1")
98
103
  assert_in_delta 0.015, coercion.coerce("1.5")
104
+ assert_in_delta 0.5, coercion.coerce("0.5")
105
+ assert_in_delta 0.01, coercion.coerce("0.01")
106
+ # Numbers work
99
107
  assert_in_delta 1.0, coercion.coerce(1)
100
108
  assert_in_delta 0.015, coercion.coerce(1.5)
101
109
  assert_in_delta 0.0, coercion.coerce("0")
102
110
  assert_in_delta 0.0, coercion.coerce(0)
103
- assert_in_delta 0.0, coercion.coerce("")
104
- assert_in_delta 0.0, coercion.coerce(nil)
105
- assert_in_delta 0.5, coercion.coerce("0.5")
111
+ # Backwards compatibility: values > 1 treated as percentages
112
+ assert_in_delta 0.15, coercion.coerce("15")
113
+ assert_in_delta 0.15, coercion.coerce(15)
114
+ # Clamping
106
115
  assert_in_delta 0, coercion.coerce("-2.5")
107
116
  end
108
117
 
@@ -116,4 +125,52 @@ class ConfigTest < Minitest::Test
116
125
  conf = ScoutApm::Config.with_file(@context, "a_file_that_doesnt_exist.yml")
117
126
  assert conf.any_keys_found?
118
127
  end
128
+
129
+ def test_endpoint_sample_rate_from_env_with_float_string
130
+ ENV['SCOUT_ENDPOINT_SAMPLE_RATE'] = '0.01'
131
+ conf = ScoutApm::Config.without_file(@context)
132
+ assert_in_delta 0.01, conf.value('endpoint_sample_rate')
133
+ ensure
134
+ ENV.delete('SCOUT_ENDPOINT_SAMPLE_RATE')
135
+ end
136
+
137
+ def test_job_sample_rate_from_env_with_float_string
138
+ ENV['SCOUT_JOB_SAMPLE_RATE'] = '0.01'
139
+ conf = ScoutApm::Config.without_file(@context)
140
+ assert_in_delta 0.01, conf.value('job_sample_rate')
141
+ ensure
142
+ ENV.delete('SCOUT_JOB_SAMPLE_RATE')
143
+ end
144
+
145
+ def test_endpoint_sample_rate_backwards_compat_with_percentage
146
+ # Values > 1 should be treated as percentages for backwards compatibility
147
+ ENV['SCOUT_ENDPOINT_SAMPLE_RATE'] = '15'
148
+ conf = ScoutApm::Config.without_file(@context)
149
+ assert_in_delta 0.15, conf.value('endpoint_sample_rate')
150
+ ensure
151
+ ENV.delete('SCOUT_ENDPOINT_SAMPLE_RATE')
152
+ end
153
+
154
+ def test_job_sample_rate_backwards_compat_with_percentage
155
+ # Values > 1 should be treated as percentages for backwards compatibility
156
+ ENV['SCOUT_JOB_SAMPLE_RATE'] = '15'
157
+ conf = ScoutApm::Config.without_file(@context)
158
+ assert_in_delta 0.15, conf.value('job_sample_rate')
159
+ ensure
160
+ ENV.delete('SCOUT_JOB_SAMPLE_RATE')
161
+ end
162
+
163
+ def test_endpoint_sample_rate_nil_when_not_set
164
+ # Nil allows sampling to fall through to global sample_rate
165
+ ENV.delete('SCOUT_ENDPOINT_SAMPLE_RATE')
166
+ conf = ScoutApm::Config.without_file(@context)
167
+ assert_nil conf.value('endpoint_sample_rate')
168
+ end
169
+
170
+ def test_job_sample_rate_nil_when_not_set
171
+ # Nil allows sampling to fall through to global sample_rate
172
+ ENV.delete('SCOUT_JOB_SAMPLE_RATE')
173
+ conf = ScoutApm::Config.without_file(@context)
174
+ assert_nil conf.value('job_sample_rate')
175
+ end
119
176
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1
4
+ version: 6.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Haynes