Skip to content

Commit 3be61a8

Browse files
authored
Merge pull request #591 from DataDog/fix/priority_sampling_response_parsing
Fix priority sampling mishandling agent response
2 parents d8d6777 + 8ae1836 commit 3be61a8

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
@@ -221,6 +221,7 @@ def process_callback(action, response)
221221
@response_callback.call(action, response, @api)
222222
rescue => e
223223
Tracer.log.debug("Error processing callback: #{e}")
224+
@mutex.synchronize { @count_internal_error += 1 }
224225
end
225226
end
226227
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)