Skip to content

Commit

Permalink
Proguard support (#216)
Browse files Browse the repository at this point in the history
* Allow unity to finish capturing uncaught exception

* Allow to use Proguard symbolication

* Formatting

* Documentation

* Formatting
  • Loading branch information
konraddysput authored Jun 12, 2024
1 parent a8874ae commit 8db1008
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
38 changes: 30 additions & 8 deletions Runtime/BacktraceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ internal AttributeProvider AttributeProvider
}
}

#if UNITY_ANDROID
private bool _useProguard = false;

/// <summary>
/// Allow to enable Proguard support for captured Exceptions.
/// </summary>
/// <param name="symbolicationId">Proguard map symbolication id</param>
public void UseProguard(String symbolicationId) {
_useProguard = true;
AttributeProvider["symbolication_id"] = symbolicationId;
}
#endif

#if !UNITY_WEBGL
private BacktraceMetrics _metrics;

Expand Down Expand Up @@ -971,7 +984,11 @@ internal void OnAnrDetected(string stackTrace)
{
Breadcrumbs.FromMonoBehavior(anrMessage, LogType.Warning, new Dictionary<string, string> { { "stackTrace", stackTrace } });
}
SendUnhandledException(hang);
var report = new BacktraceReport(hang);
if (_useProguard) {
report.UseSymbolication("proguard");
}
SendUnhandledExceptionReport(report);
}

/// <summary>
Expand All @@ -988,15 +1005,20 @@ internal void HandleUnhandledExceptionsFromAndroidBackgroundThread(string backgr
}
var message = backgroundExceptionMessage.Substring(0, splitIndex);
var stackTrace = backgroundExceptionMessage.Substring(splitIndex);
var report = new BacktraceReport(new BacktraceUnhandledException(message, stackTrace));
if (_useProguard) {
report.UseSymbolication("proguard");
}

if (Database != null)
{
var backtraceData = new BacktraceReport(new BacktraceUnhandledException(message, stackTrace)).ToBacktraceData(null, GameObjectDepth);
var backtraceData = report.ToBacktraceData(null, GameObjectDepth);
AttributeProvider.AddAttributes(backtraceData.Attributes.Attributes);
Database.Add(backtraceData);
}
else
{
HandleUnityMessage(message, stackTrace, LogType.Exception);
SendUnhandledExceptionReport(report);
}
var androidNativeClient = _nativeClient as Runtime.Native.Android.NativeClient;
if (androidNativeClient != null)
Expand Down Expand Up @@ -1125,7 +1147,7 @@ internal void HandleUnityMessage(string message, string stackTrace, LogType type
};
}

SendUnhandledException(exception, invokeSkipApi);
SendUnhandledExceptionReport(new BacktraceReport(exception), invokeSkipApi);
}

/// <summary>
Expand All @@ -1142,15 +1164,15 @@ private bool SamplingShouldSkip()
return value > Configuration.Sampling;
}

private void SendUnhandledException(BacktraceUnhandledException exception, bool invokeSkipApi = true)
private void SendUnhandledExceptionReport(BacktraceReport report, bool invokeSkipApi = true)
{
if (OnUnhandledApplicationException != null)
{
OnUnhandledApplicationException.Invoke(exception);
OnUnhandledApplicationException.Invoke(report.Exception);
}
if (ShouldSendReport(exception, null, null, invokeSkipApi))
if (ShouldSendReport(report.Exception, null, null, invokeSkipApi))
{
SendReport(new BacktraceReport(exception));
SendReport(report);
}
}

Expand Down
11 changes: 11 additions & 0 deletions Runtime/Model/BacktraceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ internal string UuidString
/// </summary>
public string[] Classifier;

/// <summary>
/// Symbolication method
/// </summary>
public String Symbolication;

/// <summary>
/// Source code information.
/// </summary>
Expand Down Expand Up @@ -125,6 +130,7 @@ public BacktraceData(BacktraceReport report, Dictionary<string, string> clientAt
Uuid = Report.Uuid;
Timestamp = Report.Timestamp;
Classifier = Report.ExceptionTypeReport ? new[] { Report.Classifier } : new string[0];
Symbolication = report.Symbolication;

SetAttributes(clientAttributes, gameObjectDepth);
SetThreadInformations();
Expand Down Expand Up @@ -152,6 +158,11 @@ public string ToJson()
jObject.Add("attributes", Attributes.ToJson());
jObject.Add("annotations", Annotation.ToJson());
jObject.Add("threads", ThreadData.ToJson());

if (!String.IsNullOrEmpty(Symbolication)) {
jObject.Add("symbolication", Symbolication);
}

if (SourceCode != null)
{
jObject.Add("sourceCode", SourceCode.ToJson());
Expand Down
13 changes: 13 additions & 0 deletions Runtime/Model/BacktraceReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public class BacktraceReport
/// </summary>
public List<BacktraceStackFrame> DiagnosticStack { get; set; }

/// <summary>
/// Current report symbolication method
/// </summary>
public String Symbolication { get; set; }

/// <summary>
/// Source code
/// </summary>
Expand Down Expand Up @@ -119,6 +124,14 @@ public BacktraceReport(
SetDefaultAttributes();
}


/// <summary>
/// Sets report symbolication type
/// </summary>
public void UseSymbolication(String symbolication) {
Symbolication = symbolication;
}

private void SetDefaultAttributes()
{
Attributes["error.message"] = Message;
Expand Down

0 comments on commit 8db1008

Please sign in to comment.