Skip to content

Commit 83f5ea1

Browse files
committed
- fixes a bug where the telemetry header would not match the specification
1 parent 71e9bb7 commit 83f5ea1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class TelemetryHandler implements Interceptor{
1717
public static final String JAVA_VERSION_PREFIX = "java";
1818
public static final String ANDROID_VERSION_PREFIX = "android";
1919
public static final String CLIENT_REQUEST_ID = "client-request-id";
20+
private static final String DEFAULT_VERSION_VALUE = "0";
2021

2122
@Override
2223
public Response intercept(Chain chain) throws IOException {
@@ -30,7 +31,9 @@ public Response intercept(Chain chain) throws IOException {
3031
final String featureUsage = "(featureUsage=" + telemetryOptions.getFeatureUsage() + ")";
3132
final String javaVersion = System.getProperty("java.version");
3233
final String androidVersion = getAndroidAPILevel();
33-
final String sdkversion_value = GRAPH_VERSION_PREFIX + "/" + VERSION + " " + featureUsage + " " + JAVA_VERSION_PREFIX + "/" + javaVersion + " " + ANDROID_VERSION_PREFIX + "/" + androidVersion;
34+
final String sdkversion_value = GRAPH_VERSION_PREFIX + "/" + VERSION + " " + featureUsage +
35+
(javaVersion == DEFAULT_VERSION_VALUE ? "" : (", " + JAVA_VERSION_PREFIX + "/" + javaVersion)) +
36+
(androidVersion == DEFAULT_VERSION_VALUE ? "" : (", " + ANDROID_VERSION_PREFIX + "/" + androidVersion));
3437
telemetryAddedBuilder.addHeader(SDK_VERSION, sdkversion_value);
3538

3639
if(request.header(CLIENT_REQUEST_ID) == null) {
@@ -61,10 +64,10 @@ private String getAndroidAPILevelInternal() {
6164
final Field sdkVersionField = versionClass.getField("SDK_INT");
6265
final Object value = sdkVersionField.get(null);
6366
final String valueStr = String.valueOf(value);
64-
return valueStr == null || valueStr == "" ? "0" : valueStr;
67+
return valueStr == null || valueStr == "" ? DEFAULT_VERSION_VALUE : valueStr;
6568
} catch (IllegalAccessException | ClassNotFoundException | NoSuchFieldException ex) {
6669
// we're not on android and return "0" to align with java version which returns "0" when running on android
67-
return "0";
70+
return DEFAULT_VERSION_VALUE;
6871
}
6972
}
7073
}

0 commit comments

Comments
 (0)