Example #1
0
 protected TelemetryProvider(AzurePSDataCollectionProfile profile, MetricHelper helper, Action <string> warningLogger, Action <string> debugLogger)
 {
     _dataCollectionProfile = profile;
     _helper        = helper;
     _warningLogger = warningLogger;
     _debugLogger   = debugLogger;
 }
Example #2
0
        private static MetricHelper CreateMetricHelper(AzurePSDataCollectionProfile profile)
        {
            var result = new MetricHelper(profile);

            result.AddTelemetryClient(new TelemetryClient
            {
                InstrumentationKey = "7df6ff70-8353-4672-80d6-568517fed090"
            });

            return(result);
        }
        /// <summary>
        /// Initialize the data collection profile
        /// </summary>
        protected static void InitializeDataCollectionProfile()
        {
            if (_dataCollectionProfile != null && _dataCollectionProfile.EnableAzureDataCollection.HasValue)
            {
                return;
            }

            // Get the value of the environment variable for Azure PS data collection setting.
            string value = Environment.GetEnvironmentVariable(AzurePSDataCollectionProfile.EnvironmentVariableName);

            if (!string.IsNullOrWhiteSpace(value))
            {
                if (string.Equals(value, bool.FalseString, StringComparison.OrdinalIgnoreCase))
                {
                    // Disable data collection only if it is explicitly set to 'false'.
                    _dataCollectionProfile = new AzurePSDataCollectionProfile(false);
                }
                else if (string.Equals(value, bool.TrueString, StringComparison.OrdinalIgnoreCase))
                {
                    // Enable data collection only if it is explicitly set to 'true'.
                    _dataCollectionProfile = new AzurePSDataCollectionProfile(true);
                }
            }

            // If the environment value is null or empty, or not correctly set, try to read the setting from default file location.
            if (_dataCollectionProfile == null)
            {
                // If it exists, remove the old AzureDataCollectionProfile.json file
                string oldFileFullPath = Path.Combine(AzurePowerShell.ProfileDirectory,
                                                      AzurePSDataCollectionProfile.OldDefaultFileName);
                if (AzureSession.Instance.DataStore.FileExists(oldFileFullPath))
                {
                    AzureSession.Instance.DataStore.DeleteFile(oldFileFullPath);
                }

                // Try and read from the new AzurePSDataCollectionProfile.json file
                string fileFullPath = Path.Combine(AzurePowerShell.ProfileDirectory,
                                                   AzurePSDataCollectionProfile.DefaultFileName);
                if (AzureSession.Instance.DataStore.FileExists(fileFullPath))
                {
                    string contents = AzureSession.Instance.DataStore.ReadFileAsText(fileFullPath);
                    _dataCollectionProfile =
                        JsonConvert.DeserializeObject <AzurePSDataCollectionProfile>(contents);
                }
            }

            // If the environment variable or file content is not set, create a new profile object.
            if (_dataCollectionProfile == null)
            {
                _dataCollectionProfile = new AzurePSDataCollectionProfile();
            }
        }
Example #4
0
            internal static TelemetryProvider Create(IEventStore store)
            {
                var profile = new AzurePSDataCollectionProfile(false);

                return(new MockTelemetryProvider(profile, new MetricHelper(profile), store.GetWarningLogger(), store.GetDebugLogger()));
            }
Example #5
0
 protected MockTelemetryProvider(AzurePSDataCollectionProfile profile, MetricHelper helper, Action <string> warningLogger, Action <string> debugLogger) : base(profile, helper, warningLogger, debugLogger)
 {
 }