Skip to main content

API Reference

Complete API documentation for the Pulse Android SDK.

Initialization

PulseSDK.INSTANCE.initialize()

Initialize the Pulse SDK. Must be called in your Application.onCreate() method as early as possible.

ParameterTypeRequiredDescription
applicationApplication✅ YesYour application instance
projectIdString✅ YesYour Pulse project ID (found in Dashboard → Settings)
globalAttributes(() -> Attributes)?❌ NoGlobal attributes provider function
sessionConfigSessionConfig❌ NoSession configuration (defaults to SessionConfig.withDefaults())
diskBuffering(DiskBufferingConfigurationSpec.() -> Unit)?❌ NoDisk buffering configuration
instrumentations(InstrumentationConfiguration.() -> Unit)?❌ NoInstrumentation configuration block

Example:

PulseSDK.INSTANCE.initialize(
application = this,
projectId = "your-project-id",
globalAttributes = {
Attributes.of(
AttributeKey.stringKey("app.version"), "1.0.0",
AttributeKey.stringKey("environment"), "production"
)
}
) {
interaction { enabled(true) }
activity { enabled(true) }
networkMonitoring { enabled(true) }
anrReporter { enabled(true) }
}

Instrumentation Options

BlockDescription
activity { }Android Activity lifecycle tracking
fragment { }Android Fragment lifecycle tracking
networkMonitoring { }Automatic HTTP request instrumentation
anrReporter { }Application Not Responding detection
crashReporter { }Native crash reporting
slowRenderingReporter { }Slow and frozen frame detection
interaction { }User interaction flow monitoring

All instrumentation blocks support enabled(Boolean) to toggle them on or off.


PulseSDK.INSTANCE.isInitialized()

Check if the SDK has been successfully initialized.

Returns: Boolean - true if initialized, false otherwise

Example:

if (PulseSDK.INSTANCE.isInitialized()) {
PulseSDK.INSTANCE.trackEvent("app_started", System.currentTimeMillis())
}

User Identification

PulseSDK.INSTANCE.setUserId(id)

Set or clear the current user ID. This identifier will be included in all subsequent telemetry data.

ParameterTypeRequiredDescription
idString?✅ YesUser ID. Pass null to clear the current user ID

Example:

PulseSDK.INSTANCE.setUserId("user_12345")

// Clear user ID (on logout)
PulseSDK.INSTANCE.setUserId(null)

PulseSDK.INSTANCE.setUserProperty(name, value)

Set a single user property that will be included with all telemetry data.

ParameterTypeRequiredDescription
nameString✅ YesProperty name
valueAny?✅ YesProperty value. Pass null to remove the property

Example:

PulseSDK.INSTANCE.setUserProperty("email", "user@example.com")
PulseSDK.INSTANCE.setUserProperty("subscription_tier", "premium")

PulseSDK.INSTANCE.setUserProperties(block)

Set multiple user properties at once.

ParameterTypeRequiredDescription
blockMutableMap<String, Any?>.() -> Unit✅ YesProperties builder block

Example:

PulseSDK.INSTANCE.setUserProperties {
put("email", "user@example.com")
put("subscription_tier", "premium")
put("account_type", "enterprise")
}

Event Tracking

PulseSDK.INSTANCE.trackEvent(name, observedTimeStampInMs, params)

Track a custom event for business analytics and user behavior tracking.

ParameterTypeRequiredDescription
nameString✅ YesEvent name (e.g., "button_clicked", "purchase_completed")
observedTimeStampInMsLong✅ YesTimestamp in milliseconds when the event occurred
paramsMap<String, Any?>❌ NoAdditional event attributes (default: emptyMap())

Example:

PulseSDK.INSTANCE.trackEvent(
name = "product_viewed",
observedTimeStampInMs = System.currentTimeMillis(),
params = mapOf(
"product_id" to "12345",
"product_name" to "Widget Pro",
"category" to "electronics",
"price" to 99.99
)
)

Error Tracking

PulseSDK.INSTANCE.trackNonFatal(name, observedTimeStampInMs, params)

Report a non-fatal error with a custom message. Use this for errors that don't crash the app but should be tracked.

ParameterTypeRequiredDescription
nameString✅ YesError name or message
observedTimeStampInMsLong✅ YesTimestamp in milliseconds when the error occurred
paramsMap<String, Any?>❌ NoAdditional error attributes for context (default: emptyMap())

Example:

try {
processPayment()
} catch (e: PaymentException) {
PulseSDK.INSTANCE.trackNonFatal(
name = "payment_processing_failed",
observedTimeStampInMs = System.currentTimeMillis(),
params = mapOf(
"error_code" to e.code,
"payment_method" to "credit_card",
"amount" to 99.99
)
)
}

PulseSDK.INSTANCE.trackNonFatal(throwable, observedTimeStampInMs, params)

Report a non-fatal exception. Automatically captures stack trace and exception details.

ParameterTypeRequiredDescription
throwableThrowable✅ YesException to report
observedTimeStampInMsLong✅ YesTimestamp in milliseconds when the error occurred
paramsMap<String, Any?>❌ NoAdditional error attributes for context (default: emptyMap())

Example:

try {
val result = apiCall()
} catch (e: NetworkException) {
PulseSDK.INSTANCE.trackNonFatal(
throwable = e,
observedTimeStampInMs = System.currentTimeMillis(),
params = mapOf(
"endpoint" to "/api/users",
"retry_count" to 3
)
)
}

Performance Tracing

PulseSDK.INSTANCE.trackSpan(spanName, params, action)

Create a span with automatic lifecycle management. The span starts when the action begins and ends when it completes (or throws an exception).

ParameterTypeRequiredDescription
spanNameString✅ YesSpan name (e.g., "database_query", "api_call")
paramsMap<String, Any?>❌ NoSpan attributes for context (default: emptyMap())
action() -> T✅ YesCode block to execute within the span

Example:

PulseSDK.INSTANCE.trackSpan(
spanName = "fetch_user_data",
params = mapOf(
"user_id" to "12345",
"operation" to "get_profile"
)
) {
apiClient.getUserProfile("12345")
}

PulseSDK.INSTANCE.startSpan(spanName, params)

Create a span with manual lifecycle control. You must call the returned function to end the span.

ParameterTypeRequiredDescription
spanNameString✅ YesSpan name
paramsMap<String, Any?>❌ NoSpan attributes (default: emptyMap())

Returns: () -> Unit - Function to call when the span should end

Example:

val endSpan = PulseSDK.INSTANCE.startSpan(
spanName = "complex_operation",
params = mapOf("operation_type" to "batch_processing")
)

try {
processBatch1()
processBatch2()
processBatch3()
} finally {
endSpan()
}

OpenTelemetry Access

PulseSDK.INSTANCE.getOtelOrNull()

Get the underlying OpenTelemetry RUM instance. Returns null if the SDK is not initialized.

Returns: OpenTelemetryRum? - The OpenTelemetry RUM instance, or null if not initialized

Example:

val otelRum = PulseSDK.INSTANCE.getOtelOrNull()
if (otelRum != null) {
val tracer = otelRum.openTelemetrySdk.getTracer("custom")
}

PulseSDK.INSTANCE.getOtelOrThrow()

Get the underlying OpenTelemetry RUM instance. Throws an exception if the SDK is not initialized.

Returns: OpenTelemetryRum - The OpenTelemetry RUM instance

Throws: IllegalStateException - If the SDK is not initialized

Example:

try {
val otelRum = PulseSDK.INSTANCE.getOtelOrThrow()
val tracer = otelRum.openTelemetrySdk.getTracer("custom")
} catch (e: IllegalStateException) {
Log.e("PulseSDK", "SDK not initialized", e)
}

Shutdown

PulseSDK.INSTANCE.shutdown()

Shut down the Pulse SDK: flush and release OpenTelemetry resources, uninstall instrumentation, and stop accepting telemetry. Shutdown is terminal in the current process — the SDK cannot be re-initialized; use a fresh app process to enable Pulse again.


Next Steps