diff --git a/src/Authentication.Abstractions/Interfaces/IConfigManagerWithEvents.cs b/src/Authentication.Abstractions/Interfaces/IConfigManagerWithEvents.cs new file mode 100644 index 0000000000..18fb5ddec8 --- /dev/null +++ b/src/Authentication.Abstractions/Interfaces/IConfigManagerWithEvents.cs @@ -0,0 +1,28 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------- + +using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models; +using Microsoft.Azure.PowerShell.Common.Config; + +using System; + +namespace Microsoft.Azure.Commands.Common.Authentication.Config +{ + public interface IConfigManagerWithEvents: IConfigManager + { + event EventHandler ConfigRead; + event EventHandler ConfigUpdated; + event EventHandler ConfigCleared; + } +} diff --git a/src/Authentication.Abstractions/Models/ClearConfigOptions.cs b/src/Authentication.Abstractions/Models/Config/ClearConfigOptions.cs similarity index 100% rename from src/Authentication.Abstractions/Models/ClearConfigOptions.cs rename to src/Authentication.Abstractions/Models/Config/ClearConfigOptions.cs diff --git a/src/Authentication.Abstractions/Models/ConfigData.cs b/src/Authentication.Abstractions/Models/Config/ConfigData.cs similarity index 100% rename from src/Authentication.Abstractions/Models/ConfigData.cs rename to src/Authentication.Abstractions/Models/Config/ConfigData.cs diff --git a/src/Authentication.Abstractions/Models/ConfigDefinition.cs b/src/Authentication.Abstractions/Models/Config/ConfigDefinition.cs similarity index 100% rename from src/Authentication.Abstractions/Models/ConfigDefinition.cs rename to src/Authentication.Abstractions/Models/Config/ConfigDefinition.cs diff --git a/src/Authentication.Abstractions/Models/Config/ConfigEventArgs .cs b/src/Authentication.Abstractions/Models/Config/ConfigEventArgs .cs new file mode 100644 index 0000000000..bc495065b4 --- /dev/null +++ b/src/Authentication.Abstractions/Models/Config/ConfigEventArgs .cs @@ -0,0 +1,34 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------- + +using System; +using System.Collections.Generic; + +namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models +{ + public class ConfigEventArgs : EventArgs, IExtensibleModel + { + public string ConfigKey { get; } + + public string ConfigValue { get; } + + public IDictionary ExtendedProperties { get; } = new Dictionary(); + + public ConfigEventArgs(string configKey, string configValue) + { + ConfigKey = configKey; + ConfigValue = configValue; + } + } +} diff --git a/src/Authentication.Abstractions/Models/ConfigFilter.cs b/src/Authentication.Abstractions/Models/Config/ConfigFilter.cs similarity index 100% rename from src/Authentication.Abstractions/Models/ConfigFilter.cs rename to src/Authentication.Abstractions/Models/Config/ConfigFilter.cs diff --git a/src/Authentication.Abstractions/Models/ConfigKeysForCommon.cs b/src/Authentication.Abstractions/Models/Config/ConfigKeysForCommon.cs similarity index 100% rename from src/Authentication.Abstractions/Models/ConfigKeysForCommon.cs rename to src/Authentication.Abstractions/Models/Config/ConfigKeysForCommon.cs diff --git a/src/Authentication.Abstractions/Models/ConfigMetrics.cs b/src/Authentication.Abstractions/Models/Config/ConfigMetrics.cs similarity index 100% rename from src/Authentication.Abstractions/Models/ConfigMetrics.cs rename to src/Authentication.Abstractions/Models/Config/ConfigMetrics.cs diff --git a/src/Authentication.Abstractions/Models/Config/ConfigReadEventArgs.cs b/src/Authentication.Abstractions/Models/Config/ConfigReadEventArgs.cs new file mode 100644 index 0000000000..1e7c25175e --- /dev/null +++ b/src/Authentication.Abstractions/Models/Config/ConfigReadEventArgs.cs @@ -0,0 +1,30 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------- + +namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models +{ + public class ConfigReadEventArgs : ConfigEventArgs + { + public string ConfigTelemetryKey { get; } + + public ConfigReadEventArgs(string configKey, string configValue) : this(configKey, configKey, configValue) + { + } + + public ConfigReadEventArgs(string configKey, string configTelemetryKey, string configValue) : base(configKey, configValue) + { + ConfigTelemetryKey = configTelemetryKey; + } + } +} diff --git a/src/Authentication.Abstractions/Models/ConfigScope.cs b/src/Authentication.Abstractions/Models/Config/ConfigScope.cs similarity index 100% rename from src/Authentication.Abstractions/Models/ConfigScope.cs rename to src/Authentication.Abstractions/Models/Config/ConfigScope.cs diff --git a/src/Authentication.Abstractions/Models/UpdateConfigOptions.cs b/src/Authentication.Abstractions/Models/Config/UpdateConfigOptions.cs similarity index 100% rename from src/Authentication.Abstractions/Models/UpdateConfigOptions.cs rename to src/Authentication.Abstractions/Models/Config/UpdateConfigOptions.cs diff --git a/src/Common/AzurePSCmdlet.cs b/src/Common/AzurePSCmdlet.cs index 55a827670a..6644ca3f9c 100644 --- a/src/Common/AzurePSCmdlet.cs +++ b/src/Common/AzurePSCmdlet.cs @@ -14,6 +14,8 @@ using Microsoft.Azure.Commands.Common.Authentication; using Microsoft.Azure.Commands.Common.Authentication.Abstractions; +using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models; +using Microsoft.Azure.Commands.Common.Authentication.Config; using Microsoft.Azure.PowerShell.Common.Config; using Microsoft.Azure.PowerShell.Common.Share.Survey; using Microsoft.Azure.PowerShell.Common.UpgradeNotification; @@ -772,6 +774,28 @@ protected virtual void InitializeQosEvent() } _qosEvent.SanitizerInfo = new SanitizerTelemetry(OutputSanitizer?.RequireSecretsDetection == true); + + AttachConfigReadHandlerForTelemetry(); + } + + /// + /// Attach config read event handler to add config telemetry + /// + private void AttachConfigReadHandlerForTelemetry() + { + AzureSession.Instance.TryGetComponent(nameof(IConfigManager), out var configManager); + if (configManager is IConfigManagerWithEvents cm) + { + cm.ConfigRead += OnConfigRead; + } + } + + private void OnConfigRead(object sender, ConfigEventArgs args) + { + if (!_qosEvent.ConfigMetrics.ContainsKey(args.ConfigKey) && args is ConfigReadEventArgs readEventArgs) + { + _qosEvent.ConfigMetrics[readEventArgs.ConfigKey] = new ConfigMetrics(readEventArgs.ConfigTelemetryKey, readEventArgs.ConfigValue.ToString()); + } } private void RecordDebugMessages()