Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Authentication.Abstractions/Models/ConfigKeysForCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ public static class ConfigKeysForCommon
public const string EnableDataCollection = "EnableDataCollection";
public const string EnableTestCoverage = "EnableTestCoverage";
public const string CheckForUpgrade = "CheckForUpgrade";
//Use DisableErrorRecordsPersistence as opt-out for now, will replace it with EnableErrorRecordsPersistence as opt-in at next major release (November 2023)
public const string DisableErrorRecordsPersistence = "DisableErrorRecordsPersistence";
public const string EnableErrorRecordsPersistence = "EnableErrorRecordsPersistence";
}
}
27 changes: 19 additions & 8 deletions src/Common/AzurePSCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,11 @@ protected void WriteSurvey()
}
protected new void WriteError(ErrorRecord errorRecord)
{
FlushDebugMessages(IsDataCollectionAllowed());
FlushDebugMessages();
if (ShouldRecordDebugMessages())
{
RecordDebugMessages();
}
if (_qosEvent != null && errorRecord != null)
{
_qosEvent.Exception = errorRecord.Exception;
Expand All @@ -515,7 +519,11 @@ protected void WriteSurvey()

protected new void ThrowTerminatingError(ErrorRecord errorRecord)
{
FlushDebugMessages(IsDataCollectionAllowed());
FlushDebugMessages();
if (ShouldRecordDebugMessages())
{
RecordDebugMessages();
}
base.ThrowTerminatingError(errorRecord);
}

Expand Down Expand Up @@ -634,13 +642,8 @@ protected void SafeWriteOutputPSObject(string typeName, params object[] args)
WriteObject(customObject);
}

private void FlushDebugMessages(bool record = false)
private void FlushDebugMessages()
{
if (record)
{
RecordDebugMessages();
}

string message;
while (DebugMessages.TryDequeue(out message))
{
Expand Down Expand Up @@ -777,6 +780,14 @@ private void RecordDebugMessages()
}
}

//Use DisableErrorRecordsPersistence as opt-out for now, will replace it with EnableErrorRecordsPersistence as opt-in at next major release (November 2023)
private bool ShouldRecordDebugMessages()
{
return (!AzureSession.Instance.TryGetComponent<IConfigManager>(nameof(IConfigManager), out var configManager)
|| !configManager.GetConfigValue<bool>(ConfigKeysForCommon.DisableErrorRecordsPersistence))
&& IsDataCollectionAllowed();
}

/// <summary>
/// Invoke this method when the cmdlet is completed or terminated.
/// </summary>
Expand Down