Skip to content

Telemetry fixes, including restricted environments coverage #4474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 16, 2017
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
8 changes: 0 additions & 8 deletions setup/azurecmdfiles.wxi
Original file line number Diff line number Diff line change
Expand Up @@ -932,9 +932,6 @@
<Component Id="cmp6FA8F4C10D6E2F9D68A204B460AF71FE" Guid="*">
<File Id="filA6898D50D80F756D8D4823D9D198700F" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.ContainerRegistry\Newtonsoft.Json.dll" />
</Component>
<Component Id="cmp84A35F715EEA9EA92E697F6F16DA0551" Guid="*">
<File Id="fil0A0E5309D6B8FB80AD11CFF5AD7B8E98" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.ContainerRegistry\ResourceManagerStartup.ps1" />
</Component>
<Component Id="cmp20310052D0C97B0D3FF2569D32B059E2" Guid="*">
<File Id="filA27432D947F8D24670028256C293BB88" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.ContainerRegistry\System.Net.Http.Extensions.dll" />
</Component>
Expand Down Expand Up @@ -2768,9 +2765,6 @@
<Component Id="cmp2BE59FD587F7E44466F41BF3189A9262" Guid="*">
<File Id="filB2A8EEA5653E4935802251294A7B9F18" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.Resources\Newtonsoft.Json.dll" />
</Component>
<Component Id="cmp44074831AFB81C156E7ED6A30C9965D5" Guid="*">
<File Id="fil243D872BC193D82929CE3811BE0B4014" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.Resources\ResourceManagerStartup.ps1" />
</Component>
<Component Id="cmpA534986DA2E43D7E50E9A6E219478266" Guid="*">
<File Id="filE2D02576DA0A4EEF0E8E1E2CFB76279A" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.Resources\System.Net.Http.Extensions.dll" />
</Component>
Expand Down Expand Up @@ -5646,7 +5640,6 @@
<ComponentRef Id="cmp06C4EBF261D1884EA04708917383FFEC" />
<ComponentRef Id="cmp999FBA5405AD96F6312C0F17EB0C70C4" />
<ComponentRef Id="cmp6FA8F4C10D6E2F9D68A204B460AF71FE" />
<ComponentRef Id="cmp84A35F715EEA9EA92E697F6F16DA0551" />
<ComponentRef Id="cmp20310052D0C97B0D3FF2569D32B059E2" />
<ComponentRef Id="cmp72D0BC3F70A05243347A44BD2C5EBE05" />
<ComponentRef Id="cmp75C3D72B9C46E1B9D3F51CE3D29F6F00" />
Expand Down Expand Up @@ -6242,7 +6235,6 @@
<ComponentRef Id="cmpD9DA964D9A49738CFC38CD27734BA2D4" />
<ComponentRef Id="cmpD80193A27EAF0B72702BBA3F066DD099" />
<ComponentRef Id="cmp2BE59FD587F7E44466F41BF3189A9262" />
<ComponentRef Id="cmp44074831AFB81C156E7ED6A30C9965D5" />
<ComponentRef Id="cmpA534986DA2E43D7E50E9A6E219478266" />
<ComponentRef Id="cmp6D34FB8F9A9678D4511D4BB8E0800104" />
<ComponentRef Id="cmp890B1E2923E26CE2A15A652293EA92BE" />
Expand Down
18 changes: 13 additions & 5 deletions src/Common/Commands.Common/AzureDataCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,21 @@ protected override void SaveDataCollectionProfile()
}

string fileFullPath = Path.Combine(AzureSession.Instance.ProfileDirectory, AzurePSDataCollectionProfile.DefaultFileName);
var contents = JsonConvert.SerializeObject(_dataCollectionProfile);
if (!AzureSession.Instance.DataStore.DirectoryExists(AzureSession.Instance.ProfileDirectory))
try
{
AzureSession.Instance.DataStore.CreateDirectory(AzureSession.Instance.ProfileDirectory);
var contents = JsonConvert.SerializeObject(_dataCollectionProfile);
if (!AzureSession.Instance.DataStore.DirectoryExists(AzureSession.Instance.ProfileDirectory))
{
AzureSession.Instance.DataStore.CreateDirectory(AzureSession.Instance.ProfileDirectory);
}

AzureSession.Instance.DataStore.WriteFile(fileFullPath, contents);
WriteWarning(string.Format(Resources.DataCollectionSaveFileInformation, fileFullPath));
}
catch
{
// do not throw if the profile cannot be written
}
AzureSession.Instance.DataStore.WriteFile(fileFullPath, contents);
WriteWarning(string.Format(Resources.DataCollectionSaveFileInformation, fileFullPath));
}

