Capturing Logs

Capture native Android app events, live-session log lines, SDK diagnostics, and grouped session properties.

Use app events for timeline entries. Use sendClientLog(...) for ad hoc live-session log lines.

App Events

import ai.ansight.runtime.AnsightEventType

AnsightRuntime.event(
    label = "Checkout loaded",
    type = AnsightEventType.Info,
    details = "route=/checkout",
)

AnsightRuntime.event(
    label = "Payment failed",
    type = AnsightEventType.Error,
    details = "httpStatus=500",
)

Live Client Logs

val result = AnsightRuntime.sendClientLog("Checkout loaded cartId=debug-42")

sendClientLog(...) sends the line over an active live session. It does not automatically mirror Logcat or third-party logging frameworks.

SDK Diagnostics

val callback = AnsightLogCallback { level, message, throwable ->
    Log.d("Ansight", "[$level] $message", throwable)
}

AnsightLogger.registerCallback(callback)
AnsightLogger.removeCallback(callback)

Session Properties

Ansight.registerCustomProperty("app", "region", "au")
Ansight.removeCustomProperty("app", "region")
Ansight.clearCustomProperties()

Grouped properties are sent with session.open and updated during an active live session.

Crash Candidates

Native crash hooks are installed automatically while Crash Capture is enabled. A framework or app integration can add context to the native outbox:

val candidateId = AnsightRuntime.recordCrashCandidate(
    runtime = "kotlin",
    kind = "unhandled_coroutine_exception",
    message = throwable.message,
    stack = throwable.stackTraceToString(),
    fatal = false,
    metadataJson = """{"component":"checkout"}""",
)

A non-fatal candidate is retained as context for an independently confirmed native exit; it is not a crash report by itself. Continue recording ordinary exception events when an error should appear immediately in the current timeline. Do not include secrets or personal data in messages, stacks, breadcrumbs, or metadata.