Skip to content

Commit

Permalink
feat: attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyg603 committed Oct 7, 2024
1 parent 746db32 commit 007bc23
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 65 deletions.
11 changes: 11 additions & 0 deletions Runtime/BugSplat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ public List<FileInfo> Attachments
}
}

/// <summary>
/// A dictionary of key values pairs to be added every time Post is called
/// </summary>
public Dictionary<string, string> Attributes
{
get
{
return clientSettings.Attributes;
}
}

/// <summary>
/// Upload Editor.log when Post is called
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions Runtime/Client/BugSplatOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class BugSplatOptions : ScriptableObject
[Tooltip("Paths to files (relative to Application.persistentDataPath) to upload with each report")]
public List<string> PersistentDataFileAttachmentPaths;

[Tooltip("Attributes to attach to reports")]
public Dictionary<string, string> Attributes;

[Tooltip("OAuth2 Client ID generated on BugSplat's Integrations page")]
public string SymbolUploadClientId;

Expand Down
12 changes: 12 additions & 0 deletions Runtime/Client/DotNetStandardClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public Task<HttpResponseMessage> Post(FileInfo minidumpFileInfo, IReportPostOpti
private ExceptionPostOptions CreateExceptionPostOptions(IReportPostOptions options)
{
var exceptionPostOptions = new ExceptionPostOptions();

foreach (var attribute in options.AdditionalAttributes)
{
exceptionPostOptions.Attributes.TryAdd(attribute.Key, attribute.Value);
}

exceptionPostOptions.Attachments.AddRange(options.AdditionalAttachments);
exceptionPostOptions.FormDataParams.AddRange(options.AdditionalFormDataParams);
exceptionPostOptions.Description = options.Description;
Expand All @@ -54,6 +60,12 @@ private ExceptionPostOptions CreateExceptionPostOptions(IReportPostOptions optio
private MinidumpPostOptions CreateMinidumpPostOptions(IReportPostOptions options)
{
var minidumpPostOptions = new MinidumpPostOptions();

foreach (var attribute in options.AdditionalAttributes)
{
minidumpPostOptions.Attributes.TryAdd(attribute.Key, attribute.Value);
}

minidumpPostOptions.Attachments.AddRange(options.AdditionalAttachments);
minidumpPostOptions.FormDataParams.AddRange(options.AdditionalFormDataParams);
minidumpPostOptions.Description = options.Description;
Expand Down
3 changes: 2 additions & 1 deletion Runtime/Client/WebGLExceptionClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ private IEnumerator PostException(string exception, IReportPostOptions options =
{ "appKey", options.Key },
{ "user", options.User },
{ "callstack", exception },
{ "crashTypeId", $"{options.CrashTypeId}" }
{ "crashTypeId", $"{options.CrashTypeId}" },
{ "attributes", JsonUtility.ToJson(options.AdditionalAttributes) }
};

var request = UnityWebClient.Post(url, formData);
Expand Down
92 changes: 46 additions & 46 deletions Runtime/Plugins/BugSplatDotNetStandard.deps.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
{
"runtimeTarget": {
"name": ".NETStandard,Version=v2.0/",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETStandard,Version=v2.0": {},
".NETStandard,Version=v2.0/": {
"BugSplatDotNetStandard/4.0.1": {
"dependencies": {
"NETStandard.Library": "2.0.3"
},
"runtime": {
"BugSplatDotNetStandard.dll": {}
}
},
"Microsoft.NETCore.Platforms/1.1.0": {},
"NETStandard.Library/2.0.3": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0"
}
}
}
},
"libraries": {
"BugSplatDotNetStandard/4.0.1": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Microsoft.NETCore.Platforms/1.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-rASRBWOUv1uKrIcHVLJR0ztrzURgBo70Fz0ZbPnvZfMU1TJpZ0fWuiG5dtZQdpmZHSa9jxR6PgifP0TfH4/cqw==",
"path": "microsoft.netcore.platforms/1.1.0",
"hashPath": "microsoft.netcore.platforms.1.1.0.nupkg.sha512"
},
"NETStandard.Library/2.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-st47PosZSHrjECdjeIzZQbzivYBJFv6P2nv4cj2ypdI204DO+vZ7l5raGMiX4eXMJ53RfOIg+/s4DHVZ54Nu2A==",
"path": "netstandard.library/2.0.3",
"hashPath": "netstandard.library.2.0.3.nupkg.sha512"
}
}
{
"runtimeTarget": {
"name": ".NETStandard,Version=v2.0/",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETStandard,Version=v2.0": {},
".NETStandard,Version=v2.0/": {
"BugSplatDotNetStandard/4.2.1.0": {
"dependencies": {
"NETStandard.Library": "2.0.3"
},
"runtime": {
"BugSplatDotNetStandard.dll": {}
}
},
"Microsoft.NETCore.Platforms/1.1.0": {},
"NETStandard.Library/2.0.3": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0"
}
}
}
},
"libraries": {
"BugSplatDotNetStandard/4.2.1.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Microsoft.NETCore.Platforms/1.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A==",
"path": "microsoft.netcore.platforms/1.1.0",
"hashPath": "microsoft.netcore.platforms.1.1.0.nupkg.sha512"
},
"NETStandard.Library/2.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-st47PosZSHrjECdjeIzZQbzivYBJFv6P2nv4cj2ypdI204DO+vZ7l5raGMiX4eXMJ53RfOIg+/s4DHVZ54Nu2A==",
"path": "netstandard.library/2.0.3",
"hashPath": "netstandard.library.2.0.3.nupkg.sha512"
}
}
}
Binary file modified Runtime/Plugins/BugSplatDotNetStandard.dll
Binary file not shown.
Binary file modified Runtime/Plugins/BugSplatDotNetStandard.pdb
Binary file not shown.
2 changes: 2 additions & 0 deletions Runtime/ReportPostOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface IReportPostOptions
{
List<FileInfo> AdditionalAttachments { get; }
List<FormDataParam> AdditionalFormDataParams { get; }
Dictionary<string, string> AdditionalAttributes { get; }
string Description { get; set; }
string Email { get; set; }
string Key { get; set; }
Expand All @@ -28,6 +29,7 @@ public class ReportPostOptions : IReportPostOptions
{
public List<FileInfo> AdditionalAttachments { get; } = new List<FileInfo>();
public List<FormDataParam> AdditionalFormDataParams { get; } = new List<FormDataParam>();
public Dictionary<string, string> AdditionalAttributes { get; } = new Dictionary<string, string>();
public string Description { get; set; }
public string Email { get; set; }
public string Key { get; set; }
Expand Down
8 changes: 7 additions & 1 deletion Runtime/Reporter/WebGLReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public IEnumerator LogMessageReceived(string logMessage, string stackTrace, LogT
User = clientSettings.User,
CrashTypeId = (int)BugSplatDotNetStandard.BugSplat.ExceptionTypeId.UnityLegacy
};

foreach (var attribute in clientSettings.Attributes)
{
options.AdditionalAttributes.TryAdd(attribute.Key, attribute.Value);
}

stackTrace = $"{logMessage}\n{stackTrace}";

yield return Post(stackTrace, options, callback);
Expand All @@ -59,7 +65,7 @@ public IEnumerator Post(Exception ex, IReportPostOptions options = null, Action<
yield return Post(ex.ToString(), options, callback);
}

private IEnumerator Post(string stackTrace, IReportPostOptions options = null, Action<ExceptionReporterPostResult> callback = null)
private IEnumerator Post(string stackTrace, IReportPostOptions options = null, Action<ExceptionReporterPostResult> callback = null)
{
if (clientSettings.CaptureEditorLog)
{
Expand Down
8 changes: 8 additions & 0 deletions Runtime/Settings/DotNetStandardClientSettingsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ public List<FileInfo> Attachments
}
}

public Dictionary<string, string> Attributes
{
get
{
return _bugsplat.Attributes;
}
}

public bool CaptureEditorLog { get; set; } = false;

public bool CapturePlayerLog { get; set; } = true;
Expand Down
1 change: 1 addition & 0 deletions Runtime/Settings/IClientSettingsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace BugSplatUnity.Runtime.Settings
internal interface IClientSettingsRepository
{
List<FileInfo> Attachments { get; }
Dictionary<string, string> Attributes { get; }
bool CaptureEditorLog { get; set; }
bool CapturePlayerLog { get; set; }
bool CaptureScreenshots { get; set; }
Expand Down
1 change: 1 addition & 0 deletions Runtime/Settings/WebGLClientSettingsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal class WebGLClientSettingsRepository : IClientSettingsRepository
// TODO BG what do we do about attachments here...
// https://github.com/BugSplat-Git/bugsplat-unity/issues/37
public List<FileInfo> Attachments { get; } = new List<FileInfo>();
public Dictionary<string, string> Attributes { get; } = new Dictionary<string, string>();
public bool CaptureEditorLog { get; set; } = false;
public bool CapturePlayerLog { get; set; } = false;
public bool CaptureScreenshots { get; set; } = false;
Expand Down
6 changes: 6 additions & 0 deletions Runtime/Util/ReportPostOptionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BugSplatUnity.Runtime.Settings;
using System.Collections.Generic;

namespace BugSplatUnity.Runtime.Util
{
Expand All @@ -11,6 +12,11 @@ public static void SetNullOrEmptyValues(this IReportPostOptions options, IClient
options.AdditionalAttachments.AddRange(clientSettings.Attachments);
}

foreach (var attribute in clientSettings.Attributes)
{
options.AdditionalAttributes.TryAdd(attribute.Key, attribute.Value);
}

if (string.IsNullOrEmpty(options.Description))
{
options.Description = clientSettings.Description;
Expand Down
23 changes: 6 additions & 17 deletions Samples~/my-unity-crasher/Scripts/BugSplatSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ public class BugSplatSettings : MonoBehaviour
void Start()
{
bugsplat = FindObjectOfType<BugSplatManager>().BugSplat;
bugsplat.Attributes.Add("OS", SystemInfo.operatingSystem);
bugsplat.Attributes.Add("CPU", SystemInfo.processorType);
bugsplat.Attributes.Add("MEMORY", $"{SystemInfo.systemMemorySize} MB");
bugsplat.Attributes.Add("GPU", SystemInfo.graphicsDeviceName);
bugsplat.Attributes.Add("GPU MEMORY", $"{SystemInfo.graphicsMemorySize} MB");
bugsplat.Description = "Overridden description from BugSplatSettings.";
bugsplat.Notes = GetSystemInfo();
bugsplat.Notes = "Overridden notes field from BugSplatSettings.";

var lastPost = new DateTime(0);
bugsplat.ShouldPostException = (ex) =>
Expand All @@ -40,20 +45,4 @@ void Update()
{

}


private string GetSystemInfo()
{
var info = new Dictionary<string, string>
{
{ "OS", SystemInfo.operatingSystem },
{ "CPU", SystemInfo.processorType },
{ "MEMORY", $"{SystemInfo.systemMemorySize} MB" },
{ "GPU", SystemInfo.graphicsDeviceName },
{ "GPU MEMORY", $"{SystemInfo.graphicsMemorySize} MB" }
};

var sections = info.Select(section => $"{section.Key}: {section.Value}");
return string.Join(Environment.NewLine, sections);
}
}

0 comments on commit 007bc23

Please sign in to comment.