@@ -41,10 +41,7 @@ namespace Microsoft.Azure.Commands.Utilities.Common
41
41
public abstract class AzurePSCmdlet : PSCmdlet , IDisposable
42
42
{
43
43
protected readonly ConcurrentQueue < string > _debugMessages ;
44
-
45
-
46
44
private DebugStreamTraceListener _adalListener ;
47
- protected static AzurePSDataCollectionProfile _dataCollectionProfile = null ;
48
45
protected static string _errorRecordFolderPath = null ;
49
46
protected const string _fileTimeStampSuffixFormat = "yyyy-MM-dd-THH-mm-ss-fff" ;
50
47
protected string _clientRequestId = Guid . NewGuid ( ) . ToString ( ) ;
@@ -56,7 +53,8 @@ public abstract class AzurePSCmdlet : PSCmdlet, IDisposable
56
53
57
54
protected AzurePSQoSEvent QosEvent ;
58
55
59
- protected virtual bool IsUsageMetricEnabled {
56
+ protected virtual bool IsUsageMetricEnabled
57
+ {
60
58
get { return true ; }
61
59
}
62
60
@@ -67,9 +65,9 @@ protected virtual bool IsErrorMetricEnabled
67
65
68
66
/// <summary>
69
67
/// Gets the PowerShell module name used for user agent header.
70
- /// By default uses "Azurepowershell "
68
+ /// By default uses "AzureCLU "
71
69
/// </summary>
72
- protected virtual string ModuleName { get { return "AzurePowershell " ; } }
70
+ protected virtual string ModuleName { get { return "AzureCLU " ; } }
73
71
74
72
/// <summary>
75
73
/// Gets PowerShell module version used for user agent header.
@@ -158,128 +156,21 @@ protected virtual void SetSessionVariable<T>(string name, T value) where T : cla
158
156
DataStore . WriteFile ( variablePath , JsonConvert . SerializeObject ( value ) ) ;
159
157
}
160
158
}
161
- /// <summary>
162
- /// Initialize the data collection profile
163
- /// </summary>
164
- protected static void InitializeDataCollectionProfile ( )
165
- {
166
- if ( _dataCollectionProfile != null && _dataCollectionProfile . EnableAzureDataCollection . HasValue )
167
- {
168
- return ;
169
- }
170
-
171
- // Get the value of the environment variable for Azure PS data collection setting.
172
- string value = Environment . GetEnvironmentVariable ( AzurePSDataCollectionProfile . EnvironmentVariableName ) ;
173
- if ( ! string . IsNullOrWhiteSpace ( value ) )
174
- {
175
- if ( string . Equals ( value , bool . FalseString , StringComparison . OrdinalIgnoreCase ) )
176
- {
177
- // Disable data collection only if it is explicitly set to 'false'.
178
- _dataCollectionProfile = new AzurePSDataCollectionProfile ( true ) ;
179
- }
180
- else if ( string . Equals ( value , bool . TrueString , StringComparison . OrdinalIgnoreCase ) )
181
- {
182
- // Enable data collection only if it is explicitly set to 'true'.
183
- _dataCollectionProfile = new AzurePSDataCollectionProfile ( false ) ;
184
- }
185
- }
186
-
187
- // If the environment value is null or empty, or not correctly set, try to read the setting from default file location.
188
- if ( _dataCollectionProfile == null )
189
- {
190
- string fileFullPath = Path . Combine ( AzurePowerShell . ProfileDirectory , AzurePSDataCollectionProfile . DefaultFileName ) ;
191
- if ( File . Exists ( fileFullPath ) )
192
- {
193
- string contents = File . ReadAllText ( fileFullPath ) ;
194
- _dataCollectionProfile = JsonConvert . DeserializeObject < AzurePSDataCollectionProfile > ( contents ) ;
195
- }
196
- }
197
-
198
- // If the environment variable or file content is not set, create a new profile object.
199
- if ( _dataCollectionProfile == null )
200
- {
201
- _dataCollectionProfile = new AzurePSDataCollectionProfile ( ) ;
202
- }
203
- }
204
-
205
- /// <summary>
206
- /// Get the data collection profile
207
- /// </summary>
208
- protected static AzurePSDataCollectionProfile GetDataCollectionProfile ( )
209
- {
210
- if ( _dataCollectionProfile == null )
211
- {
212
- InitializeDataCollectionProfile ( ) ;
213
- }
214
-
215
- return _dataCollectionProfile ;
216
- }
217
159
218
160
/// <summary>
219
161
/// Check whether the data collection is opted in from user
220
162
/// </summary>
221
163
/// <returns>true if allowed</returns>
222
- public static bool IsDataCollectionAllowed ( )
164
+ protected abstract bool IsTelemetryCollectionEnabled
223
165
{
224
- //TODO: CLU - remove before final release
225
- return true ;
226
-
227
- //if (_dataCollectionProfile != null &&
228
- // _dataCollectionProfile.EnableAzureDataCollection.HasValue &&
229
- // _dataCollectionProfile.EnableAzureDataCollection.Value)
230
- //{
231
- // return true;
232
- //}
233
-
234
- //return false;
166
+ get ;
235
167
}
236
168
237
- /// <summary>
238
- /// Save the current data collection profile Json data into the default file path
239
- /// </summary>
240
- protected abstract void SaveDataCollectionProfile ( ) ;
241
-
242
- protected bool CheckIfInteractive ( )
243
- {
244
- bool interactive = false ;
245
- //if (this.Host == null ||
246
- // this.Host.UI == null ||
247
- // this.Host.UI.RawUI == null ||
248
- // Environment.GetCommandLineArgs().Any(s => s.Equals("-NonInteractive", StringComparison.OrdinalIgnoreCase)))
249
- //{
250
- // interactive = false;
251
- //}
252
- //else
253
- //{
254
- // try
255
- // {
256
- // var test = this.Host.UI.RawUI.KeyAvailable;
257
- // }
258
- // catch
259
- // {
260
- // interactive = false;
261
- // }
262
- //}
263
-
264
- if ( ! interactive && ! _dataCollectionProfile . EnableAzureDataCollection . HasValue )
265
- {
266
- _dataCollectionProfile . EnableAzureDataCollection = false ;
267
- }
268
- return interactive ;
269
- }
270
-
271
- /// <summary>
272
- /// Prompt for the current data collection profile
273
- /// </summary>
274
- /// <param name="profile"></param>
275
- protected abstract void PromptForDataCollectionProfileIfNotExists ( ) ;
276
-
277
169
/// <summary>
278
170
/// Cmdlet begin process. Write to logs, setup Http Tracing and initialize profile
279
171
/// </summary>
280
172
protected override void BeginProcessing ( )
281
173
{
282
- PromptForDataCollectionProfileIfNotExists ( ) ;
283
174
InitializeQosEvent ( ) ;
284
175
if ( string . IsNullOrEmpty ( ParameterSetName ) )
285
176
{
@@ -352,7 +243,7 @@ protected bool IsVerbose()
352
243
353
244
protected new void WriteError ( ErrorRecord errorRecord )
354
245
{
355
- FlushDebugMessages ( IsDataCollectionAllowed ( ) ) ;
246
+ FlushDebugMessages ( IsTelemetryCollectionEnabled ) ;
356
247
if ( QosEvent != null && errorRecord != null )
357
248
{
358
249
QosEvent . Exception = errorRecord . Exception ;
@@ -524,7 +415,7 @@ protected void LogQosEvent()
524
415
return ;
525
416
}
526
417
527
- if ( ! IsDataCollectionAllowed ( ) )
418
+ if ( ! IsTelemetryCollectionEnabled )
528
419
{
529
420
return ;
530
421
}
@@ -533,8 +424,10 @@ protected void LogQosEvent()
533
424
534
425
try
535
426
{
536
- MetricHelper . LogQoSEvent ( QosEvent , IsUsageMetricEnabled , IsErrorMetricEnabled ) ;
537
- MetricHelper . FlushMetric ( ) ;
427
+ MetricHelper . LogQoSEvent ( QosEvent ,
428
+ IsUsageMetricEnabled && IsTelemetryCollectionEnabled ,
429
+ IsErrorMetricEnabled && IsTelemetryCollectionEnabled ) ;
430
+ MetricHelper . FlushMetric ( IsTelemetryCollectionEnabled ) ;
538
431
WriteDebug ( "Finish sending metric." ) ;
539
432
}
540
433
catch ( Exception e )
0 commit comments