File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
Utils/azuretools-core/src/com/microsoft/azuretools/telemetry Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 44 */
55
66package com .microsoft .azuretools .telemetry ;
7+
78import com .microsoft .applicationinsights .TelemetryClient ;
9+ import org .apache .commons .lang3 .StringUtils ;
810
911public 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}
You can’t perform that action at this time.
0 commit comments