API reference

The public API on the Sophonz object — sessions and users, logs and exceptions, spans, trace enrichment, and OpenTelemetry extension.

The whole public API lives on the io.sophonz.android.sophonzsdk.Sophonz object. Where automatic instrumentation is not enough, these methods record telemetry directly or add context to what was captured automatically.

Lifecycle

MethodDescription
start(context)Starts the SDK. Call from Application.onCreate()
isStarted()Whether the SDK has started
disable()Stops the SDK
getLastRunEndState()How the previous run ended (clean exit, crash, and so on)
getSdkCurrentTimeMs()The clock the SDK uses, corrected for device clock drift

Users

MethodDescription
setUserIdentifier(id), clearUserIdentifier()User identifier
setUsername(name), clearUsername()Username
setUserEmail(email), clearUserEmail()Email address
addUserPersona(persona), clearUserPersona(p), clearAllUserPersonas()User classification tags
getCurrentUserId()The current user identifier
getDeviceId()The device identifier

CAUTION — Choosing an identifier

Whatever you pass here is stored as given and displayed in the dashboard. An internal identifier is safer than an email address or a real name; check that the value fits your privacy policy.

Sessions

MethodDescription
getCurrentUserSessionId()The current session ID
endUserSession()Ends the session explicitly
addUserSessionProperty(key, value, scope)Adds a session property; scope separates session-only from persistent
removeUserSessionProperty(key)Removes a session property
addUserSessionListener(l), removeUserSessionListener(l)Receives session start and end callbacks

Logs and exceptions

MethodDescription
logInfo(message), logWarning(message), logError(message)Logs by severity
logMessage(message, severity, properties)A log with attributes
logException(throwable, severity, properties, message)Records an exception
logCustomStacktrace(elements, severity, properties, message)Supplies a stack trace directly
addBreadcrumb(message)A breadcrumb, shown on the session timeline
logPushNotification(...)Records a received push notification

Recording an exception is not the same as a crash. A crash is an unhandled exception that ended the app; logException records one you caught and handled.

Spans

MethodDescription
startSpan(name, parent, startTimeMs, autoTerminationMode)Starts a span
createSpan(name, parent, autoTerminationMode)Creates a span to start later
recordSpan(name, parent, attributes, events, mode) { }Times a block as a span
recordCompletedSpan(name, start, end, errorCode, parent, attributes, events)Records an interval that has already finished
getSpan(spanId)Looks up an in-flight span

autoTerminationMode decides what happens to an open span when the app backgrounds or the session ends. It keeps unfinished spans from outliving the session boundary.

Sophonz.recordSpan("checkout") {
  processPayment()
}

Screens and trace enrichment

MethodDescription
startView(name), endView(name)Marks a screen interval explicitly
activityLoaded(activity)Signals that an Activity has finished loading
observeNavigation(activity, controller)Connects a navigation controller
addStartupTraceChildSpan(name, start, end)Adds a child span to the startup trace
addStartupTraceAttribute(key, value)Adds an attribute to the startup trace
addLoadTraceChildSpan(activity, name, start, end)Adds a child span to a screen-load trace
addLoadTraceAttribute(activity, key, value)Adds an attribute to a screen-load trace
applicationInitStart(), applicationInitEnd()Marks the Application init interval
appReady()The point at which the app is actually usable

appReady() matters when the first frame and the moment the user can actually do something are not the same. To end the startup trace at that call, enable automatic_data_capture.end_startup_with_app_ready.

Network

MethodDescription
recordNetworkRequest(request)Records a request directly, for clients no instrumentation covers
addHttpRequestInfoModifier(m), removeHttpRequestInfoModifier(m)Alters request information just before it is recorded
generateW3cTraceparent()Generates a traceparent value for headers you set yourself

Experiments and feature flags

MethodDescription
trackExperiment(name, variant, ttl), untrackExperiment(name, ttl)Records experiment enrolment
trackFeatureFlag(name, ttl), untrackFeatureFlag(name, ttl)Records a feature flag
createExperiment(...), createFeatureFlag(...)Creates a tracking object
trackExperiments(list), trackFeatureFlags(list)Records several at once

These values attach to the session, so performance and error rates can be compared across the users who received a given variant.

OpenTelemetry extension

MethodDescription
getOpenTelemetryKotlin()The OpenTelemetry instance the SDK uses
addSpanExporter(exporter), addSpanProcessor(processor)Extends the span pipeline
addLogRecordExporter(exporter), addLogRecordProcessor(processor)Extends the log pipeline
setResourceAttribute(key, value)Adds a resource attribute

CAUTION — Registration order

Exporters and processors must be registered before start(). Anything added afterwards does not reach the pipeline.

This is the path to sending the same data to an OTLP backend other than Sophonz. The instrumentation follows the OpenTelemetry semantic conventions, so another backend reads it unchanged.