Unity

On this page, we get you up and running with Sentry's SDK, so that it will automatically report errors and exceptions in your application.

Don't already have an account and Sentry project established? Head over to sentry.io, then return to this page.

Install

Sentry captures data by using an SDK within your application’s runtime.

Install the SDK from Unity UPM using a Git URL to Sentry's SDK repository:

Copied
https://github.com/getsentry/unity.git#0.0.12

Configure

Currently, you can only configure Sentry using the Unity tools window.

Open Tools -> Sentry.

The first time you open the window, Unity Sentry SDK related files are created:

  • Assets/Resources/Sentry/SentryOptions.json - Sentry settings
  • Assets/Resources/Sentry/link.xml - a special file for ILL2CPP builds

Sentry tools

And the Sentry configuration window will open:

Sentry window

  • Check Enable to enable Sentry event capturing
  • DSN displays the Sentry DSN value

After you close the window, all settings are saved into Assets/Resources/Sentry/SentryOptions.json.

Verify

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:

Create TestMonoBehaviour.cs with contains Debug.LogError (but can be any exception like the C# expression throw null):

Copied
using UnityEngine;

public class TestMonoBehaviour : MonoBehaviour
{
    void Start()
    {
        Debug.Log("Log");
        Debug.LogWarning("Warning");
        Debug.LogError("Error");
    }
}

Assign it to any object you have in the scene and press play. Open up your Sentry project in the web UI and check the logs.

You should see a new issue:

Sentry issue

Open it up and check breadcrumbs:

Sentry breadcrumbs

The list of captured events are displayed.

Event debouncer

A debouncing mechanism is in place. This means that if you try to send a many requests in a quick succession (with the same log type), we will take the first one and ignore the others given the time slot. Current settings:

  • LogType.Error (also exceptions) or LogType.Exception or LogType.Assert - one second
  • LogType.Log - one second
  • LogType.Warning - one second

Create another DebouncerTestMonoBehaviour.cs, then assign it to any object in the scene and run it.

Copied
using UnityEngine;

public class DebouncerTestMonoBehaviour : MonoBehaviour
{
    void Start()
    {
        Debug.Log("Log");             // recorded
        Debug.Log("Log2");            // not recorded (1 second didn't expire from the previous call)
        Debug.LogWarning("Warning");  // recorded
        Debug.LogWarning("Warning2"); // not recorded
        Debug.LogError("Error");      // recorded
    }
}

To view and resolve the recorded error, log into sentry.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

You can edit this page on GitHub.