# Automatic Instrumentation

## Log Events

Upon start, the SDK automatically tracks a set of logs by observing certain app and device states.

=== "Android"

    | Event | Notes |
    |---|---|
    | App Close | Triggered by [`ProcessLifecycleOwner Lifecycle.Event.ON_STOP`](https://developer.android.com/reference/androidx/lifecycle/ProcessLifecycleOwner) |
    | App Exit | Emitted each time the SDK is started and Android returns a result from the [`getHistoricalProcessExitReasons`](https://developer.android.com/reference/kotlin/android/app/ActivityManager#gethistoricalprocessexitreasons) method containing details about the [`ApplicationExitInfo`](https://developer.android.com/reference/android/app/ApplicationExitInfo). |
    | App Launch | Triggered by [`ProcessLifecycleOwner Lifecycle.Event.ON_CREATE`](https://developer.android.com/reference/androidx/lifecycle/ProcessLifecycleOwner) |
    | App Launch TTI | [Manually emitted by the SDK customer](#tti) when the app becomes interactive or when a user interacts with the app, depending on the desired behavior. |
    | App Moved To Background | Triggered by [`ProcessLifecycleOwner Lifecycle.Event.ON_PAUSE`](https://developer.android.com/reference/androidx/lifecycle/ProcessLifecycleOwner) |
    | App Moved To Foreground | Triggered by [`ProcessLifecycleOwner Lifecycle.Event.ON_RESUME`](https://developer.android.com/reference/androidx/lifecycle/ProcessLifecycleOwner) |
    | App Open | Triggered by [`ProcessLifecycleOwner Lifecycle.Event.ON_START`](https://developer.android.com/reference/androidx/lifecycle/ProcessLifecycleOwner) |
    | App Update | Emitted each time the SDK detects an [`versionName`](https://developer.android.com/reference/android/content/pm/PackageInfo#versionName) or [`longVersionCode`](https://developer.android.com/reference/android/content/pm/PackageInfo#getLongVersionCode()) change. The emitted log event contains information about the app installation size. |
    | Fatal Issue - JVM | Triggered by intercepting [uncaught exceptions](https://developer.android.com/reference/java/lang/Thread.UncaughtExceptionHandler) |
    | Low Power Mode | Triggered by [`isPowerSaveMode`](https://developer.android.com/reference/android/os/PowerManager#isPowerSaveMode()) |
    | Memory Pressure | Emitted when app memory usage exceeds [ActivityManager.MemoryInfo.threshold](https://developer.android.com/reference/android/app/ActivityManager.MemoryInfo#threshold). Replaces noisy onTrimMemory-based logging. |
    | Orientation Change | Emmitted each time the SDK detects a device orientation change. |
    | Resource Utilization | Periodically reported event with a snapshot of application's resource consumption. The information captured, among others, includes **memory usage** and **battery level**. |
    | SDK Started | Emitted each time the SDK is started. It contains information about the SDK version and the duration of time the start took. |
    | Screen View | [Manually emitted by the SDK customer](#screen-views) when a user navigates to a different screen view representation. |
    | Slow Rendering | Emitted whenever an application frame takes too long to render, as detected by the [JankStats library](https://developer.android.com/topic/performance/jankstats). Android defines default [latency thresholds](https://developer.android.com/topic/performance/vitals/render#jank-relationship): frames taking longer than 16 ms are classified as **Slow Frames**, longer than 700 ms as **Frozen Frames**, and frames that exceed 5 seconds are labeled as **ANR (Application Not Responding) Frames**. These thresholds can be customized via runtime flags. |
    | Thermal State Changed | Emitted each time the callbacks of [`OnThermalStatusChangedListener`](https://developer.android.com/reference/android/os/PowerManager.OnThermalStatusChangedListener) are called. |
    | Timezone Change | Triggered by [`Intent.ACTION_TIMEZONE_CHANGED`](https://developer.android.com/reference/android/content/Intent#ACTION_TIMEZONE_CHANGED) |

=== "iOS"

    | Event | Notes |
    |---|----|
    | App Close | Triggered by [`UIApplicationDidEnterBackgroundNotification`](https://developer.apple.com/documentation/uikit/uiapplicationdidenterbackgroundnotification?language=objc) |
    | App Did Finish Launching | Triggered by [`didFinishLaunchingNotification`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/application(_:didfinishlaunchingwithoptions:)) |
    | App Launch TTI | [Manually emitted by the SDK customer](#tti) when the app becomes interactive or when a user interacts with the app, depending on the desired behavior. |
    | App Not Responding (ANR) | Emitted each time the main run loop becomes unresponsive for a specified amount of time. Default is 2 seconds but can be configured by runtime flag.
    | App Open | Triggered by [`UIApplicationWillEnterForegroundNotification`](https://developer.apple.com/documentation/uikit/uiapplicationwillenterforegroundnotification?language=objc) or [`didFinishLaunchingNotification`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/application(_:didfinishlaunchingwithoptions:)) |
    | App Update | Emitted each time the SDK detects a [version](https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleshortversionstring?language=objc) or [build number](https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleversion?language=objc) change. The emitted log event contains information about the app installation size. |
    | App Will Terminate | Triggered by [`UIApplicationWillTerminateNotification`](https://developer.apple.com/documentation/uikit/uiapplicationwillterminatenotification?language=objc) |
    | Low Power Mode | Triggered by [`isLowPowerModeEnabled`](https://developer.apple.com/documentation/foundation/processinfo/1617047-islowpowermodeenabled) |
    | Memory Pressure | Triggered by [`applicationDidReceiveMemoryWarning`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623063-applicationdidreceivememorywarni?language=objc) |
    | Orientation Change | Emmitted each time the SDK detects a device orientation change. |
    | Resource Utilization | Periodically reported event with a snapshot of application's resource consumption. The information captured, among others, includes **memory usage** and **battery level**. |
    | Scene Did Enter Background | Triggered by [`UIApplicationDidEnterBackgroundNotification`](https://developer.apple.com/documentation/uikit/uiapplicationdidenterbackgroundnotification?language=objc) |
    | Scene Will Enter Foreground | Triggered by [`UIApplicationWillEnterForegroundNotification`](https://developer.apple.com/documentation/uikit/uiapplicationwillenterforegroundnotification?language=objc) |
    | Screen View | [Manually emitted by the SDK customer](#screen-views) when a user navigates to a different screen view representation. |
    | SDK Started | Emitted each time the SDK is started. It contains information about the duration of time the start took. |
    | Session Replay | Emitted each time the SDK captures session replay frame. |
    | Thermal State Changed | Emitted each time [`ProcessInfo.thermalStateDidChangeNotification`](https://developer.apple.com/documentation/foundation/processinfo/1410656-thermalstatedidchangenotificatio) notification is posted. |
    | Timezone Change | Triggered by [`NSSystemTimeZoneDidChange`](https://developer.apple.com/documentation/foundation/nsnotification/name/1387256-nssystemtimezonedidchange) |

=== "React Native"

    React Native supports all the out of the box events provided by the platform the app is running on, see the iOS and Android sections for more details.

## Resource Reporting

The Capture SDK can take periodic snapshots of the resource consumption of the app on the device. The information captured, among others, includes **memory usage** and **battery level**.

Resource Utilization also includes **Battery Level Change Per Min**.

- Positive values mean the battery is draining.
- Negative values mean the device is charging.
- Example: A data point with a value of `10` means the battery drained 10 percentage points in the last minute.
- Example: `-10` means the battery gained 10 percentage points per minute.

!!! note
    At the moment, this value is available for charts, but it is not shown in Timeline session entries.

## Session Replay

The Capture SDK makes it possible to periodically capture optimized representations of the user screen that do not include Personal Identifiable Information (PII) like text or images.

The feature captures the application screen on a periodic basis, is enabled by default, and can be disabled at any time through a remote configuration update.

The feature allows you to specify additional categorizers, which can be used to provide custom rendering for your app-specific views. For example, categorizers can inform the SDK that your custom implementation of a switch-like UI should be rendered as a switch.

!!! info
    #### Disabling Session Replay
    - To allow the SDK to operate without session replay, you can pass a null `sessionReplayConfiguration` to the `Configuration` object used with the initial `Logger.start` call.

    ```kotlin
    Logger.start(
      // ...
      configuration = Configuration(
        sessionReplayConfiguration = null
        )
      )
    )
    ```

    ```swift
    Logger.start(
        // ...
        configuration: .init(
            sessionReplayConfiguration: nil
        )
    )
    ```

=== "Android (Kotlin)"

    ```kotlin
    Logger.start(
      // ...
      configuration = Configuration(
        sessionReplayConfiguration = SessionReplayConfiguration(
          categorizers = mapOf(
            ReplayType.View to listOf("CoreUiPanel")
          )
        )
      )
    )
    ```
    !!! info
        Session Replay supports both standard **Android** views as well as **Compose** views.
=== "Android (Java)"

    ```java
    HashMap categorizers = new HashMap();
    List<String> names = new LinkedList<String>();
    names.add("CoreUiPanel")
    categorizers.put(ReplayType.View, names);

    Logger.start(
      // ...
      new Configuration(
        new SessionReplayConfiguration(
          categorizers // categorizers
        )
      )
    );
    ```
    !!! info
        Session Replay supports both standard **Android** views as well as **Compose** views.

=== "iOS (Swift)"

    ```swift
    Logger.start(
      // ...
      configuration: .init(
        sessionReplayConfiguration: .init(
          categorizers: [
              "CoreUiPanel": AnnotatedView(.view, recurse: false),
          ]
        )
      )
    )
    ```

    !!! info
        Session Replay supports both **UIKit** views as well as **SwiftUI** views.

## TTI

Currently the SDK requires the customer to supply Time To Interactive (TTI) information via an
explicit API. This data will be used to populate the App Launch TTI log event as well as data in
the [TTI](../../product/instant-insights/categories.md#ux) instant insights dashboard.

=== "Android (Kotlin)"

    ```kotlin
    Logger.logAppLaunchTTI(...)
    ```

=== "Android (Java)"

    ```java
    Logger.logAppLaunchTTI(...);
    ```

=== "iOS (Swift)"

    ```swift
    Logger.logAppLaunchTTI(...)
    ```

=== "React Native"

    ```javascript
    import { logAppLaunchTTI } from '@bitdrift/react-native';

    logAppLaunchTTI(ttiMs)

    ```

## Screen Views

Currently the SDK requires the customer to supply which screens the users has visited via an
explicit API. This data will be used to populate the [User Journeys](../../product/instant-insights/categories.md#user-journey) instant insights dashboard.

=== "Android (Kotlin)"

    ```kotlin
    Logger.logScreenView("my_screen_name")
    ```

=== "Android (Java)"

    ```java
    Logger.logScreenView("my_screen_name");
    ```

=== "iOS (Swift)"

    ```swift
    Logger.logScreenView("my_screen_name")
    ```

=== "React Native"

    ```javascript
    import { logScreenView } from '@bitdrift/react-native';

    logScreenView('my_screen_name')
    ```

## Issues & Crashes

!!! info ""
  Refer to [Issues & Crashes](./fatal-issues.md) section for more details about how to enable automatic detection and upload of issues.

## Integrations

!!! info ""
    Refer to [Integrations](../integrations.md) section for more details about various integrations including, but not limited to, capturing of network traffic information.
