Conversation
- add parameters to initialization call - add fields to MapboxEvent - set sdkIdentifier and sdkVersion when pushing turnstile event
- renaming parameters - checkstyle fix
- adjusted fallback method to preserve backwards compatability with previous versions
|
What default values should be used for sdkIdentifier and sdkVersion, when using older versions prior to this change? |
Right now these are just I'll let @zugaldia @boundsj and @mick speak to the long term plans how we should treat these, but for now |
- changed default values for earlier sdks to null for sdkIdentifier and sdkVersion - subsequent sdks will set variables
This reverts commit 03fd7c4.
- remove nulls and keep system initialized with empty strings when using old sdk (filled in on server)
There was a problem hiding this comment.
We are adding sdkIdentifier and sdkVersion to the event object but not including it to the JSON object. 👀 https://github.com/mapbox/mapbox-java/blob/master/mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/http/TelemetryClient.java#L233-L239
Now it's working because both MapboxEvent and MapboxNavigationEvent define the same strings for keys KEY_SDK_IDENTIFIER and KEY_SDK_VERSION 👀 https://github.com/mapbox/mapbox-java/blob/master/mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/navigation/MapboxNavigationEvent.java#L31-L32 and https://github.com/mapbox/mapbox-java/blob/master/mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/http/TelemetryClient.java#L153-L154
By the way we should use the keys defined on each event because eventually they could change and mess up everything.
| this.locationEngine = locationEngine; | ||
| initialize(context, accessToken, userAgent); | ||
|
|
||
| initialize(context, accessToken, userAgent, "", ""); |
There was a problem hiding this comment.
Why not initializing sdkIdentifier and sdkVersion properties as empty and using them here?
| * @param accessToken The accessToken associated with the application | ||
| */ | ||
| public void initialize(@NonNull Context context, @NonNull String accessToken, @NonNull String userAgent) { | ||
| public void initialize(@NonNull Context context, @NonNull String accessToken, @NonNull String userAgent, |
There was a problem hiding this comment.
We're breaking the public API here and that would mean semver. We should implement this differently to not break backwards compatibility.
Adding a new overloaded initialize method should do the trick. 👀 https://github.com/mapbox/mapbox-java/blob/master/mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/MapboxTelemetry.java#L109-L120
| this.sdkVersion = sdkVersion; | ||
|
|
||
| if (this.context == null || TextUtils.isEmpty(this.accessToken) || TextUtils.isEmpty(this.userAgent) | ||
| || this.sdkIdentifier == null || this.sdkVersion == null) { |
There was a problem hiding this comment.
for now
nullvalues for the legacy Maps SDKs won't break anything.
sdkIdentifier and sdkVersion can't be empty either. We should mark somehow the different entry points (which initialize method was called) and make these checks wisely.
| event.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate(null)); | ||
| event.put(MapboxEvent.KEY_USER_ID, mapboxVendorId); | ||
| event.put(MapboxEvent.KEY_ENABLED_TELEMETRY, isTelemetryEnabled()); | ||
| event.put(MapboxEvent.KEY_SDK_IDENTIFIER, sdkIdentifier); |
There was a problem hiding this comment.
for now
nullvalues for the legacy Maps SDKs won't break anything.
We should send null values when not calling the initialize method that uses sdkIdentifier and sdkVersion explicitly. 👀 https://github.com/mapbox/mapbox-java/blob/master/mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/navigation/MapboxNavigationEvent.java#L284-L290
| event.put(MapboxEvent.KEY_USER_ID, mapboxVendorId); | ||
| event.put(MapboxEvent.KEY_ENABLED_TELEMETRY, isTelemetryEnabled()); | ||
| event.put(MapboxEvent.KEY_SDK_IDENTIFIER, sdkIdentifier); | ||
| event.put(MapboxEvent.KEY_SDK_VERSION, sdkVersion); |
- use sdkIdentifier and sdkVersion after setting them to empty strings - add sdkIdentifier and sdkVersion to JSON - added overload method -
Guardiola31337
left a comment
There was a problem hiding this comment.
Some minor details.
I recommend you to rebase and fix up the commits (:eyes: messages) to represent what would be merged into master for easier review 😉
BTW, great job 👍
| event.put(MapboxEvent.KEY_USER_ID, mapboxVendorId); | ||
| event.put(MapboxEvent.KEY_ENABLED_TELEMETRY, isTelemetryEnabled()); | ||
|
|
||
| if (sdkIdentifier == null) { |
There was a problem hiding this comment.
What about simplifying this block of code (if else) extracting it into a different method and work to make the intention clearer?
There was a problem hiding this comment.
We should send null values when not calling the initialize method that uses sdkIdentifier and sdkVersion explicitly (when sdkIdentifier and sdkVersion are empty). Right now, this condition is always false because we initialize sdkIdentifier and sdkVersion to "" and if any of them are null there is a previous check which will throw a TelemetryException.
| event.put(MapboxEvent.KEY_SDK_IDENTIFIER, sdkIdentifier); | ||
| } | ||
|
|
||
| if (sdkVersion == null) { |
|
|
||
| public void initialize(@NonNull Context context, @NonNull String accessToken, @NonNull String userAgent, | ||
| String sdkIdentifier, String sdkVersion) { | ||
|
|
| /** | ||
| * Initialize MapboxTelemetry - with sdkIdentifier + sdkVersion | ||
| * | ||
| * @param sdkIdentifier Identifies which sdk is sending the event |
There was a problem hiding this comment.
Javadoc is incorrect. context, accessToken and locationEngine parameters are missing. 👀 formatting too.
|
|
||
| if (this.sdkIdentifier == null || this.sdkVersion == null) { | ||
| throw new TelemetryException( | ||
| "Please, make sure you provide a valid context, access token, and user agent. " |
There was a problem hiding this comment.
Exception message is not reflecting what we're checking.
| } | ||
|
|
||
| initialize(context, accessToken, userAgent); | ||
|
|
| */ | ||
|
|
||
| public void initialize(@NonNull Context context, @NonNull String accessToken, @NonNull String userAgent, | ||
| String sdkIdentifier, String sdkVersion) { |
There was a problem hiding this comment.
We should add @NonNull annotation to sdkIdentifier and sdkVersion to reflect that those should be non null.
| if (this.context == null || TextUtils.isEmpty(this.accessToken) || TextUtils.isEmpty(this.userAgent) | ||
| || this.sdkIdentifier == null || this.sdkVersion == null) { | ||
| throw new TelemetryException( | ||
| "Please, make sure you provide a valid context, access token, and user agent. " |
There was a problem hiding this comment.
Exception message is not reflecting what we're checking.
- clean up code - change how null checks work for sdkIdentifier + sdkVersion
- small checkstyle fix
- useragent javadoc - clean up adding sdkIdentifier and sdkVersion to event
- changed order of useragnet within javadoc
Guardiola31337
left a comment
There was a problem hiding this comment.
Well done @electrostat
![]()
Description
Write here and include any issues you are fixing.
Check List
@Guardiola31337