Crash Analysis API

更新时间:
复制 MD 格式

This document describes the Crash Analysis API for the App Monitor Unity software development kit (SDK), which provides support for custom logs and custom exceptions.

1. Custom logs

Custom logs are reported along with exception information.

API definition

namespace Alicloud.Apm.CrashAnalysis
{
  public static class CrashAnalysis
  {
    public static void Log(string message) {}
  }
}

Custom Log Parameter Description

Parameter

Type

Required

Length range

Description

message

string

Yes

1 to 64000

Custom log message

Code example

using Alicloud.Apm.CrashAnalysis;

CrashAnalysis.Log("Your custom message");

2. Custom exception objects

API definition

namespace Alicloud.Apm.CrashAnalysis
{
  public static class CrashAnalysis
  {
    public static void RecordException(Exception exception) {}
  }
}

Custom Exception Parameter Descriptions

Parameter

Type

Required

Description

exception

System.Exception

Yes

Custom C# exception

Code example

using Alicloud.Apm.CrashAnalysis;

CrashAnalysis.RecordException(new InvalidOperationException("Your exception message")); 

3. Custom exception models

API definition

namespace Alicloud.Apm.CrashAnalysis
{
  public static class CrashAnalysis
  {
    public static void RecordExceptionModel(ExceptionModel exceptionModel) {}
  }
  
  public enum SourceLanguage
  {
    Unknown = 0,
    CSharp,
    Lua
  }
}

ExceptionModel parameters

Parameter

Type

Required

Description

Name

string

Yes

Exception name

Reason

string

Yes

Exception reason

Language

enum

No

The source language of the exception

StackTrace

IList<StackFrame>

No

A list of stack frames, from the most recent call to the oldest

StackFrame parameters

Parameter

Type

Required

Description

Symbol

string

Yes

The symbol, which is typically a function or method name

File

string

No

File name

Line

int

No

Line number

Library

string

No

Library

Code example

using Alicloud.Apm.CrashAnalysis;

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);

4. Set the Unity log level for exception reporting

  • Retrieve or set the minimum Unity log level for exception reporting.

API definition

namespace Alicloud.Apm.CrashAnalysis
{
  public static class CrashAnalysisConfiguration
  {
    public static LogType ReportLogLevel {}
  }
}

Parameters

Parameter

Type

Required

Description

ReportLogLevel

enum

UnityEngine.LogType

Yes

The Unity log level. The SDK collects application exceptions by registering the UnityEngine.Application.logMessageReceivedThreaded callback. The default log level is Exception. The log levels are sorted in ascending order as follows:

  • Log

  • Warning

  • Assert

  • Error

  • Exception

Code example

using Alicloud.Apm.CrashAnalysis;

// Set the Unity log level for exception reporting.
CrashAnalysisConfiguration.ReportLogLevel = UnityEngine.LogType.Exception;
// Get the Unity log level for exception reporting.
UnityEngine.LogType reportLogLevel = CrashAnalysisConfiguration.ReportLogLevel;

5. Set the exception handling policy

  • Retrieve or set the exception handling policy.

API definition

namespace Alicloud.Apm.CrashAnalysis
{
  public static class CrashAnalysisConfiguration
  {
    public static ExceptionPolicy ExceptionMode {}
  }
  
  public enum ExceptionPolicy
  {
    Disabled = 0,
    Record = 1,
    ReportImmediately = 2,
    ReportImmediatelyAndQuitApplication = 3
  }
}

Parameters

Parameter

Type

Required

Description

ExceptionMode

enum

Alicloud.Apm.CrashAnalysis.ExceptionPolicy

Yes

The exception reporting mode. This mode applies to custom exceptions, Unity logs, and exceptions caught by the Common Language Runtime (CLR). The default mode is ReportImmediately. The available values are as follows:

  • Disabled: The SDK takes no action.

  • Record: The SDK records the exception and reports it on the next application cold start. A maximum of 8 exceptions can be recorded.

  • ReportImmediately: The SDK reports the exception immediately. The reporting frequency and the number of reports are limited by the platform configuration.

  • ReportImmediatelyAndQuitApplication: The SDK reports the exception immediately and then quits the application after the report is sent. This mode is not recommended for production environments.

Code example

using Alicloud.Apm.CrashAnalysis;

// Set the exception handling policy.
CrashAnalysisConfiguration.ExceptionMode = ExceptionPolicy.ReportImmediately;
// Get the exception handling policy.
ExceptionPolicy exceptionPolicy = CrashAnalysisConfiguration.ExceptionMode;