add post exception v2

This commit is contained in:
bluepilledgreat 2025-04-05 01:20:44 +01:00
parent 1f21e8ce0b
commit 1e709f6b35
5 changed files with 45 additions and 8 deletions

View File

@ -1,4 +1,5 @@
using System.Reflection; using System.Net.Http.Json;
using System.Reflection;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Windows; using System.Windows;
using System.Windows.Shell; using System.Windows.Shell;
@ -125,7 +126,7 @@ namespace Bloxstrap
_showingExceptionDialog = true; _showingExceptionDialog = true;
SendLog(); SendLog(ex);
if (Bootstrapper?.Dialog != null) if (Bootstrapper?.Dialog != null)
{ {
@ -198,16 +199,23 @@ namespace Bloxstrap
} }
} }
public static async void SendLog() public static async void SendLog(Exception exception)
{ {
if (!Settings.Prop.EnableAnalytics || !CanSendLogs()) if (!Settings.Prop.EnableAnalytics || !CanSendLogs())
return; return;
var request = new PostExceptionV2Request
{
Type = exception.GetType().ToString(),
Message = exception.Message,
Log = Logger.AsDocument
};
try try
{ {
await HttpClient.PostAsync( await HttpClient.PostAsJsonAsync(
$"https://{WebUrl}/metrics/post-exception", $"https://{WebUrl}/metrics/post-exception-v2",
new StringContent(Logger.AsDocument) request
); );
} }
catch (Exception ex) catch (Exception ex)

View File

@ -27,6 +27,7 @@ global using Bloxstrap.Models.Manifest;
global using Bloxstrap.Models.Persistable; global using Bloxstrap.Models.Persistable;
global using Bloxstrap.Models.SettingTasks; global using Bloxstrap.Models.SettingTasks;
global using Bloxstrap.Models.SettingTasks.Base; global using Bloxstrap.Models.SettingTasks.Base;
global using Bloxstrap.Models.Web;
global using Bloxstrap.Resources; global using Bloxstrap.Resources;
global using Bloxstrap.UI; global using Bloxstrap.UI;
global using Bloxstrap.Utility; global using Bloxstrap.Utility;

View File

@ -0,0 +1,14 @@
namespace Bloxstrap.Models.Web
{
internal class PostExceptionV2Request
{
[JsonPropertyName("type")]
public string Type { get; set; } = "";
[JsonPropertyName("message")]
public string Message { get; set; } = "";
[JsonPropertyName("log")]
public string Log { get; set; } = "";
}
}

View File

@ -31,13 +31,20 @@
<!-- This does not need i18n as this is locked behind "Developer Mode" --> <!-- This does not need i18n as this is locked behind "Developer Mode" -->
<controls:OptionControl <controls:OptionControl
Visibility="{Binding Path=WebEnvironmentVisibility, Mode=OneTime}" Visibility="{Binding Path=DeveloperOptionVisibility, Mode=OneTime}"
Header="Web environment" Header="Web environment"
Description="Site to use for metrics" Description="Site to use for metrics"
HelpLink="https://admin.bloxstraplabs.com/Wiki/Developers/Web-Environments"> HelpLink="https://admin.bloxstraplabs.com/Wiki/Developers/Web-Environments">
<ComboBox Width="200" Padding="10,5,10,5" ItemsSource="{Binding WebEnvironments, Mode=OneWay}" SelectedValue="{Binding WebEnvironment, Mode=TwoWay}" /> <ComboBox Width="200" Padding="10,5,10,5" ItemsSource="{Binding WebEnvironments, Mode=OneWay}" SelectedValue="{Binding WebEnvironment, Mode=TwoWay}" />
</controls:OptionControl> </controls:OptionControl>
<controls:OptionControl
Visibility="{Binding Path=DeveloperOptionVisibility, Mode=OneTime}"
Header="Debug crash"
Description="All our builds keep blowing up!">
<Button Padding="10,5,10,5" Content="Self-destruct" Command="{Binding DebugCrashCommand, Mode=OneTime}" />
</controls:OptionControl>
<ui:CardExpander Margin="0,8,0,0" IsExpanded="True"> <ui:CardExpander Margin="0,8,0,0" IsExpanded="True">
<ui:CardExpander.Header> <ui:CardExpander.Header>
<Grid> <Grid>

View File

@ -28,14 +28,21 @@ namespace Bloxstrap.UI.ViewModels.Settings
set => App.Settings.Prop.WebEnvironment = value; set => App.Settings.Prop.WebEnvironment = value;
} }
public Visibility WebEnvironmentVisibility => App.Settings.Prop.DeveloperMode ? Visibility.Visible : Visibility.Collapsed; public Visibility DeveloperOptionVisibility => App.Settings.Prop.DeveloperMode ? Visibility.Visible : Visibility.Collapsed;
public bool ShouldExportConfig { get; set; } = true; public bool ShouldExportConfig { get; set; } = true;
public bool ShouldExportLogs { get; set; } = true; public bool ShouldExportLogs { get; set; } = true;
public ICommand DebugCrashCommand => new RelayCommand(DebugCrash);
public ICommand ExportDataCommand => new RelayCommand(ExportData); public ICommand ExportDataCommand => new RelayCommand(ExportData);
private void DebugCrash()
{
throw new ApplicationException("Pretend like something terrible has happened");
}
private void ExportData() private void ExportData()
{ {
string timestamp = DateTime.UtcNow.ToString("yyyyMMdd'T'HHmmss'Z'"); string timestamp = DateTime.UtcNow.ToString("yyyyMMdd'T'HHmmss'Z'");