Skip to main content

ANR Instrumentation

Generates: Events

Automatically detects Application Not Responding (ANR) conditions.

How It Works

The ANR instrumentation polls the UI thread once every second to verify that the main UI thread is still active. If 5 consecutive checks fail, an ANR condition is detected and telemetry is generated.

The ANR instrumentation is only active when the application is in the foreground.

Configuration

ANR detection is enabled by default when using the Android agent. You can configure it during SDK initialization:

PulseSDK.INSTANCE.initialize(
application = this,
endpointBaseUrl = "https://your-backend.com",
) {
anr {
enabled(true) // Enabled by default
}
}

What Gets Tracked

  • ANR conditions (5 consecutive failed UI thread checks)
  • Main thread stack trace at the time of ANR
  • Thread information

Generated Telemetry

Type: Log Record (Event)
Body: ANR detection message
pulse.type: device.anr
Status: ERROR (always)

Attributes

ANR-Specific Attributes

AttributeDescriptionExampleAlways Present
pulse.typeInstrumentation type"device.anr"✅ Yes
exception.stacktraceMain thread stack trace at ANRComplete stack trace string✅ Yes
thread.idMain thread ID2, "2"✅ Yes
thread.nameMain thread name"main"✅ Yes
screen.nameCurrent screen/activity name"MainActivity"⚠️ If available
session.idSession identifier"f40364c92b85ec0c19c35a65be42b97f"✅ Yes

Note: All ANR events include global attributes (service, device, OS, session, network carrier, etc.) in the resources object. See Global Attributes for complete list.

Sample Payload: ANR Event

{
"body": "Application Not Responding detected",
"date": "2025-11-27T08:40:00.000000Z",
"id": "0iiPdg5oW57kWey8dHienFjlP9S",
"timestamp": "2025-11-27T08:40:00.000000Z",
"attributes": {
"pulse.type": "device.anr",
"exception.stacktrace": "at android.os.Handler.dispatchMessage(Handler.java:102)\n at android.os.Looper.loop(Looper.java:193)\n at android.app.ActivityThread.main(ActivityThread.java:6669)\n ...",
"thread.id": 2,
"thread.name": "main",
"screen.name": "MainActivity",
"session.id": "f40364c92b85ec0c19c35a65be42b97f"
},
"resources": {
"android.os.api_level": "36",
"app.build_id": "1",
"app.build_name": "1.0_1",
"device.manufacturer": "Google",
"device.model.identifier": "sdk_gphone64_arm64",
"device.model.name": "sdk_gphone64_arm64",
"os.description": "BE2A.250530.026.D1",
"os.name": "Android",
"os.type": "linux",
"os.version": "16",
"rum.sdk.version": "0.16.0-alpha-SNAPSHOT",
"service.name": "PulseReactNativeOtelExample",
"service.version": "1.0_1",
"telemetry.sdk.language": "java",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "1.54.1"
}
}

Note: This instrumentation supports additional user-configurable AttributeExtractors that may set additional attributes from the stack trace.

Best Practices

  1. Monitor ANR rates: Track ANR frequency to identify performance issues
  2. Optimize main thread: Move heavy operations off the main thread to prevent ANRs