Crash analysis

更新时间:
复制 MD 格式

This document describes how to verify the Crash Analysis feature of the Alibaba Cloud App Monitor Unity Software Development Kit (SDK).

1. Report an exception

  1. You can write test code to simulate or trigger a Unity script exception. For example:

    throw new InvalidOperationException("Your exception message");
  2. After you trigger the exception, wait for about 2 minutes. Then, you can view the data on the Custom Exception page under Crash Analysis in the console.

    Note
    • There is a delay of about 2 to 3 minutes from when the exception data is collected to when it is displayed in the console.

    • If the SDK exception handling policy is set to record, the application uploads the exception data after it is restarted.

    image

2. Custom dimensions

  1. You can write test code to call the SDK's custom dimension interface. For example:

    using Alicloud.Apm;
    
    // The following code is an example.
    Apm.SetCustomKeyValue("level", 1);
  2. Call the custom dimension interface and then trigger an exception. After about 2 minutes, you can view the data on the Custom Exception page under Crash Analysis in the console. The data is displayed in the red box in the following figure:

3. Report a custom exception

  1. You can write test code to call the SDK's custom exception interface. For example:

    using Alicloud.Apm.CrashAnalysis;
    
    // The following code is an example.
    try 
    {
      throw new InvalidOperationException("Your exception message");
    } 
    catch (Exception ex)
    {
      CrashAnalysis.RecordException(ex);
    } 
    Note

    In C#, an exception's stack trace is generated when the exception is thrown (throw), not when the exception object is created. Therefore, you must use the method shown in the example to report custom exceptions.

  2. After you call the custom exception interface, wait for about 2 minutes. Then, you can view the data on the Custom Exception page under Crash Analysis in the console. The data is displayed in the red box in the following figure:

    Note

    The Is Custom option shows Yes for exceptions reported by a developer through the SDK's custom interface. This distinguishes them from exceptions that the SDK automatically catches.

4. Customize other scripting language exceptions

  1. You can write test code to call the SDK's custom exception model interface. For example, to report a Lua language exception:

    using Alicloud.Apm.CrashAnalysis;
    
    // The following code is an example.
    var model = new ExceptionModel("LuaRuntimeError", "attempt to index a nil value", SourceLanguage.Lua);
    model.StackTrace.Add(StackFrame.FromSymbol("main", "script.lua", 15, "lua"));
    model.StackTrace.Add(StackFrame.FromSymbol("doSomething", "utils.lua", 8, "lua"));
    
    CrashAnalysis.RecordExceptionModel(model);
  2. After you call the custom exception model interface, wait for about 2 minutes. Then, you can view the data on the Custom Exception page under Crash Analysis in the console. The data is displayed in the red box in the following figure:

    Note

    Currently, the Unity SDK supports exception types only for the C# and Lua scripting languages.