Repository navigation
Add HttpTransport extensibility and synchronous serialization support - #1560
Merged
Merged
Conversation
mattjohnsonpint
requested review from
SimonCropp and
bruno-garcia
as code owners
March 30, 2022 20:22
Contributor
Author
|
Just because it's a bit hard to read in the diff, here's the new version of public async Task SendEnvelopeAsync(Envelope envelope, CancellationToken cancellationToken = default)
{
using var processedEnvelope = ProcessEnvelope(envelope);
if (processedEnvelope.Items.Count > 0)
{
using var request = CreateRequest(processedEnvelope);
using var response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
await HandleResponseAsync(response, processedEnvelope, cancellationToken).ConfigureAwait(false);
}
} |
5 tasks done
vaind
approved these changes
Mar 31, 2022
vaind
left a comment
Contributor
There was a problem hiding this comment.
Works fine for the unity WebGL implementation. There's just one open point that could maybe be improved. See getsentry/sentry-unity#657 (review)
bruno-garcia
approved these changes
Mar 31, 2022
Contributor
Author
|
I removed the |
This was referenced Apr 26, 2022
This file contains hidden or 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
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.
As mentioned in #1553 (comment), we need to have a clean way for higher-level SDKs (like sentry-unity) to implement their own HTTP transports. In doing so, we'll need to support both asynchronous and synchronous handling of response messages, including synchronous serialization support for things like logging of payloads.
This PR takes most of the functionality of
HttpTransportand pulls it into an abstract base class,HttpTransportBase. That allows protected access to the core functionality of the transport, reducingSendEnvelopeAsyncto a small bit of orchestration code. Higher-level SDKs (such asUnityWebRequestTransportproposed in getsentry/sentry-unity#657) can implement their own version of that method without having to take a dependency onHttpClientor async/await.Note that
ITransportis still internal and implemented only onHttpTransport- notHttpTransportBase.A fully synchronous path for handling response messages is available as
HandleResponseinstead ofHandleResponseAsync(either can be used by the parent class). In order to fully implement this correctly,Sentry.Protocol.Envelopes.ISerializablehas been given aSerializemethod which mirrors the existingSerializeAsyncmethod. All implementations and tests are identical, except as to whether async methods are employed or not. At the lowest level, these now use things likeStream.Writeinstead ofStream.WriteAsync- which are implemented in .NET using the correct primitives (no sync over async or vice versa).