-
Notifications
You must be signed in to change notification settings - Fork 116
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
Instrument Rack response bodies #1140
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment has been minimized.
This comment has been minimized.
1 similar comment
This is a message from the daily scheduled checks. |
jeffkreeftmeijer
approved these changes
Jul 8, 2024
Instrument what happens when a Rack response body is read and closed. We instrument these events by wrapping the response body in the appropriate response body BodyWrapper subclass, depending on the response object type. This change was previously sent in as PR #1037 and reverted in #1052. We saw issues with multiple requests reported in the same transaction. This problem occurred when there was an error in the middleware stack, and the BodyWrapper never closed the response body. I've removed any transaction complete logic from the BodyWrapper in the original PR. We now have a Rack EventHandler that ensures the transaction is always closed per request, even when such an error scenario occurs again. The only scenario in which we don't support this response body instrumentation is when no EventHandler is present in the middleware stack. This level of support is acceptable to me. We want people to use the EventHandler. Most of our automatic instrumentations are updated to add it to the middleware stack. From the original commit: 7da96e7 > Some work might be getting done within a Rack response body. For > example, when ActionController::Streaming is used, or when a Rack app > elects to stream a response. > > The Rack SPEC doc defines the behavior in sufficient detail to wrap > this into the current AppSignal transaction. > > Sadly, there is some work involved in supporting all the right > methods, so just "one-size-fits-all" wrapper will not quite work. Part of #1099 Co-authored-by: Julik Tarkhanov <me@julik.nl>
Now that the AbstractMiddleware instruments response bodies, the StreamingListener has no special purpose anymore. It will now inherit from the AbstractMiddleware and be scheduled for removal. Also removed the StreamWrapper class used previously by the StreamingListener. It was a private API that no one should have been using.
Deprecate the StreamingListener now that it is almost identical to the AbstractMiddleware. Those couple differences are actually ones we don't want people to rely on, so deprecate it.
If multiple rack instrumentation middleware are present in the middleware stack, don't instrument the response body multiple times. Once it detects the response body is already a BodyWrapper subclass, pass it through without change.
tombruijn
force-pushed
the
instrument-responses
branch
from
July 8, 2024 12:25
6a42960
to
bbb957e
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Based on PR #1139
Instrument Rack response bodies
Instrument what happens when a Rack response body is read and closed. We instrument these events by wrapping the response body in the appropriate response body BodyWrapper subclass, depending on the response object type.
This change was previously sent in as PR #1037 and reverted in #1052. We saw issues with multiple requests reported in the same transaction. This problem occurred when there was an error in the middleware stack, and the BodyWrapper never closed the response body.
I've removed any transaction complete logic from the BodyWrapper in the original PR. We now have a Rack EventHandler that ensures the transaction is always closed per request, even when such an error scenario occurs again.
The only scenario in which we don't support this response body instrumentation is when no EventHandler is present in the middleware stack. This level of support is acceptable to me. We want people to use the EventHandler. Most of our automatic instrumentations are updated to add it to the middleware stack.
From the original commit: 7da96e7
Closes #1099
Co-authored-by: Julik Tarkhanov me@julik.nl
Update StreamingListener to use AbstractMiddleware
Now that the AbstractMiddleware instruments response bodies, the StreamingListener has no special purpose anymore. It will now inherit from the AbstractMiddleware and be scheduled for removal.
Also removed the StreamWrapper class used previously by the StreamingListener. It was a private API that no one should have been using.
Deprecate StreamingListener middleware
Deprecate the StreamingListener now that it is almost identical to the AbstractMiddleware. Those couple differences are actually ones we don't want people to rely on, so deprecate it.
Don't instrument response bodies twice
If multiple rack instrumentation middleware are present in the middleware stack, don't instrument the response body multiple times.
Once it detects the response body is already a BodyWrapper subclass, pass it through without change.