snowplow / snowplow-php-tracker

Snowplow event tracker for PHP. Add analytics into your PHP apps and scripts
http://snowplowanalytics.com
34 stars 36 forks source link

Add retry capability for events that failed to send to collector in socket and sync emitter (close #135) #140

Closed matus-tomlein closed 1 year ago

matus-tomlein commented 1 year ago

Issue #140

Adds retry mechanism to two emitters: socket and sync emitters. The socket emitter already had a sort of a retry mechanism but it wasn't applied on failure status codes, didn't have a backoff period and also retried only once.

The new retry has the following features:

  1. Configurable max number of retries. The default max number of retries is 1 to reflect the previous setting in the socket emitter.
  2. Exponential backoff period with the base 100ms.
  3. Retries on all 5xx and 4xx status codes except for 400, 401, 403, 410, 422.

The retry was not added to the file and curl emitters because these behave differently. They use the curl multi API which executes multiple curl requests to the collector at once asynchronously. While it would be possible to implement a retry capability, it's not straightforward so I decided to go for the low hanging fruit first and implement on socket and sync emitters.

This PR also fixes a problem in the socket emitter, where the tracker did not read the request response which resulted in the requests being ended prematurely and potentially events could be lost. Instead, the socket emitter now always reads the response and parses the status code.

Documentation PR here.

coveralls commented 1 year ago

Coverage Status

coverage: 90.0% (+1.7%) from 88.336% when pulling e41832972fc2a531ca247a3b12f15dcbfe9ed1f8 on issue/135-retry into 9f5819de122061e4955060f112e1f5ed449c5120 on master.