Fix priority sampling mishandling agent response #591
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While adding debugging metrics to the tracer, I discovered that when priority sampling is enabled, the writer mishandles the JSON response it receives from the agent, when trying to use it to update its sampling rates.
It was receiving a response formatted like:
However, the logic was written such that it didn't expect a top level key
"rate_by_service"
, so it consumes that key as a service improperly, and throws an error when trying to process the Hash like a Float.This bug was hidden because the callback that did this was wrapped with exception handling which silently appended to a debug log, instead of raising an exception or increasing the internal error metric.
This pull request fixes the bug by consuming the value properly, and now properly asserts that the internal error metric does not increase in the test, which should prevent a similar bug from going unnoticed in the future.