Skip to content

Conversation

@bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Oct 22, 2025

This PR adds support for Structured Logging.

Implementation Context

The tricky part is the separation between UnityLogHandlerIntegration and UnityApplicationLoggingIntegration.

UnityLogHandlerIntegration

  • Receives the actual excpetion object we need for line number processing
  • Receives all pre-formatted log messages <- we use this to capture structured logs

UnityApplicationLoggingIntegration

  • Receives materialized log messages allowing us to capture breadcrumbs without additional allocation
  • Receives stringified Unity stack traces we use to attach to events captured via Debug.LogError
  • Allows us to capture exceptions on WebGL

Result

Screenshot 2025-10-22 at 16 49 31 Screenshot 2025-10-22 at 16 51 56

@github-actions
Copy link
Contributor

github-actions bot commented Oct 22, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 78c80ad

@bitsandfoxes bitsandfoxes marked this pull request as ready for review October 24, 2025 11:54
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like a lot but I've split up the implementation of everything inside of OnLogMessageReceived into:

  • IsGettingDebounced
  • ProcessException <- responsible for capturing exceptions via logs on WebGL
  • ProcessError <- responsible for creating events out of Debug.LogError when configured
  • ProcessBreadcrumbs <- responsible for creating breadcrumbs out of logs

private readonly IDiagnosticLogger? _logger;

public UnityErrorLogException(string logString, string logStackTrace, SentryOptions? options)
: base(logString)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is fixing an actual bug where the .NET SDK would automatically add a breadcrumb for exceptions but the actual logmessage would be missing, causing a generic "Exception of type X was captured" breadcrumb.

}

private void OnQuitting()
private void ProcessBreadcrumbs(string message, LogType logType)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the actual change in this file: Capture breadcrumbs only when not capturing structured logs or when explicitly opted in.

Comment on lines +158 to +162
if (_options.AutoSessionTracking)
{
_hub?.PauseSession();
}
_hub?.FlushAsync(_sentryOptions?.ShutdownTimeout ?? TimeSpan.FromSeconds(1)).GetAwaiter().GetResult();
_hub?.FlushAsync(_options.ShutdownTimeout).GetAwaiter().GetResult();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a separate PR that cleans up the unreleated SessionTracking in the LogHandlerIntegration.

@bitsandfoxes bitsandfoxes requested a review from a team October 24, 2025 12:57
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.

2 participants