Diagnostics and logging

From decentraland/unity-explorer · View interactive version

Diagnostics and logging is an AI agent skill from the GitHub repository decentraland/unity-explorer. Diagnostics, logging, and error reporting via ReportHub. Use when adding log statements, configuring severity matrices, tagging systems with LogCategory, integrating with Sentry, or overriding log levels at runtime.

How to use this skill

Skill file

Diagnostics & Logging

Sources


ReportHub API

Replace all Debug.Log calls with ReportHub. ReportHub is a custom ILogHandler that routes logs through multiple handlers.

// Log a message with category
ReportHub.Log(ReportCategory.SDK_AUDIO_SOURCES, "Audio source initialized");

// Log a warning
ReportHub.LogWarning(ReportCategory.UNSPECIFIED, $"Not a place: {message}");

// Log an exception
ReportHub.LogException(exception, ReportCategory.GENERIC_WEB_REQUEST);

ReportData

Each log entry carries:

Report Handlers

System Integration

LogCategory Attribute

Tag systems with [LogCategory] to automatically associate logs with a category:

[UpdateInGroup(typeof(CleanUpGroup))]
[LogCategory(ReportCategory.SDK_AUDIO_SOURCES)]
[ThrottlingEnabled]
public partial class CleanUpAudioSourceSystem : BaseUnityLoopSystem, IFinalizeWorldSystem
{
    // All logs from this system are tagged with SDK_AUDIO_SOURCES
}

GetReportCategory

Systems can retrieve their category via GetReportCategory() — the value is cached after first call.

New Features

When creating a new feature, introduce a new ReportCategory entry. Do not reuse existing categories for unrelated features.

CategorySeverityMatrix

Controls which logs get logged per handler, by severity and category. Stored in ReportsHandlingSettings ScriptableObject.

Configuration is a matrix of:

Exception Tolerance

The ISystemGroupExceptionHandler (SceneExceptionsHandler) tracks exceptions per minute:

Runtime Overrides

Method 1 — Chat Command

/log-matrix enable VOICE_CHAT Error
/log-matrix disable SDK_AUDIO_SOURCES Warning

Changes are lost on client close.

Method 2 — JSON File

Drop a .json file in the build root folder, launch with --use-log-matrix "filename.json":

{
    "isOverride": true,
    "debugLogMatrix": [
        { "category": "VOICE_CHAT", "severity": "Warning" }
    ],
    "sentryMatrix": [
        { "category": "VOICE_CHAT", "severity": "Exception" }
    ]
}

Keys must match CategorySeverityMatrixDto field names — JsonUtility ignores unknown ones. { "allOverride": true } enables every category at every severity in the log file only, and takes precedence over isOverride/debugLogMatrix. A log captured under allOverride contains resolved media stream URLs with signed sig/expire query params — do not attach it to a public issue.

Use Cases

Sentry Configuration

Filtering Un-actionable Sentry Events

Some reports are the expected outcome of a condition the client cannot act on: a websocket the remote end dropped (every consumer already retries), a cleartext http:// URL the player refuses (always scene-authored), Unity's own "Platform does not support compute shaders" on below-spec GPUs (the minimum-specs guard already detects it), or failing requests to a creator's preview server in local scene development. "Not a client defect" is not a reason to leave them in Sentry: the fix is to stop reporting them.

Code Example — Exception Handling with Logging

For a real-world example combining exception handling with ReportHub logging, see the async-programming skill's MinimapController.GetPlaceInfoAsync pattern. It demonstrates the standard three-tier catch hierarchy: silent OperationCanceledException, LogWarning for expected errors, and LogException for unexpected failures.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.