API reference

All recording, configuration, and capture operations must run on Unity's main thread.

Record an event

TraceId Record(
    string eventName,
    object data = null,
    UnityEngine.Object source = null,
    TraceId parentId = default,
    string category = null,
    TraceLevel level = TraceLevel.Info,
    string callerFile = "",
    string callerMember = "",
    int callerLine = 0);

C# caller attributes supply the calling file, member, and line automatically. The default category is the part of eventName before its first .; names without a separator use General.

Add recording points to game code or event-bus adapters explicitly; the package does not intercept every C# event. Pass the returned session-aware TraceId as parentId to asynchronous and coroutine follow-up work. Causality is not inferred from timestamps.

Recording works in the Editor and Development Builds. Regular release builds return an invalid TraceId. Since method arguments are evaluated before Record is called, guard expensive DTO creation with if (EventTrace.IsEnabled).

EventTrace methods

API Behavior
EventTrace.Configure(options) Validates and copies settings; resizing retains the newest records
EventTrace.StartSession(name, metadata) Creates a session ID, snapshots metadata, and clears the buffer
EventTrace.Record(...) Stores a payload snapshot, caller location, explicit parent ID, and optional call stack
EventTrace.GetSnapshot() Returns the current immutable records in a new array
EventTrace.Capture() Returns a detached capture of the session, records, and dropped count
EventTrace.Clear() Clears the buffer without resetting the session ID or sequence counter
TraceCapture.ToJson() Exports format version 1 JSON
TraceCapture.FromJson(json) Validates format, IDs, sequence, and parent links, then returns a detached capture

TraceRecord exposes read-only properties. GetSnapshot() returns records in buffer order. Source objects are held through weak references; destroyed objects and imported captures cannot be selected. Runtime object IDs are not persistent identifiers across sessions.

Configuration and capture limits

Setting Default Allowed values
enabled true Enable or disable recording
captureCaller true Capture caller file/member/line
captureStackTrace false Capture recording-time call stacks
maxEvents 10000 1–100,000
maxPayloadCharacters 4096 128–65,536
maxStackTraceCharacters 8192 128–65,536
maxBufferCharacters 4 * 1024 * 1024 At least one maximum-sized payload, up to 64M characters

The buffer evicts the oldest records when either the event-count or character budget is exceeded. DroppedCount includes records discarded by either limit. The character budget limits managed string lengths, not exact process memory; record objects, arrays, rendering, stack formatting, and JSON export need additional memory.

Payload snapshots copy public fields and readable public properties, with a default depth limit of 4 and at most 32 collection or object entries. Unity objects store only name, ID, and type. Oversized payloads use valid JSON: {"$truncated":true}. Cycles become <cycle>, excessive depth becomes <max-depth>, and unreadable properties become <unreadable: ...>. Getter execution time is not bounded, so use small data objects.

If a parent is evicted or belongs to another session, the UI indicates this rather than linking to an unrelated event with the same sequence number.

Call stacks

Caller location and call stack capture are independent. Caller location is enabled by default and stores one file/member/line. Stack capture is disabled by default.

var options = EventTrace.Configuration;
options.captureStackTrace = true;
options.maxStackTraceCharacters = 8192;
EventTrace.Configure(options);

EventTrace.Record("Combat.Hit", new { damage = 25 });
string callStack = EventTrace.GetSnapshot()[0].StackTrace;

The stack is captured inside Record, before payload getters are evaluated, and omits the recorder's own frame. It represents the synchronous managed call chain at that moment. File names and line numbers are included when debug symbols are available; optimized or IL2CPP builds can provide less detail. Async and coroutine continuations do not recreate earlier execution stacks.

maxStackTraceCharacters defaults to 8,192 and accepts 128–65,536. Longer stacks are truncated. Stored stack characters count toward maxBufferCharacters; a record larger than the entire buffer budget is dropped. The limit bounds retained stack text, not the temporary allocation used to build the string.

Import and export

var capture = EventTrace.Capture();
var json = capture.ToJson();
var restored = TraceCapture.FromJson(json);

JSON contains session ID, name, start UTC, metadata, event and parent IDs, elapsed time and frame, category and severity, payload, source name and object ID, caller location, and optional stack trace. Unity object references are not exported. The optional stack field preserves format version 1 compatibility with older files.

The Editor uses .etr by default. TraceCaptureImporter imports files in Assets as TraceCaptureAsset objects. Its inspector displays a summary and preview and can open the full capture in the browser. Runtime ToJson and FromJson methods do not depend on the file extension.

Imports accept at most 16M characters and 100,000 records. The browser also checks a 16MB file-size limit before reading. Large exports may exceed these limits, so reduce capture limits or split captures.

Tests

To run the package's EditMode tests in a consuming project, install Unity Test Framework and add "testables": ["com.achive.event-tracer"] to Packages/manifest.json. The runtime package does not depend on Test Framework or Play Bookmarks.