protected override void SetDataCollectionProfileIfNotExists()
Expand Down
91 changes: 56 additions & 35 deletions src/Common/Commands.Common/AzurePSCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ protected string PSVersion
get
{
if (string.IsNullOrEmpty(_psVersion))
{
if(this.Host != null)
{
if (this.Host != null)
{
_psVersion = this.Host.Version.ToString();
}
Expand Down Expand Up @@ -153,19 +153,33 @@ protected static void InitializeDataCollectionProfile()
// If it exists, remove the old AzureDataCollectionProfile.json file
string oldFileFullPath = Path.Combine(AzurePowerShell.ProfileDirectory,
AzurePSDataCollectionProfile.OldDefaultFileName);
if (AzureSession.Instance.DataStore.FileExists(oldFileFullPath))
try
{
if (AzureSession.Instance.DataStore.FileExists(oldFileFullPath))
{
AzureSession.Instance.DataStore.DeleteFile(oldFileFullPath);
}
}
catch
{
AzureSession.Instance.DataStore.DeleteFile(oldFileFullPath);
// do not throw if the old file cannot be deleted
}

// Try and read from the new AzurePSDataCollectionProfile.json file
string fileFullPath = Path.Combine(AzurePowerShell.ProfileDirectory,
AzurePSDataCollectionProfile.DefaultFileName);
if (AzureSession.Instance.DataStore.FileExists(fileFullPath))
try
{
if (AzureSession.Instance.DataStore.FileExists(fileFullPath))
{
string contents = AzureSession.Instance.DataStore.ReadFileAsText(fileFullPath);
_dataCollectionProfile =
JsonConvert.DeserializeObject<AzurePSDataCollectionProfile>(contents);
}
}
catch
{
string contents = AzureSession.Instance.DataStore.ReadFileAsText(fileFullPath);
_dataCollectionProfile =
JsonConvert.DeserializeObject<AzurePSDataCollectionProfile>(contents);
// do not throw if the data collection profile cannot be serialized
}
}

Expand Down Expand Up @@ -284,7 +298,7 @@ protected virtual void TearDownDebuggingTraces()

protected virtual void SetupHttpClientPipeline()
{
AzureSession.Instance.ClientFactory.UserAgents.Add(new ProductInfoHeaderValue(ModuleName, string.Format("v{0}", ModuleVersion)));
AzureSession.Instance.ClientFactory.UserAgents.Add(new ProductInfoHeaderValue(ModuleName, string.Format("v{0}", ModuleVersion)));
AzureSession.Instance.ClientFactory.UserAgents.Add(new ProductInfoHeaderValue(PSVERSION, string.Format("v{0}", PSVersion)));

AzureSession.Instance.ClientFactory.AddHandler(
Expand Down Expand Up @@ -472,41 +486,48 @@ private void FlushDebugMessages(bool record = false)

private void RecordDebugMessages()
{
// Create 'ErrorRecords' folder under profile directory, if not exists
if (string.IsNullOrEmpty(_errorRecordFolderPath)
|| !Directory.Exists(_errorRecordFolderPath))
try
{
_errorRecordFolderPath = Path.Combine(AzurePowerShell.ProfileDirectory,
"ErrorRecords");
Directory.CreateDirectory(_errorRecordFolderPath);
}
// Create 'ErrorRecords' folder under profile directory, if not exists
if (string.IsNullOrEmpty(_errorRecordFolderPath)
|| !Directory.Exists(_errorRecordFolderPath))
{
_errorRecordFolderPath = Path.Combine(AzurePowerShell.ProfileDirectory,
"ErrorRecords");
Directory.CreateDirectory(_errorRecordFolderPath);
}

CommandInfo cmd = this.MyInvocation.MyCommand;
CommandInfo cmd = this.MyInvocation.MyCommand;

string filePrefix = cmd.Name;
string timeSampSuffix = DateTime.Now.ToString(_fileTimeStampSuffixFormat);
string fileName = filePrefix + "_" + timeSampSuffix + ".log";
string filePath = Path.Combine(_errorRecordFolderPath, fileName);
string filePrefix = cmd.Name;
string timeSampSuffix = DateTime.Now.ToString(_fileTimeStampSuffixFormat);
string fileName = filePrefix + "_" + timeSampSuffix + ".log";
string filePath = Path.Combine(_errorRecordFolderPath, fileName);

StringBuilder sb = new StringBuilder();
sb.Append("Module : ").AppendLine(cmd.ModuleName);
sb.Append("Cmdlet : ").AppendLine(cmd.Name);
StringBuilder sb = new StringBuilder();
sb.Append("Module : ").AppendLine(cmd.ModuleName);
sb.Append("Cmdlet : ").AppendLine(cmd.Name);

sb.AppendLine("Parameters");
foreach (var item in this.MyInvocation.BoundParameters)
{
sb.Append(" -").Append(item.Key).Append(" : ");
sb.AppendLine(item.Value == null ? "null" : item.Value.ToString());
}
sb.AppendLine("Parameters");
foreach (var item in this.MyInvocation.BoundParameters)
{
sb.Append(" -").Append(item.Key).Append(" : ");
sb.AppendLine(item.Value == null ? "null" : item.Value.ToString());
}

sb.AppendLine();

sb.AppendLine();
foreach (var content in DebugMessages)
{
sb.AppendLine(content);
}

foreach (var content in DebugMessages)
AzureSession.Instance.DataStore.WriteFile(filePath, sb.ToString());
}
catch
{
sb.AppendLine(content);
// do not throw an error if recording debug messages fails
}

AzureSession.Instance.DataStore.WriteFile(filePath, sb.ToString());
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Common/Commands.Common/Commands.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<Compile Include="Serialization\LegacyAzureSubscription.cs" />
<Compile Include="Serialization\ModelConversionExtensions.cs" />
<Compile Include="Utilities\FileUtilities.cs" />
<Compile Include="Utilities\INetworkHelper.cs" />
<Compile Include="Utilities\JsonUtilities.cs" />
<Compile Include="AzureDataCmdlet.cs" />
<Compile Include="AzurePSCmdlet.cs" />
Expand All @@ -148,6 +149,7 @@
<Compile Include="Utilities\ConversionUtilities.cs" />
<Compile Include="DebugStreamTraceListener.cs" />
<Compile Include="Utilities\GeneralUtilities.cs" />
<Compile Include="Utilities\NetworkHelper.cs" />
<Compile Include="Utilities\PowerShellUtilities.cs" />
<Compile Include="RecordingTracingInterceptor.cs" />
<Compile Include="ClientCreatedArgs.cs" />
Expand Down
Loading