Search Unity

Custom Metadata for each exception report

Discussion in 'Unity Cloud Diagnostics' started by Djadjouka, May 1, 2019.

  1. Djadjouka

    Djadjouka

    Joined:
    Nov 1, 2016
    Posts:
    9
    Hi,

    Is there a way to set metadata for a crash report just before it's sent? I'm thinking about reporting some data that varies constantly from frame to frame like the framerate, the ping or the time since the start of the game. If there was an event or a callback when a crash report is ready to be sent, that would be perfect. If it doesn't exist, is it something that is on the roadmap?
     
  2. johng_unity

    johng_unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    158
    I think you can achieve this with SetUserMetadata:

    https://docs.unity3d.com/2018.3/Doc...ndler.CrashReportHandler.SetUserMetadata.html

    This post is a little out of date but it describes this feature as well:

    https://blogs.unity3d.com/2018/10/15/whats-new-in-performance-reporting/

    Note this feature of Cloud Diagnostics is only available to Plus/Pro subscribers.
     
    eladleb4 likes this.
  3. Djadjouka

    Djadjouka

    Joined:
    Nov 1, 2016
    Posts:
    9
    Thanks for the quick reply!

    I have tried that this afternoon. My only issue with that method is that I need to keep updating the values each frame instead of being able to set the data when the crash happens to have the most accurate values. For example, if I wanted to send the time since the game has started, I would have to do it like this:

    Code (CSharp):
    1. public class MetadataManager : MonoBehaviour
    2. {
    3.     private static DateTime gameStartTime;
    4.  
    5.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    6.     private void OnGameStarted()
    7.     {
    8.         gameStartTime = DateTime.Now;
    9.     }
    10.  
    11.     void Update()
    12.     {
    13.         CrashReportHandler.SetUserMetadata("timeSinceGameStart", (DateTime.Now - gameStartTime).TotalSeconds.ToString());
    14.     }
    15. }
    I think that would be easier and more efficient for performance to be able to set the metadata based on a callback or event like this:

    Code (CSharp):
    1. public class MetadataManager : MonoBehaviour
    2. {
    3.     private static DateTime gameStartTime;
    4.  
    5.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    6.     private void OnGameStarted()
    7.     {
    8.         gameStartTime = DateTime.Now;
    9.     }
    10.  
    11.     void Awake()
    12.     {
    13.         CrashReportHandler.UnhandledExceptionEvent += OnUnhandledException;
    14.     }
    15.  
    16.     private void OnUnhandledException()
    17.     {
    18.         CrashReportHandler.SetUserMetadata("timeSinceGameStart", (DateTime.Now - gameStartTime).TotalSeconds.ToString());
    19.     }
    20. }
    The metadata would be processed after that UnhandledExceptionEvent.
     
  4. emmanuelsolis

    emmanuelsolis

    Joined:
    Jan 9, 2019
    Posts:
    1
    I would like add to what @Djadjouka is propossing. Additional to having a callback for when a crash report is genereated, it would also be a great function to be able to force sending a crash report. Some times, part of our code has to be handled in a try ... catch to prevent leaving the execution on an inconsistent state, but it would be very helpfull if we still got the crash report. Currently, only Unhandled exceptions are reported. So, something like this would be great:

    Code (CSharp):
    1.         private void SomeAction()
    2.         {
    3.             try
    4.             {
    5.                 // Work that can fail.
    6.             }
    7.             catch (Exception ex)
    8.             {
    9.                 // Do something to handled the exception
    10.                 CrashReport.Send(ex);
    11.             }
    12.         }
    13.  
    In the example above, after handling the exception, we are still reporting it. That would also be a great place where user metadata can be added to the crash report.
     
    Djadjouka likes this.
  5. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Hi @Djadjouka and @emmanuelsolis, thank you for the awesome suggestions! The callback feature is already in our backlog of features that we'd like to add.

    For the second issue regarding being able to manually send crash reports, you can actually accomplish that by calling Debug.LogException() in your code. These will still send out exception reports while allowing you to properly handle the exception.
     
    Energy0124, Can-Baycay and Djadjouka like this.
  6. Can-Baycay

    Can-Baycay

    Joined:
    Dec 14, 2010
    Posts:
    27
    That's great news @ryanc-unity. Any ETA on that callback feature?
     
  7. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Hi @Can-Baycay! Unfortunately we don't have an ETA yet on the callback feature. But we'll be sure to update everyone here when we're close to announcing something.
     
  8. ethiffeault_ubi

    ethiffeault_ubi

    Joined:
    Jan 8, 2019
    Posts:
    2
  9. fujindevil

    fujindevil

    Joined:
    Oct 3, 2012
    Posts:
    71
    Debug.LogException is not sending a report for us. Is there any way to achieve this?
     
  10. Zarkow

    Zarkow

    Joined:
    Jul 27, 2015
    Posts:
    92
    It looks like the callback never came? Making the class UnityEngine.CrashReportHandler.CrashReportHandler useless and potentially dangerous - the game will carry on, not understanding that something went wrong and that very-very-very often have secondary problems emerging down the line. Up to and including completely ruined savegame files. That is a disaster for players.
     
  11. Liderangel

    Liderangel

    Joined:
    Jul 8, 2018
    Posts:
    101
    Hey! Since it's been 3 years an update on the issue would be much appreciated!
     
    Brown2Fox likes this.
  12. joe_nk

    joe_nk

    Joined:
    Jan 6, 2017
    Posts:
    67
    Would love to see the extended functionality described above