-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PROF-9821] Fix incorrect code provenance due to broken JSON monkey patch #3695
[PROF-9821] Fix incorrect code provenance due to broken JSON monkey patch #3695
Conversation
…atch **What does this PR do?** This PR tweaks the `Datadog::Profiling::Collectors::CodeProvenance::Library` class so that if it is encoded instance-filed-by-instance-field it results in a correct code provenance JSON file. Specifically, the `path` argument is now stored as a `paths` array, to match what we expect in the JSON file. **Motivation:** We've discovered that in a certain combination of the oj and activesupport libraries, when oj is used to replace the standard library JSON gem, it incorrectly encodes our `Library` instances instance-field-by-instance-field instead of calling `#to_json`. This resulted in incorrect code provenance files, which would be rejected by the backend. Since the change is trivial (`path` => `paths` array), I've opted to change the shape of `Library` so that it still encodes correctly in the presence of a buggy JSON encoder monkey patch. **Additional Notes:** N/A **How to test the change?** I've added coverage to this issue. I did it in a bit of a roundabout way (using YAML), see details for why, but I claim it's a reasonable proxy for any encoder that encodes field-by-field, including oj.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3695 +/- ##
=======================================
Coverage 98.11% 98.11%
=======================================
Files 1225 1225
Lines 72743 72755 +12
Branches 3479 3479
=======================================
+ Hits 71369 71382 +13
+ Misses 1374 1373 -1 ☔ View full report in Codecov by Sentry. |
path: '/example/path/to/datadog/gem', | ||
) | ||
|
||
serialized_without_to_json = YAML.dump(instance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the reasoning here that YAML serialization is performed field by field, same as some JSON libraries would serialize, or that libraries like oj
actually use YAML serialization logic? I am guessing it's the former and if so, a comment to this effect in the code would be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I've added a comment above the spec stating this:
# So instead in this test we use YAML as an example of an encoder that doesn't use #to_json, and does it
# field-by-field. Thus if the Library class doesn't match exactly what we want in the output, this test will fail.
What does this PR do?
This PR tweaks the
Datadog::Profiling::Collectors::CodeProvenance::Library
class so that if it is encoded instance-filed-by-instance-field it results in a correct code provenance JSON file.Specifically, the
path
argument is now stored as apaths
array, to match what we expect in the JSON file.Motivation:
We've discovered that in a certain combination of the oj and activesupport libraries, when oj is used to replace the standard library JSON gem, it incorrectly encodes our
Library
instances instance-field-by-instance-field instead of calling#to_json
.This resulted in incorrect code provenance files, which would be rejected by the backend.
Since the change is trivial (
path
=>paths
array), I've opted to change the shape ofLibrary
so that it still encodes correctly in the presence of a buggy JSON encoder monkey patch.Additional Notes:
N/A
How to test the change?
I've added coverage to this issue. I did it in a bit of a roundabout way (using YAML), see details for why, but I claim it's a reasonable proxy for any encoder that encodes field-by-field, including oj.