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

fix: Stacktraces for Debug.LogError events #1965

Merged
merged 23 commits into from
Jan 23, 2025

Conversation

bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Jan 13, 2025

Fixes #1608

This PR restores the functionality of capturing Debug.LogError and provides stacktraces in the resulting event.

Before

Screenshot 2025-01-22 at 11 43 07

After

Screenshot 2025-01-22 at 12 54 51

Implementation Details

In this PR, we split the logging integration into two components:

  • UnityLogHandlerIntegration
  • UnityApplicationLoggingIntegration

The UnityLogHandlerIntegration hooks into the actual log handler and intercepts all logs. This allows us to access the exception object directly in case of Debug.LogException, but comes with notable limitations:

  • We must call string.Format for each log captured as a breadcrumb
  • We lose access to the stacktrace string that was previously available through Application.OnMessageReceived

To address these limitations, we now implement both approaches:

  1. Capturing exceptions via UnityLogHandlerIntegration
  2. Creating breadcrumbs for logs via UnityApplicationLoggingIntegration
  3. Capturing LogErrors via UnityApplicationLoggingIntegration

We create a synthetic exception that parses the stringified stacktrace during capture and generates an event from it.

Known Limitations

Currently, we cannot provide line numbers for these issues. The IL2CPPEventProcessor requires an actually thrown exception to retrieve the necessary images and instruction addresses. In the case of Debug.LogError, no such exception exists.

@bitsandfoxes bitsandfoxes marked this pull request as ready for review January 21, 2025 18:59
@bitsandfoxes bitsandfoxes requested a review from vaind January 23, 2025 13:53
@bitsandfoxes bitsandfoxes changed the title fix: Stacktraces for non-exception events fix: Stacktraces for Debug.LogError events Jan 23, 2025
return frames;
}

private static SentryStackFrame ParseStackFrame(string stackFrameLine)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I'd have preferred regex as that would have been easier to read to me. But AFAICT, the manual parsing seems correct

@bitsandfoxes bitsandfoxes merged commit 123b270 into main Jan 23, 2025
13 checks passed
@bitsandfoxes bitsandfoxes deleted the feat/split-logging-integration branch January 23, 2025 17:38
LineNumber = lineNo == -1 ? null : lineNo
};
}
catch (Exception)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concerning that we catch all and don't have any indication of what went wrong. debug logging at least?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split logging integration from error capturing
4 participants