fix: Override Code:0 with the StatusCode value #66
+93
−7
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.
Summary
The Amplitude client is set up like the following:
The flow works like the following:
amplitude.Client.Track()
to send an event.storages.inMemoryEventStorage
(bydestination.amplitudePlugin
)destination.amplitudePlugin
pulls the events from the store asynchronously and sends them to the Amplitude (server) viainternal.AmplitudeHTTPClient.Send()
destination.amplitudePlugin
waits for the http response and callsinternal.AmplitudeResponseProcessor.Process()
to transform the response fromAmplitudeResponse
toAmplitudeProcessorResult
AmplitudeProcessorResult
is used to createtypes.ExecuteResult
and call the client's callbackAmplitudeResponse
has 2 status codes and 2 errors:Code
field is populated from the json response body.For example:
See: https://amplitude.com/docs/apis/analytics/batch-event-upload#successsummary
Q: What happens if an http request fails, there's no response body or the body is not json?
The
Code
field will be 0.This leads to many issues:
One.
#64 - a fix, which only takes care of 413
Two.
Customers get
Code=0
via the callback.When this happens the customers don't know how to handle it.
Does it mean we should retry or drop the message?
This leads to a potential data loss.
A few examples of errors:
Event reached max retry times 1: code=0, events=...
HTTP request failed: Post "https://api2.amplitude.com/batch": unexpected EOF: code=0, events=...
In this change we make
internal.AmplitudeResponseProcessor
to assignCode
fromStatusCode
(effectively http response status code) ifCode=0
(if request failed or json parsing failed).This will tell the customer the real reason of a failure and the customer will be able to decide what to do with the message.
Testing
Checklist