We are happy to announce the release of version 0.5.0 of the Snowplow Ruby Tracker. As well as making the Tracker more robust, this release introduces several breaking API changes.
Read on for more detail on:
- Improved concurrency
- More robust error handling
- The SelfDescribingJson class
- New setFingerprint method
- Getting help
1. Improved concurrency
The Ruby Tracker’s
AsyncEmitter class now uses the Queue class to implement the producer-consumer pattern, where a fixed pool of threads work on sending events. Reusing threads this way performs better than the previous implementation in which a new thread was created for every network request.
You can configure the number of threads to use with the new
thread_count field of the AsyncEmitter’s configuration hash like this:
If your application only rarely sends events, the default of 1 thread should be good enough; otherwise try experimenting with different values to determine which works best.
We have also eliminated a race condition where sending many events at once could cause events to be duplicated or skipped.
2. More robust error handling
The previous tracker version only treated requests with status code 200 as successful. This behavior has been broadened to include all 2xx and 3xx status codes.
The tracker now catches all network-related exceptions and treats the events which caused them as failed. This means that network unavailability no longer causes the tracker to throw exceptions.
3. The SelfDescribingJson class
SelfDescribingJson class makes it easier to build unstructured events and custom contexts.
Instead of fully specifying JSONs like this:
you would now use the
SelfDescribingJson class to automatically handle the “schema” and “data” fields like this:
Note that this is a breaking change and old-style API calls which manually construct unstructured events and custom contexts will no longer work.
4. New setUserFingerprint method
Thanks to Snowplow community member Kacper Bielecki (@kazjote on GitHub), you can now set a user fingerprint for a Subject like this:
Thanks a lot Kacper!
This release increases the version of the
contexts schema from 1-0-0 to 1-0-1 to allow empty contexts arrays. Because of this, it is only compatible with version 0.9.14 and later of the core Snowplow platform.
You will need to update all unstructured events and contexts to use the
SelfDescribingJson class mentioned above.
tracker.flush method now takes one boolean argument,
async, which defaults to
false. Usage of this method is demonstrated below:
The Emitter class’s
buffer_size configuration option used to be 0-indexed, so with the following configuration the Emitter would send events in batches of 6:
buffer_size is now 1-indexed, so that with this configuration events will be sent in batches of 5.
Due to JRuby compatibility issues, we have made the Ruby Tracker’s dependency on the Contracts gem more strict: rather than allowing all Contracts versions since 0.3.0, the Gemfile now requires a Contracts version between 0.7 and 0.11 (inclusive).
6. Getting help
These links may be useful:
- The wiki page
- The GitHub repository
If you have an idea for a new feature or want help getting things set up, please get in touch. Raise an issue in the GitHub repository if you find any bugs.