Skip to content

Commit 8ae1836

Browse files
committed
Fixed: Priority sampling mishandling agent response.
1 parent edd3d55 commit 8ae1836

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

lib/ddtrace/transport.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def process_callback(action, response)
219219
@response_callback.call(action, response, @api)
220220
rescue => e
221221
Tracer.log.debug("Error processing callback: #{e}")
222+
@mutex.synchronize { @count_internal_error += 1 }
222223
end
223224
end
224225
end

lib/ddtrace/writer.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ def sampling_updater(action, response, api)
120120
return unless action == :traces && response.is_a?(Net::HTTPOK)
121121

122122
if api[:version] == HTTPTransport::V4
123-
service_rates = JSON.parse(response.body)
124-
@priority_sampler.update(service_rates)
123+
body = JSON.parse(response.body)
124+
if body.is_a?(Hash) && body.key?('rate_by_service')
125+
@priority_sampler.update(body['rate_by_service'])
126+
end
125127
true
126128
else
127129
false

spec/ddtrace/writer_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@
167167
context 'and is a :traces action' do
168168
context 'and is API v4' do
169169
let(:api) { { version: Datadog::HTTPTransport::V4 } }
170+
let(:body) { sampling_response.to_json }
171+
let(:sampling_response) { { 'rate_by_service' => service_rates } }
170172
let(:service_rates) { { 'service:a,env:test' => 0.1, 'service:b,env:test' => 0.5 } }
171-
let(:body) { service_rates.to_json }
172173

173174
it do
174175
expect(sampler).to receive(:update).with(service_rates)

0 commit comments

Comments
 (0)