Skip to content

Commit f44d051

Browse files
authored
Add ConfigInfo Telemetry (#420)
* 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
1 parent 7be70ef commit f44d051

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Concurrent;
17+
using System.Collections.Generic;
18+
19+
namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models
20+
{
21+
/// <summary>
22+
/// Recorded value for config in telemetry
23+
/// </summary>
24+
public class ConfigMetrics: IExtensibleModel
25+
{
26+
/// <summary>
27+
/// The unique key of config. It's required for recording config telemetry.
28+
/// </summary>
29+
public string ConfigKey { get; private set; }
30+
31+
/// <summary>
32+
/// Config value in string format. It's required for recording config telemetry.
33+
/// </summary>
34+
public string ConfigValue { get; private set; }
35+
36+
public IDictionary<string, string> ExtendedProperties { get; } = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
37+
38+
public ConfigMetrics(string ConfigKey, string ConfigValue)
39+
{
40+
this.ConfigKey = ConfigKey;
41+
this.ConfigValue = ConfigValue;
42+
}
43+
}
44+
}

src/Common/MetricHelper.cs

+18
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
using System.Threading.Tasks;
3636
using System.ComponentModel;
3737
using Microsoft.WindowsAzure.Commands.Common.Sanitizer;
38+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models;
3839

3940
namespace Microsoft.WindowsAzure.Commands.Common
4041
{
@@ -451,6 +452,7 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string,
451452
}
452453
}
453454

455+
PopulateConfigMetricsFromQos(qos, eventProperties);
454456
PopulateSanitizerPropertiesFromQos(qos, eventProperties);
455457

456458
if (qos.InputFromPipeline != null)
@@ -500,6 +502,17 @@ private void PopulateSanitizerPropertiesFromQos(AzurePSQoSEvent qos, IDictionary
500502
}
501503
}
502504

505+
private void PopulateConfigMetricsFromQos(AzurePSQoSEvent qos, IDictionary<string, string> eventProperties)
506+
{
507+
if (qos?.ConfigMetrics != null)
508+
{
509+
foreach (var configMetric in qos.ConfigMetrics)
510+
{
511+
eventProperties[configMetric.ConfigKey] = configMetric.ConfigValue;
512+
}
513+
}
514+
}
515+
503516
private static string[] exceptionTrackAcceptModuleList = { "Az.Accounts", "Az.Compute", "Az.AKS", "Az.ContainerRegistry" };
504517
private static string[] exceptionTrackAcceptCmdletList = { "Get-AzKeyVaultSecret", "Get-AzKeyVaultCert" };
505518

@@ -656,7 +669,11 @@ public class AzurePSQoSEvent
656669

657670
public string ParameterSetName { get; set; }
658671
public string InvocationName { get; set; }
672+
673+
public List<ConfigMetrics> ConfigMetrics { get; private set; }
674+
659675
public Dictionary<string, string> CustomProperties { get; private set; }
676+
660677
private static bool ShowTelemetry = string.Equals(bool.TrueString, Environment.GetEnvironmentVariable("AZUREPS_DEBUG_SHOW_TELEMETRY"), StringComparison.OrdinalIgnoreCase);
661678

662679
public SanitizerTelemetry SanitizerInfo { get; set; }
@@ -666,6 +683,7 @@ public AzurePSQoSEvent()
666683
StartTime = DateTimeOffset.Now;
667684
_timer = new Stopwatch();
668685
_timer.Start();
686+
ConfigMetrics = new List<ConfigMetrics>();
669687
CustomProperties = new Dictionary<string, string>();
670688
}
671689

0 commit comments

Comments
 (0)