Skip to content

Commit 95df4e8

Browse files
authored
Added function to log cmdlet execution info during test (#361)
1 parent 1b1efb9 commit 95df4e8

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

src/Authentication.Abstractions/Models/ConfigKeysForCommon.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ public static class ConfigKeysForCommon
2727
public const string EnableInterceptSurvey = "DisplaySurveyMessage";
2828
public const string DisplayBreakingChangeWarning = "DisplayBreakingChangeWarning";
2929
public const string EnableDataCollection = "EnableDataCollection";
30+
public const string EnableTestCoverage = "EnableTestCoverage";
3031
}
3132
}

src/Common/AzurePSCmdlet.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,9 @@ protected virtual void InitializeQosEvent()
673673
_qosEvent.PSHostName = PSHostName;
674674
_qosEvent.ModuleName = this.ModuleName;
675675
_qosEvent.ModuleVersion = this.ModuleVersion;
676+
_qosEvent.SourceScript = MyInvocation.ScriptName;
677+
_qosEvent.ScriptLineNumber = MyInvocation.ScriptLineNumber;
678+
676679
if (this.MyInvocation != null && this.MyInvocation.MyCommand != null)
677680
{
678681
_qosEvent.CommandName = this.MyInvocation.MyCommand.Name;
@@ -752,18 +755,14 @@ protected void LogQosEvent()
752755
return;
753756
}
754757

758+
_qosEvent.ParameterSetName = this.ParameterSetName;
755759
_qosEvent.FinishQosEvent();
756760

757761
if (!IsUsageMetricEnabled && (!IsErrorMetricEnabled || _qosEvent.IsSuccess))
758762
{
759763
return;
760764
}
761765

762-
if (!IsDataCollectionAllowed())
763-
{
764-
return;
765-
}
766-
767766
WriteDebug(_qosEvent.ToString());
768767

769768
try

src/Common/ITestCoverage.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
namespace Microsoft.WindowsAzure.Commands.Common
16+
{
17+
/// <summary>
18+
/// All properties and actions defined for test coverage
19+
/// </summary>
20+
public interface ITestCoverage
21+
{
22+
/// <summary>
23+
/// Log the raw data from QoS event object
24+
/// </summary>
25+
/// <param name="qos"></param>
26+
void LogRawData(AzurePSQoSEvent qos);
27+
}
28+
}

src/Common/MetricHelper.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.Azure.Commands.Common;
1919
using Microsoft.Azure.Commands.Common.Authentication;
2020
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
21+
using Microsoft.Azure.PowerShell.Common.Config;
2122
using Microsoft.Azure.PowerShell.Common.Share;
2223
using Microsoft.Rest.Azure;
2324
using Microsoft.WindowsAzure.Commands.Common.Utilities;
@@ -181,11 +182,20 @@ public void AddTelemetryClient(TelemetryClient client)
181182

182183
public void LogQoSEvent(AzurePSQoSEvent qos, bool isUsageMetricEnabled, bool isErrorMetricEnabled)
183184
{
184-
if (qos == null || !IsMetricTermAccepted())
185-
{
185+
if (qos == null)
186186
return;
187+
188+
if (!string.IsNullOrEmpty(qos.SourceScript)
189+
&& AzureSession.Instance.TryGetComponent<IConfigManager>(nameof(IConfigManager), out var configManager)
190+
&& configManager.GetConfigValue<bool>(ConfigKeysForCommon.EnableTestCoverage)
191+
&& AzureSession.Instance.TryGetComponent<ITestCoverage>(nameof(ITestCoverage), out var testCoverage))
192+
{
193+
testCoverage.LogRawData(qos);
187194
}
188195

196+
if (!IsMetricTermAccepted())
197+
return;
198+
189199
if (isUsageMetricEnabled)
190200
{
191201
LogUsageEvent(qos);
@@ -573,6 +583,8 @@ public class AzurePSQoSEvent
573583
public string ModuleName { get; set; }
574584
public string ModuleVersion { get; set; }
575585
//Version of PowerShell runspace ($Host.Runspace.Version)
586+
public string SourceScript { get; set; }
587+
public int ScriptLineNumber { get; set; }
576588
public string PSVersion { get; set; }
577589
//Host version of PowerShell ($Host.Version) which can be customized by PowerShell wrapper
578590
public string HostVersion { get; set; }

0 commit comments

Comments
 (0)