29
29
using System . Linq ;
30
30
using System . Threading ;
31
31
using Microsoft . Azure . Commands . Common . Authentication . Factories ;
32
+ using Microsoft . ApplicationInsights ;
33
+ using Microsoft . ApplicationInsights . Extensibility ;
32
34
using Microsoft . Rest ;
33
35
34
36
namespace Microsoft . Azure . Commands . Utilities . Common
@@ -45,7 +47,7 @@ public abstract class AzurePSCmdlet : PSCmdlet, IDisposable
45
47
protected static AzurePSDataCollectionProfile _dataCollectionProfile = null ;
46
48
protected static string _errorRecordFolderPath = null ;
47
49
protected const string _fileTimeStampSuffixFormat = "yyyy-MM-dd-THH-mm-ss-fff" ;
48
-
50
+ protected string _clientRequestId = Guid . NewGuid ( ) . ToString ( ) ;
49
51
public IClientFactory ClientFactory { get ; set ; }
50
52
51
53
public IAuthenticationFactory AuthenticationFactory { get ; set ; }
@@ -55,7 +57,7 @@ public abstract class AzurePSCmdlet : PSCmdlet, IDisposable
55
57
protected AzurePSQoSEvent QosEvent ;
56
58
57
59
protected virtual bool IsUsageMetricEnabled {
58
- get { return false ; }
60
+ get { return true ; }
59
61
}
60
62
61
63
protected virtual bool IsErrorMetricEnabled
@@ -85,6 +87,11 @@ protected virtual bool IsErrorMetricEnabled
85
87
public AzurePSCmdlet ( )
86
88
{
87
89
_debugMessages = new ConcurrentQueue < string > ( ) ;
90
+ //TODO: Inject from CI server
91
+ MetricHelper . AddTelemetryClient ( new TelemetryClient
92
+ {
93
+ InstrumentationKey = "963c4276-ec20-48ad-b9ab-3968e9da5578"
94
+ } ) ;
88
95
#if DEBUG
89
96
if ( ! TestMockSupport . RunningMocked )
90
97
{
@@ -214,6 +221,9 @@ protected static AzurePSDataCollectionProfile GetDataCollectionProfile()
214
221
/// <returns>true if allowed</returns>
215
222
public static bool IsDataCollectionAllowed ( )
216
223
{
224
+ //TODO: CLU - remove before final release
225
+ return true ;
226
+
217
227
if ( _dataCollectionProfile != null &&
218
228
_dataCollectionProfile . EnableAzureDataCollection . HasValue &&
219
229
_dataCollectionProfile . EnableAzureDataCollection . Value )
@@ -299,7 +309,7 @@ protected override void BeginProcessing()
299
309
ProductInfoHeaderValue userAgentValue = new ProductInfoHeaderValue (
300
310
ModuleName , string . Format ( "v{0}" , ModuleVersion ) ) ;
301
311
ClientFactory . UserAgents . Add ( userAgentValue ) ;
302
- ClientFactory . AddHandler ( new CmdletInfoHandler ( this . CommandRuntime . ToString ( ) , this . ParameterSetName ) ) ;
312
+ ClientFactory . AddHandler ( new CmdletInfoHandler ( this . CommandRuntime . ToString ( ) , this . ParameterSetName , this . _clientRequestId ) ) ;
303
313
ServiceClientTracing . AddTracingInterceptor ( _adalListener ) ;
304
314
ServiceClientTracing . IsEnabled = true ;
305
315
base . BeginProcessing ( ) ;
@@ -347,7 +357,7 @@ protected bool IsVerbose()
347
357
{
348
358
QosEvent . Exception = errorRecord . Exception ;
349
359
QosEvent . IsSuccess = false ;
350
- LogQosEvent ( true ) ;
360
+ LogQosEvent ( ) ;
351
361
}
352
362
353
363
base . WriteError ( errorRecord ) ;
@@ -500,7 +510,7 @@ private void RecordDebugMessages()
500
510
/// <summary>
501
511
/// Invoke this method when the cmdlet is completed or terminated.
502
512
/// </summary>
503
- protected void LogQosEvent ( bool waitForMetricSending = false )
513
+ protected void LogQosEvent ( )
504
514
{
505
515
if ( QosEvent == null )
506
516
{
@@ -524,7 +534,7 @@ protected void LogQosEvent(bool waitForMetricSending = false)
524
534
try
525
535
{
526
536
MetricHelper . LogQoSEvent ( QosEvent , IsUsageMetricEnabled , IsErrorMetricEnabled ) ;
527
- MetricHelper . FlushMetric ( waitForMetricSending ) ;
537
+ MetricHelper . FlushMetric ( ) ;
528
538
WriteDebug ( "Finish sending metric." ) ;
529
539
}
530
540
catch ( Exception e )
0 commit comments