Skip to content

Commit 2c688ec

Browse files
committed
Fix telemetry client enable configuration
1 parent 08eee7f commit 2c688ec

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Utils/azuretools-core/src/com/microsoft/azuretools/telemetry/AppInsightsClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ private static boolean isAppInsightsClientAvailable() {
176176
private static void initTelemetryManager() {
177177
try {
178178
final Map<String, String> properties = buildProperties("", new HashMap<>());
179+
TelemetryClientSingleton.setConfiguration(configuration);
179180
final TelemetryClient client = TelemetryClientSingleton.getTelemetry();
180181
final String eventNamePrefix = configuration.eventName();
181182
TelemetryManager.getInstance().setTelemetryClient(client);
@@ -188,5 +189,4 @@ private static void initTelemetryManager() {
188189
} catch (Exception ignore) {
189190
}
190191
}
191-
192192
}

Utils/azuretools-core/src/com/microsoft/azuretools/telemetry/TelemetryClientSingleton.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,35 @@
44
*/
55

66
package com.microsoft.azuretools.telemetry;
7+
78
import com.microsoft.applicationinsights.TelemetryClient;
9+
import org.apache.commons.lang3.StringUtils;
810

911
public final class TelemetryClientSingleton {
1012
private TelemetryClient telemetry = null;
13+
private AppInsightsConfiguration configuration = null;
1114

1215
private static final class SingletonHolder {
1316
private static final TelemetryClientSingleton INSTANCE = new TelemetryClientSingleton();
1417
}
1518

16-
public static TelemetryClient getTelemetry(){
19+
public static TelemetryClient getTelemetry() {
1720
return SingletonHolder.INSTANCE.telemetry;
1821
}
1922

20-
private TelemetryClientSingleton(){
21-
telemetry = new TelemetryClient();
23+
public static void setConfiguration(final AppInsightsConfiguration configuration) {
24+
SingletonHolder.INSTANCE.configuration = configuration;
25+
}
26+
27+
private TelemetryClientSingleton() {
28+
telemetry = new TelemetryClient() {
29+
@Override
30+
public boolean isDisabled() {
31+
if (configuration == null) {
32+
return true;
33+
}
34+
return (StringUtils.isNotEmpty(configuration.preferenceVal()) && !Boolean.valueOf(configuration.preferenceVal())) || super.isDisabled();
35+
}
36+
};
2237
}
2338
}

0 commit comments

Comments
 (0)