Datadog SDK for Android

repository·develop·Indexed 42 days ago

https://github.com/datadog/dd-sdk-android

A client-side SDK for Android and Android TV that enables Log Collection, Real User Monitoring (RUM), and Application Performance Monitoring (APM). It includes support for Feature Flagging and Experimentation via a native FlagsClient or a vendor-neutral OpenFeature Provider.

Tokens
26.5K
Snippets
91
Records
130
Agent score
53%

What's inside Datadog

  1. Use OpenTelemetry extensions for OkHttp

    develop

    The dd-sdk-android-okhttp-otel extension allows you to integrate Datadog with OkHttp using OpenTelemetry.

    Depending on your goal, follow these paths:

    1. Automatic Network Tracking: To automatically track network requests made by the OkHttp library for Real User Monitoring (RUM), refer to the Datadog SDK instrumentation for OkHttp documentation.

    2. Distributed Tracing (Parent Spans): To add a parent span to network requests made by the OkHttp library (enabling distributed tracing), refer to the Datadog SDK Android for OpenTelemetry documentation.

  2. Understand Session Replay performance impact

    develop

    The Session Replay feature has a higher impact on CPU and memory usage compared to the standard Datadog SDK without Replay enabled. Performance varies significantly based on the masking configuration used (Touch Privacy, Text & Input, and Image masking).

    Key Performance Drivers

    • Image Masking: Enabling MASK_NONE for images (recording actual images) tends to increase CPU and memory usage more than other configurations.
    • UI Framework: Performance characteristics differ between traditional Android View and Jetpack Compose implementations.
    • Masking Configuration: The level of privacy applied (e.g., HIDE, MASK_ALL, MASK_SENSITIVE_INPUTS) directly influences the resource overhead.
  3. Understand SDK background behavior and manual tracking

    develop

    When your application moves to the background, the Datadog SDK's auto-instrumentation stops and detaches from UI callbacks (such as lifecycle events and gesture detection). Consequently, RUM events will not be automatically tracked while the app is in the background.

    However, you can still manually track and send events using the RumMonitor. The Datadog endpoints continue to accept RUM events, logs, and traces, and the SDK will continue to collect and send new batches of data.

  4. Compare FlagsClient and OpenFeature Provider

    develop

    Decide between using the Datadog-specific FlagsClient or the vendor-neutral OpenFeature Provider based on your requirements.

    FeatureFlagsClientOpenFeature Provider
    API StandardDatadog-specificOpenFeature standard
    Evaluation ContextPer client instanceGlobal/static context
    Structured FlagsReturns JSONObjectReturns Value.Structure
    Vendor NeutralityDatadog-specificVendor-neutral (easy to swap providers)
    Type SafetyKotlin-native typesOpenFeature Value types
    State ManagementManual listener registrationFlow-based observation

    Use OpenFeature Provider if:

    • You want a vendor-neutral API.
    • You are already using OpenFeature elsewhere.
    • You prefer a static-context paradigm.

    Use FlagsClient directly if:

    • You want the most direct integration with Datadog.
    • You prefer instance-based evaluation contexts.
    • You want to work with native Kotlin types directly.
  5. How RecomposeScopeImpl is used for parameter extraction

    develop

    During composition, some CompositionGroup objects hold an instance of RecomposeScopeImpl within their data iterable.

    RecomposeScopeImpl contains a block lambda used to perform the composition job. This lambda acts as a Single Abstract Method (SAM) interface that holds the parameters passed to @Composable methods. The Compose compiler generates these parameters as properties of the Composable class, allowing the SDK to automatically read these fields and access the values passed to composables.

  6. Manage SDK battery and storage constraints

    develop

    The Datadog SDK includes built-in safeguards to minimize impact on device resources:

    • Battery Consumption: The SDK will not perform any network activity if the device battery level is below 10% or if the device is in power saving mode.
    • Data Lifespan: The SDK stores data in batches and attempts to send them when network is available. To prevent excessive storage use, a batch will not be stored for more than 18 hours. The SDK automatically removes batches older than 18 hours whenever it reads a new batch for sending.
    • Storage Limits: The SDK limits its total storage usage to 512 MB. Every time a new batch is created, the SDK checks the total storage used. If it exceeds 512 MB, the SDK attempts to free up space by removing older files.
  7. Understand Composer and CompositionData structures

    develop

    The Composer tracks the state of the UI through CompositionData. This data is organized into CompositionGroup objects, which represent independent branches of composition (for example, different branches of an if-else statement).

    Each CompositionGroup contains:

    • sourceInfo: A String providing source code insights (file, line number, etc.).
    • identity: A key used to identify the group across recompositions.
    • node: An optional representation of an actual Node.
    • data: An Iterable containing composable inputs and parameters (e.g., CompositionContextHolder).
  8. How Session Replay tracks Jetpack Compose hierarchies

    develop

    Datadog Session Replay tracks Jetpack Compose UI by traversing the internal Composition object stored within ComposeView or AndroidComposeView.

    Key components in the hierarchy include:

    1. ComposeView / AndroidComposeView: The Android View containing the composition.
    2. WrappedComposition: Found in the View's internal tags under the key androidx.compose.ui.R.id.wrapped_composition_tag. It holds the CompositionImpl.
    3. CompositionImpl: Holds the Composer instance used to traverse the UI tree.
    4. Composer: Manages CompositionData, which contains the CompositionGroup objects representing the UI structure.