Skip to content

Commit

Permalink
Add ConfigInfo Telemetry (#420)
Browse files Browse the repository at this point in the history
* first version

* Update src/Authentication.Abstractions/Authentication.Abstractions.csproj

* refine code

* resolve comments

* revert csproj

* polish

* rename to ConfigMetrics

* revert src/Authentication.Abstractions/Authentication.Abstractions.csproj

* Update src/Authentication.Abstractions/Authentication.Abstractions.csproj

* wip
  • Loading branch information
BethanyZhou authored Jun 14, 2024
1 parent 7be70ef commit f44d051
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Authentication.Abstractions/Models/ConfigMetrics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// ----------------------------------------------------------------------------------
//
// 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.Concurrent;
using System.Collections.Generic;

namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models
{
/// <summary>
/// Recorded value for config in telemetry
/// </summary>
public class ConfigMetrics: IExtensibleModel
{
/// <summary>
/// The unique key of config. It's required for recording config telemetry.
/// </summary>
public string ConfigKey { get; private set; }

/// <summary>
/// Config value in string format. It's required for recording config telemetry.
/// </summary>
public string ConfigValue { get; private set; }

public IDictionary<string, string> ExtendedProperties { get; } = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);

public ConfigMetrics(string ConfigKey, string ConfigValue)
{
this.ConfigKey = ConfigKey;
this.ConfigValue = ConfigValue;
}
}
}
18 changes: 18 additions & 0 deletions src/Common/MetricHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using System.Threading.Tasks;
using System.ComponentModel;
using Microsoft.WindowsAzure.Commands.Common.Sanitizer;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models;

namespace Microsoft.WindowsAzure.Commands.Common
{
Expand Down Expand Up @@ -451,6 +452,7 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string,
}
}

PopulateConfigMetricsFromQos(qos, eventProperties);
PopulateSanitizerPropertiesFromQos(qos, eventProperties);

if (qos.InputFromPipeline != null)
Expand Down Expand Up @@ -500,6 +502,17 @@ private void PopulateSanitizerPropertiesFromQos(AzurePSQoSEvent qos, IDictionary
}
}

private void PopulateConfigMetricsFromQos(AzurePSQoSEvent qos, IDictionary<string, string> eventProperties)
{
if (qos?.ConfigMetrics != null)
{
foreach (var configMetric in qos.ConfigMetrics)
{
eventProperties[configMetric.ConfigKey] = configMetric.ConfigValue;
}
}
}

private static string[] exceptionTrackAcceptModuleList = { "Az.Accounts", "Az.Compute", "Az.AKS", "Az.ContainerRegistry" };
private static string[] exceptionTrackAcceptCmdletList = { "Get-AzKeyVaultSecret", "Get-AzKeyVaultCert" };

Expand Down Expand Up @@ -656,7 +669,11 @@ public class AzurePSQoSEvent

public string ParameterSetName { get; set; }
public string InvocationName { get; set; }

public List<ConfigMetrics> ConfigMetrics { get; private set; }

public Dictionary<string, string> CustomProperties { get; private set; }

private static bool ShowTelemetry = string.Equals(bool.TrueString, Environment.GetEnvironmentVariable("AZUREPS_DEBUG_SHOW_TELEMETRY"), StringComparison.OrdinalIgnoreCase);

public SanitizerTelemetry SanitizerInfo { get; set; }
Expand All @@ -666,6 +683,7 @@ public AzurePSQoSEvent()
StartTime = DateTimeOffset.Now;
_timer = new Stopwatch();
_timer.Start();
ConfigMetrics = new List<ConfigMetrics>();
CustomProperties = new Dictionary<string, string>();
}

Expand Down

0 comments on commit f44d051

Please sign in to comment.