Skip to content

Commit f448119

Browse files
authored
Fix SDK Version sent from QuickPulse channel (#881)
* Fix SDK Version sent from qp * update readme
1 parent a51d8c2 commit f448119

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
and `HttpExtractor`.
1111
- Deprecated `ApplicationInsightsHttpResponseWrapper`
1212
- Fixed [#826](https://github.com/Microsoft/ApplicationInsights-Java/issues/826) Remove duplicate provider.
13+
- Fix incorrect sdk version being sent in Quick Pulse payload.
1314

1415
# Version 2.3.1
1516
- Fixed [#799](https://github.com/Microsoft/ApplicationInsights-Java/issues/799) Removed dependency on Guava vulnerable to [CVE-2018-10237](https://nvd.nist.gov/vuln/detail/CVE-2018-10237).

core/src/main/java/com/microsoft/applicationinsights/internal/quickpulse/DefaultQuickPulseDataFetcher.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
package com.microsoft.applicationinsights.internal.quickpulse;
2323

2424
import java.util.Date;
25+
import java.util.Properties;
2526
import java.util.concurrent.ArrayBlockingQueue;
2627

28+
import com.microsoft.applicationinsights.internal.util.PropertyHelper;
2729
import org.apache.commons.lang3.exception.ExceptionUtils;
2830
import org.apache.http.client.methods.HttpPost;
2931
import org.apache.http.entity.ByteArrayEntity;
@@ -39,10 +41,12 @@ final class DefaultQuickPulseDataFetcher implements QuickPulseDataFetcher {
3941
private final ArrayBlockingQueue<HttpPost> sendQueue;
4042
private final QuickPulseNetworkHelper networkHelper = new QuickPulseNetworkHelper();
4143
private String postPrefix;
44+
private final String sdkVersion;
4245

4346
public DefaultQuickPulseDataFetcher(final ArrayBlockingQueue<HttpPost> sendQueue, final String ikey, final String instanceName, final String quickPulseId) {
4447
quickPulsePostUri = QP_BASE_URI + "post?ikey=" + ikey;
4548
this.sendQueue = sendQueue;
49+
sdkVersion = getCurrentSdkVersion();
4650
final StringBuilder sb = new StringBuilder();
4751
sb.append("[{");
4852
formatDocuments(sb);
@@ -55,6 +59,21 @@ public DefaultQuickPulseDataFetcher(final ArrayBlockingQueue<HttpPost> sendQueue
5559
postPrefix = sb.toString();
5660
}
5761

62+
/**
63+
* Get SDK Version from properties
64+
* @return current SDK version
65+
*/
66+
/* Visible for testing */ String getCurrentSdkVersion() {
67+
String prefix = "java";
68+
Properties sdkVersionProps = PropertyHelper.getSdkVersionProperties();
69+
if (sdkVersionProps != null) {
70+
String version = sdkVersionProps.getProperty("version");
71+
return prefix + ":" + version;
72+
}
73+
// return unknown version if no version number found.
74+
return prefix + ":" + "unknown";
75+
}
76+
5877
@Override
5978
public void prepareQuickPulseDataForSend() {
6079
try {
@@ -90,7 +109,7 @@ private ByteArrayEntity buildPostEntity(QuickPulseDataCollector.FinalCounters co
90109
long ms = System.currentTimeMillis();
91110
sb.append(ms);
92111
sb.append(")\\/\",");
93-
sb.append("\"Version\": \"2.2.0-738\"");
112+
sb.append("\"Version\": \"" + sdkVersion + "\"");
94113
sb.append("}]");
95114
ByteArrayEntity bae = new ByteArrayEntity(sb.toString().getBytes());
96115
return bae;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.microsoft.applicationinsights.internal.quickpulse;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.junit.runners.JUnit4;
7+
8+
@RunWith(JUnit4.class)
9+
public class DefaultQuickPulseDataFetcherTests {
10+
11+
@Test
12+
public void testGetCurrentSdkVersion() {
13+
DefaultQuickPulseDataFetcher dataFetcher = new DefaultQuickPulseDataFetcher(null, null,
14+
null, null);
15+
String sdkVersion = dataFetcher.getCurrentSdkVersion();
16+
Assert.assertNotNull(sdkVersion);
17+
Assert.assertNotEquals("java:unknown", sdkVersion);
18+
}
19+
}

0 commit comments

Comments
 (0)