Skip to content
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

Merged
merged 11 commits into from
Sep 27, 2017

Conversation

electrostat
Copy link

@electrostat electrostat commented Sep 22, 2017

  • add parameters to initialization call
  • add fields to MapboxEvent
  • set sdkIdentifier and sdkVersion when pushing turnstile event

Description

Write here and include any issues you are fixing.

Check List

  • Javadoc added to any methods included
  • Added any test to ensure the fix works properly.

@Guardiola31337

- add parameters to initialization call
- add fields to MapboxEvent
- set sdkIdentifier and sdkVersion when pushing turnstile event
@electrostat electrostat self-assigned this Sep 22, 2017
Anthony Agby added 2 commits September 22, 2017 15:54
- renaming parameters
- checkstyle fix
- adjusted fallback method to preserve backwards compatability with previous versions
@electrostat
Copy link
Author

What default values should be used for sdkIdentifier and sdkVersion, when using older versions prior to this change?

@ericrwolfe @mick

@ericrwolfe
Copy link

What default values should be used for sdkIdentifier and sdkVersion, when using older versions prior to this change?

Right now these are just null values on our server for legacy clients as our iOS Maps SDK hasn't yet been switched over to the standalone telemetry library https://github.com/mapbox/mapbox-events-ios.

I'll let @zugaldia @boundsj and @mick speak to the long term plans how we should treat these, but for now null values for the legacy Maps SDKs won't break anything.

Anthony Agby added 3 commits September 25, 2017 10:47
- 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)
Copy link
Contributor

@Guardiola31337 Guardiola31337 left a 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, "", "");
Copy link
Contributor

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,
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 #574 (comment)

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 #574 (comment)

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);
Copy link
Contributor

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
-
Copy link
Contributor

@Guardiola31337 Guardiola31337 left a 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) {
Copy link
Contributor

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?

Copy link
Contributor

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) {
Copy link
Contributor

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) {

Copy link
Contributor

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
Copy link
Contributor

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. "
Copy link
Contributor

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);

Copy link
Contributor

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) {
Copy link
Contributor

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. "
Copy link
Contributor

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.

Anthony Agby added 2 commits September 27, 2017 11:49
- clean up code
- change how null checks work for sdkIdentifier + sdkVersion
- small checkstyle fix
Anthony Agby added 2 commits September 27, 2017 14:17
- useragent javadoc
- clean up adding sdkIdentifier and sdkVersion to event
- changed order of useragnet within javadoc
@electrostat electrostat removed the request for review from Guardiola31337 September 27, 2017 20:11
Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done @electrostat
:shipit:

@electrostat electrostat merged commit f1cbd9b into master Sep 27, 2017
@Guardiola31337 Guardiola31337 deleted the aa-sdkIdentifier-sdkVersion-telemetry-update branch September 29, 2017 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants