• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

backtrace-labs/backtrace-unity: First-class error reporting for the Unity game e ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

backtrace-labs/backtrace-unity

开源软件地址:

https://github.com/backtrace-labs/backtrace-unity

开源编程语言:

C# 98.1%

开源软件介绍:

Backtrace Unity support

Backtrace's integration with Unity allows developers to capture and report log errors, handled and unhandled Unity exceptions, and native crashes to their Backtrace instance, instantly offering the ability to prioritize and debug software errors.

Create your Backtrace instance at https://register.backtrace.io/signup/ today and then integrate this library into your game.

openupm

Usage

 //Read from manager BacktraceClient instance
var backtraceClient = GameObject.Find("_Manager").GetComponent<BacktraceClient>();
try
{
    //throw exception here
}
catch(Exception exception)
{
    var report = new BacktraceReport(exception);
    backtraceClient.Send(report);
}

Feature Summary

  • Lightweight library that quickly submits log errors, handled and unhandled exceptions, and native crashes to Backtrace
    • Supports wide range of Unity versions (2018.4+) and deployments (iOS, Android, Windows, Mac, WebGL, PS4/5 Xbox One/S/X, Nintendo Switch, Stadia)
    • Install via OpenUPM and the Unity Package Manager
  • Collect detailed context
    • Callstacks, including function names and line numbers where possible
    • System metadata including device GUID, OS version, memory usage, process age
    • Custom metadata including app version, scene info, device drivers
    • Breadcrumbs, screenshots, log or config files, other attachments
    • Android NDK Crashes; iOS Native Crashes, Windows Native Crashes
  • Client-side features
    • Deduplication options and custom client side fingerprinting
    • Client side filters and sampling controls
    • Offline crash capture/storage for future collection
    • Customizable event handlers and base classes
    • Performance statistics collection option for timing observability
  • Unity IDE integration to configure Backtrace behaviors in your game.

Prerequisites

  • Unity environment 2018.4.x+
  • .NET 3.5/4.5/Standard 2.0 scripting runtime version
  • Mono or IL2CPP scripting backend
  • Backtrace instance - Create your own at https://register.backtrace.io/signup/

Platforms Supported

Backtrace-unity has been tested and certified for games deployed on the following platforms:

  • Mobile - Android, iOS
  • PC - Windows, Mac
  • Web - WebGL
  • Game Consoles - PlayStation4, PlayStation5, Xbox One, Xbox Series X, Nintendo Switch, Google Stadia

There are some differences in capabilities that backtrace-unity provides based on the platform. Major capabilities are summarized as follows:

  • All Platforms - Errors, Unhandled Exceptions, Handled Exceptions, Custom Indexable Metadata, File Attachments*, Breadcrumbs, Automatic attachment of Screenshots, Client Side Deduplication Rules*, Client Side Submission Filtering, Client Side Submission Limits, Crash Free Metrics (except WebGL), Performance Diagnostics, Offline Database*(Except Nintendo Switch)
  • Android -Identified by attribute uname.sysname = Android; ANRs (Hangs), Native Process and Memory Information, Java Exception Handler (Plugins, Exported Game in Android Studio), NDK crashes, low memory warnings. Client-side unwinding option for NDK 19+ (Unity 2019+).
  • iOS - Identified by attribute uname.sysname = IOS; ANRs (Hangs), Native Engine, Memory and Plugin Crashes.
  • WebGL - Identified by attribute uname.sysname = WebGL. The attribute device.model is currently used to share the browser information. Note that stacktraces for WebGL errors are only available if you choose to enable them in the Publishing Settings / Enable Exceptions drop down. More details here.
  • Switch - Identified by attribute uname.sysname = Switch. Note that the attribute GUID is regenerated with each Switch restart (It is not an accurate count of number of Users or Devices. It is a count of Switch Sessions). Note that the current release does no support Offline Database or related features.
  • PlayStation4 / PlayStation5- Identified by attribute uname.sysname = PS4 / PS5
  • Windows - Identified by attribute uname.sysname = Windows. Provides an option to capture Minidumps for Engine Crashes.
  • MacOS - Identified by attribute uname.sysname = MacOS.

Note: Unity allows you to disable stack trace information in player properties. If this is set, the call stack will be empty and no log lines section will be included in Breadcrumbs.

Setup

List of steps necessary to setup full Backtrace Unity integration.

Installation guide

You have three options, we recommend using OpenUPM for most users.

OpenUPM

  • See our package and installation instructions on OpenUPM.

Git Url

Since Unity 2018.3 the Unity Package Manager allows you to install a package directly via Git. You can use the clone URL on the main page of our repository.

Manual download

  • Download the backtrace-unity zip file. Unzip it and keep the folder in a known location. It can be downloaded here
  • Open your Unity project
  • Use the Unity Package Manager to install the backtrace-unity library (Window -> Package Manager -> Add Package From Disk -> KnownFolder/package.json)

Integrating into your project

  • Under the Assets Menu "Create" option, there is now a Backtrace -> Configuration option. Choose that option (or Right click on empty space and select from the menu box) to have a Backtrace Configuration is generated in the Assets folder. You can drag and drop generated asset file into Backtrace Client configuration window. Backtrace menu dialog box
  • Next, select an object from the Scene Hierarchy to associate the Backtrace reporting client to. In the example below, we use the Manager object., Using the Inspector panel, click the Add Component button and search for the Backtrace Client object.
  • Within the Backtrace Client panel, there is a Backtrace Configuration field. Drag and drop the Backtrace Configuration from the Assets folder to that field. More fields will appear for you to fill in to configure the Backtrace Client and Offline Database options. Backtrace configuration window
  • Provide valid Backtrace client configuration and start using library! Full Backtrace configuration

Integrating into your project via code

One of the integration paths require to create game object in your game scene. If you would like to initialize Backtrace integration programatically, we recommend to use Initialize method available in BacktraceClient class.

  var backtraceClient = BacktraceClient.Initialize(
      url: serverUrl,
      databasePath: "${Application.persistentDataPath}/sample/backtrace/path",
      gameObjectName: "game-object-name",
      attributes: attributes);

If you need to use more advanced configuration, Initialize method accepts a BacktraceConfiguration scriptable object. See below:

  var configuration = ScriptableObject.CreateInstance<BacktraceConfiguration>();
  configuration.ServerUrl = serverUrl;
  configuration.Enabled = true;
  configuration.DatabasePath = "${Application.persistentDataPath}/sample/backtrace/path";
  configuration.CreateDatabase = true;
  configuration.Sampling = 0.002;
  configuration.ClientSideUnwinding = true;
  _backtraceClient = BacktraceClient.Initialize(
      configuration,
      gameObjectName: "game-object-name",
      attributes: attributes);

Plugin best practices

The plugin will report on 6 'classes' or errors:

  1. Log Errors - Programmers use Debug.LogError, a variant of Debug.Log, to log error messages to the console.
  2. Unhandled Exceptions - Unhandled Exceptions are exceptions in a game that occur outside of an explicit try / catch statement.
  3. Handled Exceptions - Exceptions that are explicitly caught and handled.
  4. Crashes - An end to the game play experience. The game crashes or restarts.
  5. Hangs (mobile only) - A game is non responsive. Some platforms will tell the user “This app has stopped responding
  6. Out of memory crashes (mobile only) - A game crashed under memory pressure.
  7. Message reports, explictly sent by the BacktraceClient.

The plugin provides 3 controls for managing what the client will report.

  • The Filter Reports option in the UI, where you can select Everything, Message, Handled Exception, Unhandled Exception, Hang and Game Error.
  • SkipReports allows you to tell the client to only report on specific classes of these errors.
  • Log Error Sampling allows you to tell the client to sample the DebugLog errors. Programmers may not be aware of the frequency that DebugLog errors are being generated when released in retail, and we recommend you are intentional about capturing these types of errors.
  • Client Side Deduplication allows you to aggregate the reports based on callstack, error message, or classifier, and send only a single message to Backtrace each time the offline database is flushed.

Backtrace Client and Offline Database Settings

The following is a reference guide to the Backtrace Client fields:

  • Server Address: This field is required to submit exceptions from your Unity project to your Backtrace instance. More information about how to retrieve this value for your instance is our docs at What is a submission URL and What is a submission token? NOTE: the backtrace-unity plugin will expect full URL with token to your Backtrace instance,

  • Reports per minute: Limits the number of reports the client will send per minutes. If set to 0, there is no limit. If set to a higher value and the value is reached, the client will not send any reports until the next minute. Further, the BacktraceClient.Send/BacktraceClient.SendAsync method will return false.

  • Client Advanced Settings

    • Destroy client on new scene load - Backtrace-client by default will be available on each scene. Once you initialize Backtrace integration, you can fetch Backtrace game object from every scene. In case if you don't want to have Backtrace-unity integration available by default in each scene, please set this value to true.
    • Use normalized exception message: If exception does not have a stack trace, use a normalized exception message to generate fingerprint.
    • Filter reports: Configure Backtrace plugin to filter reports based on report type - Message, Exception, Unhandled Exception, Hang. By default this option is disabled (None).
    • Send unhandled native game crashes on startup: Try to find game native crashes and send them on Game startup.
    • Handle unhandled exceptions: Toggle this on or off to set the library to handle unhandled exceptions that are not captured by try-catch blocks.
    • Symbols upload token - If you want to upload Unity debug symbols for Android NDK Native Crash debugging, enter your Backtrace Symbol upload token here. This option is available only in Android build.
    • Log random sampling rate - Enables a random sampling mechanism for DebugLog.error messages - by default sampling is equal to 0.01 - which means only 1% of randomply sampling reports will be send to Backtrace. If you would like to send all DebugLog.error messages to Backtrace - please replace 0.01 value with 1.
  • Game Object Depth Limit: Allows developer to filter number of game object childrens in Backtrace report.

  • REMOVED: Collect last n game logs: Collect last n number of logs generated by game. This is not part of Breadcrumbs

  • Enabled performance statistics: Allows BacktraceClient to measure execution time and include performance information as report attributes.

  • Ignore SSL validation: Unity by default will validate ssl certificates. By using this option you can avoid ssl certificates validation. However, if you don't need to ignore ssl validation, please set this option to false.

  • Crash Free Metrics Reporting

    • Enable crash free metrics reporting. This toggles the periodic transmission of session information to the Backtrace endpoints. This will enable metrics such as crash free users and crash free sessions. Metric events by default are sent when the game starts, when the game is closed / ends, and every 30 minutes while the game is running. So even if a user starts up the game and quits after only a couple of minutes, session and user metrics will still be sent. See the "Crash Free Metrics" section below for more information on this feature.
  • Attachments Paths

    • Paths to attachments to be included for all report types.
  • Backtrace Database Configuration

    • Enable Database: When this setting is toggled, the backtrace-unity plugin will configure an offline database that will store reports if they can't be submitted do to being offline or not finding a network. When toggled on, there are a number of Database settings to configure.
    • Backtrace Database path: This is the path to directory where the Backtrace database will store reports on your game. You can use interpolated strings SUCH AS ${Application.persistentDataPath}/backtrace/database to dynamically look up a known directory structure to use. NOTE: Backtrace database will remove all existing files in the database directory upion first initialization.
    • Create database directory toggle: If toggled, the library will create the offline database directory if the provided path doesn't exists,
    • Client-side deduplication: Backtrace-unity plugin allows you to combine the same reports. By using deduplication rules, you can tell backtrace-unity plugin how we should merge reports.
    • Breadcrumbs
      • Enable breadcrumbs support - Toggles whether or not Breadcrumbs will be collected and submitted
      • Breadcrumbs events type - Specifies which events to collect and send
      • Breadcrumbs log level - Specifies which logs levels to include. For example, including DEBUG log level will provide more details, but a shorter time window due to network bandwidth constraints
    • Native crashes
      • Capture native crashes: This option will appear for games being deployed to Android or iOS and will allow Backtrace to capture and symbolicate native stack traces from crashes impacting the Unity Engine or any Unity Plugin.
      • Capture ANR (Application not responding): This option will appear for Android or iOS and allow Backtrace to capture Hang reports. If enabled, a report will be generated if an application is not respinsive for more than 5 seconds.
      • Send Out of memory exceptions to Backtrace: This option will appear for Android or iOS and allow Backtrace to follow the behavior defined in the Android or iOS sections.
      • Enable client-side unwinding: This option will appear for supported versions of Android (NDK 19; Unity 2019+), and allow Backtrace to perform client side unwinding of native crashes. Please see Android Client-side unwinding for details.
    • Minidump type: Type of minidump that will be attached to Backtrace report in the report generated on Windows machine.
    • Attach Unity Player.log: Add Unity player log file to Backtrace report. NOTE: This feature is available only on desktop - Windows/MacOS/Linux.
    • Attach screenshot: Generate and attach screenshot of frame as exception occurs.
    • Auto Send Mode: When toggled on, the database will send automatically reports to Backtrace server based on the Retry Settings below. When toggled off, the developer will need to use the Flush method to attempt to send and clear. Recommend that this is toggled on.
    • Maximum number of records: This is one of two limits you can impose for controlling the growth of the offline store. This setting is the maximum number of stored reports in database. If value is equal to zero, then limit not exists, When the limit is reached, the database will remove the oldest entries.
    • Maximum database size: This is the second limit you can impose for controlling the growth of the offline store. This setting is the maximum database size in MB. If value is equal to zero, then size is unlimited, When the limit is reached, the database will remove the oldest entries.
    • Retry interval: If the database is unable to send its record, this setting specifies how many seconds the library should wait between retries.
    • Maximum retries: If the database is unable to send its record, this setting specifies the maximum number of retries before the system gives up.
    • Retry order: This specifies in which order records are sent to the Backtrace server.

Android Specific information

The backtrace-unity library includes support for capturing Android NDK crashes and additional Android Native information, from underlying Android OS (Memory and process related), JNI, and NDK layers.

Native process and memory related information

system.memory usage related information including memfree, swapfree, and vmalloc.used is now available. Additional VM details and voluntary / nonvountary ctxt switches are included.

Client side unwinding

Client side unwinding may be useful if you are unable to upload all the symbols for your application. For example, if you are having stability issues in system or other opaque libraries on the devices where your game is deployed, it is better to unwind the callstack on the crashing application (i.e: the client). This may not provide the same callstack quality as with debugging symbols, but will give you debugging information you would otherwise not have if you don't have debugging symbols available.

This function is enabled in backtrace-unity via the a toggle under Native Crashes in Backtrace UI Panel in Unity (see below) or via the BacktraceConfiguration object and the .ClientSideUnwinding = true;. See an example in the Integrating into your project via code

Native crash options

ANRs and Hangs

When configuring the backtrace-unity client for an Android deployment, programmers will have a toggle available in the backtrace-unity GUI in the Unity Editor to enable or disable ANR or Hang reports. This will use the default of 5 seconds. This will be made configurable in a future release.

The error.type for these reports will be Hang.

Out of Memory Reports

Backtrace can detect and flag low memory conditions for Unity games running on Android devices. When low memory conditions are detected, two attributes will be set:

  • memory.warning will be set to true
  • memory.warning.date will be set to the epoch timestamp of when the low memory condition was detected.

If the games does not recover from low memory conditions and the operating system does decide to kill the game, a crash report will be submitted to Backtrace with memory.warning and memory.warning.date set.

This functionality can be toggled on or off in the Backtrace configuration.

Symbols upload

Unity allows developer to generate symbols archive called symbols.zip in the il2cpp build pipeline in the root directory of your game. In this archive you can find generated symbols for your game libraries. When your game crashes due to a native exception, your stack trace will contain only memory addresses instead of function name. Symbols from symbols.zip archive allows Backtrace to match function address to function name in your source code.

To generate symbols.zip archive make sure:

  • you selected il2cpp build,
  • you checked Create symbols.zip in the Build settings window Create symbols.zip

Backtrace offers to upload symbols automatically from Unity Editor to your Backtrace instance. Backtrace symbols upload pipeline will be triggered after successfull build of il2cpp Android game and when Symbols upload token is available in Backtrace Client options. After successfull build, upload pipeline will confirm symbols upload.

If you build outside the Unity Editor and need to manually upload symbols to Backtrace, you must rename symbols generated by Unity end simply with a .so or a .so.debug extension. By default, symbol files within the .zip will end with extension .sym.so. or .dbg.so Backtrace will only match symbols to files based on the ending with .so or .so.debug extension. Please ensure all .sym.so files are renamed to have a single .so extention, and all .dbg.so files are renamed to have a single .so.debug extension before uploading the zip.

To learn more about how to submit those symbol files to Backtrace, please see the Project Settings / Symbols. You can manage submission tokens, upload via the UI, or configure external Symbol Servers to connect and discover required symbols. Please review additional documentation here.

iOS Specific information

The backtrace-unity library includes support for capturing native iOS crashes as well as iOS native memory and process information from underlying iOS layer.

Native process and memory related information

system and vm usage related information including system.memory.free, system.memory.used, system.memory.total, system.memory.active, system.memory.inactive, system.memory.wired are avaialble.

Hangs

When configuring the backtrace-unity client for an iOS deployment, programmers will have a toggle available in the backtrace-unity GUI in the Unity Editor to enable or disable ANR or Hang reports. This will use the default of 5 seconds. The error.type for these reports will be Hang.

Out of Memory Reports

On iOS devices, when the operation system indicates there's memory pressure, Backtrace take a snapshot of the application state and persists it on the mobile device. When the operating system ends up killing the game, upon restart Backtrace will inspect the state file and deduce if the game was terminated because of memory pressure (for more information on the algorithm, see the backtrace-cocoa repository). If so, an error will be sent based on the data that was previously collected and persisted. Note that a snapshot will be taken every 2 minutes at most if low memory conditions persist.

This functionality can be toggled on or off in the Backtrace configuration.

Native Crashes

When configuring the backtrace-unity client for an iOS deployment in the Unity Editor, programmers will have a toggle to enable or disable Capture native crashes. If this is enabled, the backtrace-unity client will ensure the crash report is generated, stored locally, and uploaded upon next game start. Unity crash reporter might prevent Backtrace Crash reporter from sending crashes to Backtrace. To be sure Backtrace is able to collect and send data please set "Enable CrashReport API" to false. Enable symbols

Debug Symbol upload

When building your iOS game in Xcode, you must make sure you configure the build settings to generate "DWARF with dSYM files for any build that you want to debug with Backtrace (By default, it may only generate DWARF). In the example below, DWARF with dSYM files is enabled in the Project Build Settings for each Target. Enable symbols

This change will generate dSYM files every time you build your game in Xcode. You can find the files in the ...\Build\Products\<the folder representing your build>. Within there will be dSYM files that you should compress into a .zip file and submit to Backtrace for use during symbolication.

pack symbols

To learn more about how to submit those symbol files to Backtrace, please see the Project Settings / Symbols. You can manage submission tokens, upload via the UI, or configure external Symbol Servers to connect and discover required symbols. Please review additional Symbol documentaion at https://support.backtrace.io/hc/en-us/articles/360040517071-Symbolication-Overview

Windows Specific information

The backtrace-unity library includes support for capturing native Windows crashes.

Hangs

When configuring the backtrace-unity client for a Windows deployment, programmers will have a toggle available in the backtrace-unity GUI in the Unity Editor to enable or disable ANR or Hang reports. This will use the default of 5 seconds. The error.type for these reports will be Hang.

Native Crashes

When configuring the backtrace-unity client for a Windows deployment in the Unity Editor, programmers will have a toggle to enable or disable Capture native crashes. If this is enabled, the backtrace-unity client will ensure the crash report is generated, stored locally, and uploaded upon next game start. Backtrace-Unity supports crashes captured by Unity Crash handler and crashes not captured by Unity tool.

Data Privacy

Backtrace-Unity allows developers to remove and modify data that the library collects when an exception occurs using the following methods:

  • BeforeSend event The library will fire an event every time an exception in the managed environment occurs. The BeforeEvent trigger allows you to skip the report (you can do that by returning null value) or to modify data that library collected before sending the report. BeforeSend event might be useful in case if you would like to extend attributes or json object data based on data that application has at the time of exception.

Example code:

//Read from manager BacktraceClient instance
var backtraceClient = GameObject.Find("manager name").GetComponent<BacktraceClient>();
// set beforeSend event
_backtraceClient.BeforeSend = (BacktraceData data) =>
{
    data.Attributes.Attributes["my-dynamic-attribute"] = "value";
    return data;
};
  • Environment Variable Management The Annotations class exposes the EnvironmentVariableCache dictionary - a dictionary that stores environment variables collected by the library. You can manipulate the data in this cache before the report is sent. For example - to replace theUSERNAME environment variable collected by Backtrace library with random string you can easily edit annotations environment varaible and Backtrace-Unity will reuse them on report creation.
Annotations.EnvironmentVariablesCache["USERNAME"] = "%USERNAME%";

Also you can still use BeforeSend event to edit collected diagnostic data:

  client.BeforeSend = (BacktraceData data) =>
  {
      data.Annotation.EnvironmentVariables["USERNAME"] = "%USERNAME%";
      return data;
  }

API Overview

You can further configure your game to submit crashes by making further changes in the C# code for your game.

Basic configuration

If you setup Backtrace client and Backtrace database configuration you can retrieve database and client instances by using GameObject. When you retrieve client instance you can start sending reports from try/catch block in your game!

 //Read from manager BacktraceClient instance
var backtraceClient = GameObject.Find("manager name").GetComponent<BacktraceClient>();

//Set custom client attribute
backtraceClient["attribute"] = "attribute value";

 //Read from manager BacktraceClient instance
var database = GameObject.Find("manager name").GetComponent<BacktraceDatabase>();


try{
    //throw exception here
}
catch(Exception exception){
    var report = new BacktraceReport(exception);
    backtraceClient.Send(report);
}

If you would like to change Backtrace client/database options, we recommend to change these values on the Unity UI via Backtrace Configuration file. However, if you would like to change these values dynamically, please use method Refresh to apply new configuration changes.

For example:

//Read from manager BacktraceClient instance
var backtraceClient = GameObject.Find("manager name").GetComponent<BacktraceClient>();
//Set custom client attribute
backtraceClient[ 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
cmcneil/board-yet: A board game recommendation engine/model/website.发布时间:2022-06-07
下一篇:
yujen/RN4UE4: RakNet plugin for Unreal Engine 4发布时间:2022-06-07
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap