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
endpointBaseUrlString✅ YesBackend endpoint URL for sending telemetry data
endpointHeadersMap<String, String>❌ NoCustom HTTP headers (default: emptyMap())
globalAttributes(() -> Attributes)?❌ NoGlobal attributes provider function
diskBuffering(DiskBufferingConfigurationSpec.() -> Unit)?❌ NoDisk buffering configuration
instrumentations(InstrumentationConfiguration.() -> Unit)?❌ NoInstrumentation configuration block

Example:

PulseSDK.INSTANCE.initialize(
application = this,
endpointBaseUrl = "https://your-backend.com",
endpointHeaders = mapOf("Authorization" to "Bearer token"),
globalAttributes = {
Attributes.of(
AttributeKey.stringKey("app.version"), "1.0.0",
AttributeKey.stringKey("environment"), "production"
)
}
) {
interaction { enabled(true) }
activity { enabled(true) }
network { enabled(true) }
anr { enabled(true) }
}

PulseSDK.INSTANCE.isInitialized()

Check if the SDK has been successfully initialized.

Returns: Boolean - true if initialized, false otherwise

Example:

if (PulseSDK.INSTANCE.isInitialized()) {
// SDK is ready to use
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:

// Set user ID
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
valueString✅ YesProperty value

Example:

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

PulseSDK.INSTANCE.setUserProperties(block)

Set multiple user properties at once using a builder pattern.

ParameterTypeRequiredDescription
blockAttributesBuilder.() -> 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: null)

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: null)

Example:

try {
// Some operation that might fail
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: null)

Example:

try {
// Some operation that might throw
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, block)

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

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

Returns: T - Result of the executed block

Example:

val result = PulseSDK.INSTANCE.trackSpan(
spanName = "fetch_user_data",
params = mapOf(
"user_id" to "12345",
"operation" to "get_profile"
)
) {
// Your code here - span automatically tracks duration
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>✅ YesSpan attributes

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 {
// Perform operations
processBatch1()
processBatch2()
processBatch3()
} finally {
// Always end the span
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) {
// Access OpenTelemetry APIs directly
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()
// Access OpenTelemetry APIs directly
val tracer = otelRum.openTelemetrySdk.getTracer("custom")
} catch (e: IllegalStateException) {
// Handle case where SDK is not initialized
Log.e("PulseSDK", "SDK not initialized", e)
}

Next Steps