Skip to content
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

Proguard support #216

Merged
merged 6 commits into from
Jun 12, 2024
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
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
Loading