Skip to content
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

Fix 1116, remove parsing of resp body from http.rb instrumentation #1122

Merged
merged 4 commits into from
Jul 28, 2020

Conversation

ericmustin
Copy link
Contributor

Resolves #1116

This piggybacks off the discussion here #1117

Ultimately, it is not safe to read the http.rb response body in ddtrace: we end up consuming the body reading stream, so the host application cannot properly read it. The httprb suggests usage of .readpartial which we would also impact.

To address this issue we should stop reading the response body message altogether. This will remove some information from our error reporting, but it's ultimately required for the safe operation of ddtrace with http.rb.

@ericmustin ericmustin requested a review from a team July 27, 2020 22:47
marcotc
marcotc previously approved these changes Jul 27, 2020
lib/ddtrace/contrib/httprb/instrumentation.rb Outdated Show resolved Hide resolved
@marcotc marcotc added the bug Involves a bug label Jul 27, 2020
Co-authored-by: Marco Costa <marco.costa@datadoghq.com>
marcotc
marcotc previously approved these changes Jul 27, 2020
Copy link
Member

@marcotc marcotc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 🔨

@ericmustin
Copy link
Contributor Author

@marcotc accidentally dismissed review trying to kick tests :( . will merge tmrw, no rush

@ericmustin ericmustin merged commit f6eb36d into master Jul 28, 2020
@ericmustin ericmustin deleted the 1116_fix_httprb_error_handling branch July 28, 2020 08:36
@marcotc marcotc added this to the 0.39.0 milestone Jul 28, 2020
@cdmo
Copy link

cdmo commented Jan 14, 2021

This is an old and closed issue, but, is there a specific example of how checking the response body makes it unavailable to the host app? We are monkeypatching this gem in an app to add some cases where we don't want ddog to tag things as errors because for our application there are many non-200 responses that are part of the standard day-in day-out operation based on how the webservice we consume reacts. When we do this, the host app can still access the body, so curious about what context would prevent the host app from being able to access the body 🤔

@marcotc
Copy link
Member

marcotc commented Jan 15, 2021

👋 @cdmo, what we noticed is that some versions of http.rb would completely consume the payload when executing JSON.parse(response.body), leaving the body unreadable for the host application.

This only happens in cases where the payload is a stream, thus would need to be manually rewound by the host application to be read again (if that's even possible).

Also, it's generally unadvised to read a response.body, as we don't know if it's only a few bytes or gigabytes of data.

If your application does not suffer from this issue, similar to how our test suite didn't, you are likely safe to read response.body as many time as you'd like. For us, we can't be sure, and it's not guaranteed to be safe to read the payload.

@cdmo
Copy link

cdmo commented Jan 15, 2021

@marcotc thanks for the quick and thorough response and it makes total sense. We have guarantees that the payload will always be small for this application and for the version of httprb and ruby and all other pieces of the app, the http response body is still available. We'll be monkeypatching this gem and will just have to be careful to check on functionality of the app and datadog reporting when we update this gem or httprb (or maybe ruby too). Thanks again.

@marcotc
Copy link
Member

marcotc commented Jan 15, 2021

The changes in psu-libraries/myaccount#341 make think about adding some sort of interface with a user accessible callback for each span created, including arguments and local variables available at the time.

I'll keep this in mind 🤔

@ericmustin
Copy link
Contributor Author

@marcotc i think a hooks interface is worth surfacing imo.

There's prior art here in the node tracer: https://datadoghq.dev/dd-trace-js/interfaces/plugins.http.html#hooks

Additionally we have a sort've orphaned/undocumented feature similar to this for net/http #724

iirc we had concerns about the net/http hook being misused for resource renaming to create resources with cardinality issues, but for use cases like the one above this is far more efficient than what we'd currently expose to modify spans, a trace processor.

lastly i went to penn state and spent a lot of time in the paterno library, so, it'd be cool to ship something that was useful for them 😅.

@cdmo
Copy link

cdmo commented Jan 18, 2021

Cool! Thanks to you both for considering this. If you ever find yourself back in Happy Valley, feel free to stop by the library and say hi :) I guess it's true what the student ambassadors say, there are Penn State grads everywhere!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Involves a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http.rb tracer raises "HTTP::StateError: body is being streamed" on failure responses
3 participants