-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sdkIdentifier + sdkversion #574
Add sdkIdentifier + sdkversion #574
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not initializing sdkIdentifier
and sdkVersion
properties as empty and using them here?
@@ -125,7 +128,8 @@ public void initialize(@NonNull Context context, @NonNull String accessToken, | |||
* @param context The context associated with the application | |||
* @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now
null
values 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.
@@ -651,6 +659,8 @@ private void pushTurnstileEvent() { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now
null
values 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
@@ -651,6 +659,8 @@ private void pushTurnstileEvent() { | |||
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); | |||
event.put(MapboxEvent.KEY_SDK_VERSION, sdkVersion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here ☝️
- use sdkIdentifier and sdkVersion after setting them to empty strings - add sdkIdentifier and sdkVersion to JSON - added overload method -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍
@@ -652,6 +682,18 @@ private void pushTurnstileEvent() { | |||
event.put(MapboxEvent.KEY_USER_ID, mapboxVendorId); | |||
event.put(MapboxEvent.KEY_ENABLED_TELEMETRY, isTelemetryEnabled()); | |||
|
|||
if (sdkIdentifier == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here ☝️
|
||
public void initialize(@NonNull Context context, @NonNull String accessToken, @NonNull String userAgent, | ||
String sdkIdentifier, String sdkVersion) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT blank line
/** | ||
* Initialize MapboxTelemetry - with sdkIdentifier + sdkVersion | ||
* | ||
* @param sdkIdentifier Identifies which sdk is sending the event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exception message is not reflecting what we're checking.
initialize(context, accessToken, userAgent); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT blank line
*/ | ||
|
||
public void initialize(@NonNull Context context, @NonNull String accessToken, @NonNull String userAgent, | ||
String sdkIdentifier, String sdkVersion) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)) { | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done @electrostat
Description
Write here and include any issues you are fixing.
Check List
@Guardiola31337