Guarantees
- Never throws. Every method is guarded. Failures inside the SDK are swallowed, never passed to your app.
- Safe before init. Calls made before the SDK has started do nothing.
- Non-blocking. No method does network or heavy disk work on the calling thread.
- Thread-safe. Call from any thread.
CodeskopAndroid.init
fun CodeskopAndroid.init(context: Context, config: CodeskopConfig)Starts the SDK. Call once, from Application.onCreate. It returns immediately and does its setup in the background. Repeated calls are ignored. If the key isn't a public Codeskop key, the SDK stays off. Not needed if you use manifest auto-init.
The Codeskop object
com.codeskop.sdk.core.Codeskop is the entry point for everything after startup.
identify
fun identify(userId: String, traits: Map<String, Any?> = emptyMap())Attaches later events to a user. Pass a stable ID from your own system, never an email. With product analytics (Growth and Scale, 0.3.0+), traits are also sent once as an identify event for the user's profile and segments. The user is held in memory, so call identify again when the app restarts with a signed-in user. See Identify users.
track
fun track(name: String, properties: Map<String, Any?> = emptyMap())Product analytics: records a custom event. Property values may be text, numbers, booleans, null or lists of those. Added in 0.3.0. See Track events & screens.
screen
fun screen(name: String, properties: Map<String, Any?> = emptyMap())Product analytics: records a screen view. Activities are recorded automatically (captureScreens); call this for Compose destinations and fragments. Added in 0.3.0.
reset
fun reset()Clears the current user, for example on logout. The anonymous install ID is kept.
recordException
fun recordException(throwable: Throwable, attributes: Map<String, Any?> = emptyMap())Reports an exception you caught yourself, as a handled exception event with its stack trace. The message is redacted unless captureExceptionMessages is on.
attributes in 0.2.0
Theattributes parameter is accepted but not yet sent with the event.setEnabled
fun setEnabled(enabled: Boolean)Pauses (false) or resumes (true) capture on this device, for the current process. Has no effect before the SDK has finished starting. To keep capture off for a user who opted out, don't call init for them.
flush
suspend fun flush(): BooleanUploads queued events now, instead of waiting for the next scheduled sync. Returns true if a sync ran. Call it from a coroutine, for example lifecycleScope.launch { Codeskop.flush() }. You rarely need it; sync is automatic.
captureApiError / captureApiTiming
fun captureApiError(call: ApiCall)fun captureApiTiming(call: ApiCall)Report an HTTP call yourself, for clients other than OkHttp. The OkHttp adapter calls these for you.
| Option | Type | Default | Description |
|---|---|---|---|
| method | String | required | HTTP method, such as GET or POST. |
| url | String | required | Full URL. Only the host and path are stored; the query string is dropped. |
| status | Int? | null | Response status. Leave null if the call failed before a response. |
| errorKind | String? | null | A short failure label, such as timeout or network_error. |
| requestBytes | Long | 0 | Request body size. |
| responseBytes | Long | 0 | Response body size. |
| timing | ApiTiming? | null | Phase timings in ms: dnsMs, connectMs, tlsMs, ttfbMs, totalMs (each optional). |
| headers | Map<String, String> | emptyMap() | Headers to include. Anything in redactHeaders is masked. |
Methods not to call
Codeskop also exposes methods the SDK uses internally, such as init(config), attachRuntime, sync, refreshConfig, captureAnr and captureHeartbeat. They're public only for technical reasons. Don't call them from your app; use CodeskopAndroid.init to start the SDK.CodeskopConfig
data class CodeskopConfig( val apiKey: String, val endpoint: String = "https://api.codeskop.com", val sampleRates: Map<String, Double> = emptyMap(), val redactHeaders: Set<String> = setOf("authorization", "cookie", "set-cookie"), val maxQueueMb: Int = 10, val flushBatchSize: Int = 50, val captureExceptionMessages: Boolean = false, // 0.2.0+ // Accepted, no effect in 0.3.0: // environment, captureNetwork, captureHeaders, captureBodies, // redactQueryKeys, heartbeatEnabled)Full descriptions are on the Configuration page.
OkHttp adapter
| Option | Type | Description |
|---|---|---|
| OkHttpClient.Builder.codeskop() | OkHttpClient.Builder | Registers both of the pieces below in one call (0.2.0+). Import com.codeskop.sdk.okhttp.codeskop. |
| CodeskopOkHttpInterceptor() | okhttp3.Interceptor | Records failed calls (4xx, 5xx, timeouts, connection errors). Register with addInterceptor. |
| CodeskopEventListener.factory() | EventListener.Factory | Records timing for every completed call. Register with eventListenerFactory. |
Manifest keys
| Option | Type | Default | Description |
|---|---|---|---|
| codeskop.api_key | string | Not set | Public ingest key. Turns on auto-init. |
| codeskop.endpoint | string | https://api.codeskop.com | Ingest URL. |
| codeskop.capture_exception_messages | boolean | false | Send exception messages instead of [REDACTED] (0.2.0+). |
Event types
The names used as sampleRates keys: crash, crash_native, anr, exception, api_error, api_timing, heartbeat. Crash and ANR types are never sampled.