### Setup Local CI Environment Source: https://github.com/datadog/dd-sdk-android/blob/develop/CONTRIBUTING.md Run this script to set up the local continuous integration environment. Ensure you have the Android SDK installed. ```shell ./local_ci.sh --setup ``` -------------------------------- ### Example Test Method Following Conventions Source: https://github.com/datadog/dd-sdk-android/blob/develop/CONTRIBUTING.md Demonstrates a test method adhering to the Given-When-Then principle and the specified naming convention. It includes setup, action, and assertion steps with clear parameter naming. ```kotlin @Test fun `M forward boolean attribute to handler W addAttribute()`( @StringForgery(StringForgeryType.ALPHABETICAL) fakeMessage : String, @StringForgery(StringForgeryType.ALPHABETICAL) fakeKey : String, @BoolForgery value : Boolean, @Mock mockLogHandler: InternalLogger ) { // Given testedLogger = Logger(mockLogHandler) // When testedLogger.addAttribute(fakeKey, value) testedLogger.v(fakeMessage) // Then verify(mockLogHandler) .handleLog( Log.VERBOSE, fakeMessage, null, mapOf(key to value), emptySet() ) } ``` -------------------------------- ### Simulate Cold Start for Application Startup Time Source: https://github.com/datadog/dd-sdk-android/blob/develop/docs/sdk_performance.md Use this command to simulate a cold start of your application for performance testing. Ensure the application is killed before running. ```shell adb shell am start -S -W ml.docilealligator.infinityforreddit/.activities.MainActivity -c android.intent.category.LAUNCHER -a android.intent.action.MAIN ``` -------------------------------- ### Start Gauges Source: https://github.com/datadog/dd-sdk-android/blob/develop/tools/benchmark/README.md Initiate all configured gauges to begin collecting and reporting metrics. This should be called after creating the DatadogMeter. ```kotlin meter.startGauges() ``` -------------------------------- ### Minimal Sample App Configuration Source: https://github.com/datadog/dd-sdk-android/blob/develop/sample/README.md Use this minimal configuration for basic sample app setup. Ensure 'token' and 'rumApplicationId' are replaced with your actual Datadog credentials. ```json { "token": "YOUR APP TOKEN", "rumApplicationId": "YOUR RUM APPLICATION ID" } ``` -------------------------------- ### Build SDK with Gradle Source: https://github.com/datadog/dd-sdk-android/blob/develop/CONTRIBUTING.md Use this Gradle command to assemble the SDK libraries. Ensure you have Gradle installed and the project is cloned. ```shell ./gradlew assembleLibraries ``` -------------------------------- ### Start Performance Measure Source: https://github.com/datadog/dd-sdk-android/wiki/InternalLogger Start measuring a performance metric. Returns a PerformanceMetric object that can later be used to send telemetry, or null if sampled out. ```APIDOC ## startPerformanceMeasure ### Description Start measuring a performance metric. Returns a PerformanceMetric object that can later be used to send telemetry, or null if sampled out. ### Method ABSTRACT FUN ### Endpoint N/A (Internal method) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **PerformanceMetric?** - a PerformanceMetric object that can later be used to send telemetry, or null if sampled out #### Response Example N/A ### Parameters - **callerClass** (String) - Required - name of the class calling the performance measurement. - **metric** (TelemetryMetricType) - Required - name of the metric that we want to measure. - **samplingRate** (Float) - Required - value between 0-100 for sampling the event. - **operationName** (String) - Required - the name of the operation being measured ``` -------------------------------- ### Configuration Builder Constructor Source: https://github.com/datadog/dd-sdk-android/wiki/Configuration.Builder Initializes the Configuration.Builder with essential parameters for SDK setup. ```APIDOC ## Constructor Configuration.Builder ### Description Initializes the Configuration.Builder with essential parameters for SDK setup. ### Method constructor ### Parameters #### Path Parameters - **clientToken** (String) - Required - your API key of type Client Token - **env** (String) - Required - the environment name that will be sent with each event. This can be used to filter your events on different environments (e.g.: "staging" vs. "production"). - **variant** (String) - Optional - the variant of your application, which should be the value from your `BuildConfig.FLAVOR` constant if you have different flavors, empty string otherwise. (default: NO_VARIANT) - **service** (String?) - Optional - the service name (if set to null, it'll be set to your application's package name, e.g.: com.example.android) ``` -------------------------------- ### Initialize Fresco with Datadog Integration Source: https://github.com/datadog/dd-sdk-android/blob/develop/integrations/dd-sdk-android-fresco/README.md Configure Fresco to use Datadog's OkHttp integration and cache listener. This setup automatically tracks network requests and disk cache errors. ```kotlin val config = OkHttpImagePipelineConfigFactory.newBuilder(context, okHttpClient) .setMainDiskCacheConfig( DiskCacheConfig.newBuilder(context) .setCacheEventListener(DatadogFrescoCacheListener()) .build() ) .build() Fresco.initialize(context, config) ``` -------------------------------- ### Configure OkHttp with DatadogInterceptor Source: https://github.com/datadog/dd-sdk-android/blob/develop/integrations/dd-sdk-android-coil3/README.md Create an OkHttpClient instance and add the DatadogInterceptor to automatically track network requests. This is part of the Coil 3 setup. ```kotlin val okHttpClient = OkHttpClient.Builder() .addInterceptor(DatadogInterceptor.Builder(tracedHosts).build()) .build() ``` -------------------------------- ### Sample App Configuration with Custom Endpoints Source: https://github.com/datadog/dd-sdk-android/blob/develop/sample/README.md Configure custom endpoints for logs, traces, and RUM if you need to target a site not included in the default DatadogSite enum. Replace example URLs with your staging environment endpoints. ```json { "logsEndpoint": "http://api.example.com/logs", "tracesEndpoint": "http://api.example.com/spans", "rumEndpoint": "http://api.example.com/rum" } ``` -------------------------------- ### Initialize Datadog SDK Source: https://github.com/datadog/dd-sdk-android/blob/develop/dd-sdk-android-core/README.md Set up the Datadog SDK with your application context, API token, environment, site, and variant. Ensure you use a Client Token for your API key. ```kotlin class SampleApplication : Application() { override fun onCreate() { super.onCreate() val configuration = Configuration.Builder( clientToken = CLIENT_TOKEN, env = ENV_NAME, variant = APP_VARIANT_NAME ) .useSite(DatadogSite.US1) // replace with the site you're targeting (e.g.: US3, EU1, …) .build() Datadog.initialize(this, configuration, trackingConsent) } } ``` -------------------------------- ### GET Method Source: https://github.com/datadog/dd-sdk-android/wiki/RumResourceMethod Represents the GET HTTP method for resource calls. ```APIDOC ## GET /api/resource/{id} ### Description This endpoint retrieves a specific resource using its ID. ### Method GET ### Endpoint /api/resource/{id} ### Parameters #### Path Parameters - **id** (String) - Required - The unique identifier of the resource. ### Response #### Success Response (200) - **name** (String) - The name of the resource. - **ordinal** (Int) - The ordinal value of the resource. #### Response Example ```json { "name": "example_resource", "ordinal": 1 } ``` ``` -------------------------------- ### RumMonitor.stopResource Source: https://github.com/datadog/dd-sdk-android/wiki/RumMonitor Stops a previously started Resource, linked with the key instance. ```APIDOC ## stopResource ### Description Stops a previously started Resource, linked with the key instance. ### Method abstract fun stopResource ### Endpoint RumMonitor#stopResource ### Parameters #### Path Parameters - **key** (String) - Required - the instance that represents the active view (usually your request or network call instance). - **statusCode** (Int?) - Optional - the status code of the resource (if any) - **size** (Long?) - Optional - the size of the resource, in bytes - **kind** (RumResourceKind) - Required - the type of resource loaded - **attributes** (Map) - Required - additional custom attributes to attach to the resource. Attributes can be nested up to 9 levels deep. Keys using more than 9 levels will be sanitized by SDK. ### See also - [RumMonitor.startResource] - [RumMonitor.stopResourceWithError] ``` -------------------------------- ### RumSessionListener Interface Source: https://github.com/datadog/dd-sdk-android/wiki/RumSessionListener This interface provides a callback for session start events. ```APIDOC ## Interface RumSessionListener An interface to get informed whenever a new session is starting, providing you with Datadog's session id. ### Functions #### onSessionStarted abstract fun onSessionStarted(sessionId: String, isDiscarded: Boolean) Called whenever a new session is started. ###### Parameters | | | |---|---| | sessionId | the Session's id (matching the `session.id` attribute in Datadog's RUM events) | | isDiscarded | whether or not the session is discarded by the sample rate (when `true` it means no event in this session will be kept). | ``` -------------------------------- ### Initialize Secondary SDK Instance and Enable Products Source: https://github.com/datadog/dd-sdk-android/blob/develop/MIGRATION.MD Initialize a named SDK instance and enable various products like Logs, Traces, RUM, and crash reporting using this instance. The SDK instance name must remain consistent across application runs for storage path association. ```kotlin val namedSdkInstance = Datadog.initialize("myInstance", context, configuration, trackingConsent) val userInfo = UserInfo(...) Datadog.setUserInfo(userInfo, sdkCore = namedSdkInstance) Logs.enable(logsConfig, namedSdkInstance) val logger = Logger.Builder(namedSdkInstance) ... .build() Trace.enable(traceConfig, namedSdkInstance) val tracer = AndroidTracer.Builder(namedSdkInstance) ... .build() Rum.enable(rumConfig, namedSdkInstance) GlobalRumMonitor.get(namedSdkInstance) NdkCrashReports.enable(namedSdkInstance) WebViewTracking.enable(webView, allowedHosts, namedSdkInstance) ``` -------------------------------- ### Build Sample App Flavor Source: https://github.com/datadog/dd-sdk-android/blob/develop/AGENTS.md Build a specific flavor of the sample application. Requires specifying the module path and flavor name, such as 'us1'. ```bash ./gradlew :sample:kotlin:assembleUs1Debug ``` -------------------------------- ### Action Tracking API Source: https://github.com/datadog/dd-sdk-android/wiki/RumMonitor Methods for starting and stopping the tracking of user actions. ```APIDOC ## POST /api/v1/rum/actions ### Description Notifies that an action stopped, and updates the action's type and name. This is used to stop tracking long running actions (e.g., scroll), started with [startAction](RumMonitor#startAction). ### Method POST ### Endpoint /api/v1/rum/actions ### Parameters #### Request Body - **type** (RumActionType) - Required - The type of the action (e.g., CLICK, SWIPE, CUSTOM). - **name** (String) - Required - The name of the action. - **attributes** (Map) - Optional - Additional custom attributes to attach to the action. ### Request Example ```json { "type": "CLICK", "name": "Login Button", "attributes": { "element_id": "login_btn" } } ``` ### Response #### Success Response (200) This endpoint typically returns a 200 OK status upon successful registration of the action stop. #### Response Example ```json { "status": "OK" } ``` ``` -------------------------------- ### View Tracking API Source: https://github.com/datadog/dd-sdk-android/wiki/RumMonitor Methods for starting and stopping the tracking of application views. ```APIDOC ## POST /api/v1/rum/views ### Description Notifies that a View is being shown to the user, linked with the key instance. This is used to start tracking a new view or screen in the application. ### Method POST ### Endpoint /api/v1/rum/views ### Parameters #### Request Body - **key** (Any) - Required - The instance that represents the active view (e.g., Activity or Fragment instance). - **name** (String) - Required - The name of the view (e.g., Activity or Fragment full class name). - **attributes** (Map) - Optional - Additional custom attributes to attach to the view. Attributes can be nested up to 9 levels deep. ### Request Example ```json { "key": "com.example.MainActivity", "name": "MainActivity", "attributes": { "screen_type": "activity" } } ``` ### Response #### Success Response (200) This endpoint typically returns a 200 OK status upon successful registration of the view start. #### Response Example ```json { "status": "OK" } ``` ``` -------------------------------- ### Enable Trace Product Source: https://github.com/datadog/dd-sdk-android/blob/develop/MIGRATION.MD Configure and enable the Trace product using `TraceConfiguration.Builder` and `Trace.enable`. An `AndroidTracer.Builder` is also shown for setting up the tracer, which should be registered with `GlobalTracer`. ```kotlin val traceConfig = TraceConfiguration.Builder() ... .build() Trace.enable(traceConfig) val tracer = AndroidTracer.Builder() ... .build() GlobalTracer.registerIfAbsent(tracer) ``` -------------------------------- ### Resource Tracking API Source: https://github.com/datadog/dd-sdk-android/wiki/RumMonitor Methods for starting and stopping the tracking of network resources. ```APIDOC ## POST /api/v1/rum/resources ### Description Notifies that a new Resource is being loaded, linked with the key instance. This method is used to start tracking a network request or resource load. ### Method POST ### Endpoint /api/v1/rum/resources ### Parameters #### Request Body - **key** (String) - Required - The unique identifier for the resource being loaded. - **method** (RumResourceMethod) - Required - The HTTP method used for the resource request (e.g., GET, POST). - **url** (String) - Required - The URL or local path of the resource being loaded. - **attributes** (Map) - Optional - Additional custom attributes to attach to the resource. Attributes can be nested up to 9 levels deep. ### Request Example ```json { "key": "unique_resource_key", "method": "GET", "url": "https://example.com/data.json", "attributes": { "custom_field": "custom_value" } } ``` ### Response #### Success Response (200) This endpoint typically returns a 200 OK status upon successful registration of the resource start. #### Response Example ```json { "status": "OK" } ``` ``` ```APIDOC ## POST /api/v1/rum/resources/deprecated ### Description Deprecated method for notifying that a new Resource is being loaded. Use the `startResource` method which takes `RumHttpMethod` as `method` parameter instead. ### Method POST ### Endpoint /api/v1/rum/resources/deprecated ### Parameters #### Request Body - **key** (String) - Required - The unique identifier for the resource being loaded. - **method** (String) - Required - The HTTP method used for the resource request (e.g., "GET" or "POST"). - **url** (String) - Required - The URL or local path of the resource being loaded. - **attributes** (Map) - Optional - Additional custom attributes to attach to the resource. ### Request Example ```json { "key": "deprecated_resource_key", "method": "GET", "url": "https://example.com/deprecated_data.json", "attributes": {} } ``` ### Response #### Success Response (200) This endpoint typically returns a 200 OK status upon successful registration of the resource start. #### Response Example ```json { "status": "OK" } ``` ``` -------------------------------- ### Enable Logs Product Source: https://github.com/datadog/dd-sdk-android/blob/develop/MIGRATION.MD Configure and enable the Logs product using `LogsConfiguration.Builder` and `Logs.enable`. A `Logger.Builder` is also shown for setting up individual loggers. ```kotlin val logsConfig = LogsConfiguration.Builder() ... .build() Logs.enable(logsConfig) val logger = Logger.Builder() ... .build() ``` -------------------------------- ### AdvancedNetworkRumMonitor - stopResource Source: https://github.com/datadog/dd-sdk-android/wiki/AdvancedNetworkRumMonitor Stops a previously started Resource, linked with the provided key. ```APIDOC ## POST /api/v1/rum/resources/stop ### Description Stops a previously started Resource, linked with the key instance. ### Method POST ### Endpoint /api/v1/rum/resources/stop ### Parameters #### Query Parameters - **key** (ResourceId) - Required - The instance that represents the active view (usually your request or network call instance). - **statusCode** (Int?) - Optional - The status code of the resource (if any). - **size** (Long?) - Optional - The size of the resource, in bytes. - **kind** (RumResourceKind) - Required - The type of resource loaded. - **attributes** (Map) - Optional - Additional custom attributes to attach to the resource. Attributes can be nested up to 9 levels deep. Keys using more than 9 levels will be sanitized by SDK. ### Request Example ```json { "key": "some-resource-id", "statusCode": 200, "size": 1024, "kind": "xhr", "attributes": { "processed": true } } ``` ### Response #### Success Response (200) - **status** (String) - Indicates the success of the operation. #### Response Example ```json { "status": "OK" } ``` ### See Also - [AdvancedNetworkRumMonitor.startResource] - [AdvancedNetworkRumMonitor.stopResourceWithError] ``` -------------------------------- ### FragmentViewTrackingStrategy Constructor Source: https://github.com/datadog/dd-sdk-android/wiki/FragmentViewTrackingStrategy Initializes a new instance of the FragmentViewTrackingStrategy class. ```APIDOC ## FragmentViewTrackingStrategy Constructor ### Description Creates an instance of the FragmentViewTrackingStrategy. ### Method constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ### Constructor Parameters - **trackArguments** (Boolean) - Whether to track Fragment arguments. - **supportFragmentComponentPredicate** (ComponentPredicate) - Predicate to accept AndroidX Fragments as valid RUM View events. Defaults to `AcceptAllSupportFragments()`. - **defaultFragmentComponentPredicate** (ComponentPredicate) - Predicate to accept default Android Fragments as valid RUM View events. Defaults to `AcceptAllDefaultFragment()`. ``` -------------------------------- ### Initialize Datadog SDK and Enable Feature Flags Source: https://github.com/datadog/dd-sdk-android/blob/develop/features/dd-sdk-android-flags-openfeature/README.md Initialize the core Datadog SDK with your client token, environment, and variant. Then, enable the Feature Flags feature with optional configuration. ```kotlin // Initialize the core Datadog SDK val coreConfiguration = Configuration.Builder( clientToken = "", env = "", variant = "" ).build() Datadog.initialize(this, coreConfiguration, trackingConsent) // Enable the Feature Flags feature val flagsConfig = FlagsConfiguration.Builder().build() Flags.enable(flagsConfig) ``` -------------------------------- ### RumMonitor.stopResourceWithError Source: https://github.com/datadog/dd-sdk-android/wiki/RumMonitor Stops a previously started Resource that failed loading, linked with the key instance. ```APIDOC ## stopResourceWithError (with Throwable) ### Description Stops a previously started Resource that failed loading, linked with the key instance. ### Method abstract fun stopResourceWithError ### Endpoint RumMonitor#stopResourceWithError ### Parameters #### Path Parameters - **key** (String) - Required - the instance that represents the active view (usually your request or network call instance). - **statusCode** (Int?) - Optional - the status code of the resource (if any) - **message** (String) - Required - a message explaining the error - **source** (RumErrorSource) - Required - the source of the error - **throwable** (Throwable) - Required - the throwable - **attributes** (Map) - Required - additional custom attributes to attach to the error. Attributes can be nested up to 9 levels deep. Keys using more than 9 levels will be sanitized by SDK. Users that want to supply a custom fingerprint for this error can add a value under the key [RumAttributes.ERROR_FINGERPRINT] ### See also - [RumMonitor.startResource] - [RumMonitor.stopResource] ``` ```APIDOC ## stopResourceWithError (with Stacktrace) ### Description Stops a previously started Resource that failed loading, linked with the key instance by providing the intercepted stacktrace. Note: This method should only be used from hybrid application. ### Method abstract fun stopResourceWithError ### Endpoint RumMonitor#stopResourceWithError ### Parameters #### Path Parameters - **key** (String) - Required - the instance that represents the active view (usually your request or network call instance). - **statusCode** (Int?) - Optional - the status code of the resource (if any) - **message** (String) - Required - a message explaining the error - **source** (RumErrorSource) - Required - the source of the error - **stackTrace** (String) - Required - the intercepted stacktrace - **errorType** (String?) - Optional - the type of the error - **attributes** (Map) - Required - additional custom attributes to attach to the error. Attributes can be nested up to 9 levels deep. Keys using more than 9 levels will be sanitized by SDK. ### See also - [RumMonitor.startResource] - [RumMonitor.stopResource] ``` -------------------------------- ### GlobalRumMonitor API Source: https://github.com/datadog/dd-sdk-android/wiki/GlobalRumMonitor Provides methods to get and check the registration status of the global RumMonitor instance. ```APIDOC ## GlobalRumMonitor A global RumMonitor holder, ensuring that all RUM events are registered on the same instance. If the RUM feature is not enabled, a default no-op implementation is used. You can then retrieve the active RumMonitor using the [get](GlobalRumMonitor#get) method. ### get Returns the constant RumMonitor instance. Until a RUM feature is enabled, a no-op implementation is returned. #### Method GET (conceptual, as this is a static method call) #### Endpoint N/A (static method) #### Parameters ##### Query Parameters - **sdkCore** (SdkCore) - Optional - The SdkCore instance to use. If not provided, the default instance will be used. #### Return The monitor associated with the instance given instance, or a no-op monitor. If SDK instance is not provided, default instance will be used. ### isRegistered Identify whether a RumMonitor has previously been registered for the given SDK instance. This check is useful in scenarios where more than one component may be responsible for registering a monitor. #### Method GET (conceptual, as this is a static method call) #### Endpoint N/A (static method) #### Parameters ##### Query Parameters - **sdkCore** (SdkCore) - Optional - The SdkCore instance to check against. If not provided, default instance will be checked. #### Return whether a monitor has been registered ([Boolean]) ``` -------------------------------- ### Local Benchmark Configuration Source: https://github.com/datadog/dd-sdk-android/blob/develop/sample/benchmark/README.md Create this `benchmark.json` file in the `config/` folder to run the application locally. Ensure you replace placeholder values with your actual tokens and IDs. ```json { "token": "MY_CLIENT_TOKEN", "rumApplicationId": "MY_RUM_APPLICATION_ID", "apiKey": "MY_API_KEY", "applicationKey": "MY_APPLICATION_KEY" } ``` -------------------------------- ### AdvancedNetworkRumMonitor - stopResourceWithError Source: https://github.com/datadog/dd-sdk-android/wiki/AdvancedNetworkRumMonitor Stops a previously started Resource that failed loading, linked with the provided key. ```APIDOC ## POST /api/v1/rum/resources/error ### Description Stops a previously started Resource that failed loading, linked with the key instance. ### Method POST ### Endpoint /api/v1/rum/resources/error ### Parameters #### Query Parameters - **key** (ResourceId) - Required - The instance that represents the active view (usually your request or network call instance). - **statusCode** (Int?) - Optional - The status code of the resource (if any). - **message** (String) - Required - A message explaining the error. - **source** (RumErrorSource) - Required - The source of the error. - **throwable** (Throwable) - Required - The throwable. - **attributes** (Map) - Optional - Additional custom attributes to attach to the error. Attributes can be nested up to 9 levels deep. Keys using more than 9 levels will be sanitized by SDK. Users that want to supply a custom fingerprint for this error can add a value under the key [RumAttributes.ERROR_FINGERPRINT]. ### Request Example ```json { "key": "some-resource-id", "statusCode": 500, "message": "Internal Server Error", "source": "network", "throwable": "java.lang.Exception: Something went wrong", "attributes": { "RumAttributes.ERROR_FINGERPRINT": "custom-fingerprint" } } ``` ### Response #### Success Response (200) - **status** (String) - Indicates the success of the operation. #### Response Example ```json { "status": "OK" } ``` ### See Also - [AdvancedNetworkRumMonitor.startResource] - [AdvancedNetworkRumMonitor.stopResource] ``` -------------------------------- ### Set up C++ 17 Compiler and Add Subdirectories Source: https://github.com/datadog/dd-sdk-android/blob/develop/features/dd-sdk-android-ndk/CMakeLists.txt Configures the C++ standard to 17 and adds the main source and test directories. Testing is enabled only for Debug builds. ```cmake cmake_minimum_required(VERSION 3.22.1) project("dd-sdk-android-ndk") # use the C++ 17 compiler set(CMAKE_CXX_STANDARD 17) add_subdirectory(src/main/cpp) if(${CMAKE_BUILD_TYPE} STREQUAL Debug) enable_testing() add_subdirectory(src/test/cpp) endif() ``` -------------------------------- ### Set up ImageLoader with OkHttpNetworkFetcherFactory Source: https://github.com/datadog/dd-sdk-android/blob/develop/integrations/dd-sdk-android-coil3/README.md Build an ImageLoader using Coil 3, providing the OkHttpClient configured with DatadogInterceptor via OkHttpNetworkFetcherFactory. This ensures network requests are monitored. ```kotlin val imageLoader = ImageLoader.Builder(context) .components { add(OkHttpNetworkFetcherFactory(okHttpClient)) } .build() SingletonImageLoader.setSafe { imageLoader } ``` -------------------------------- ### Initialize the core Datadog SDK Source: https://github.com/datadog/dd-sdk-android/blob/develop/features/dd-sdk-android-flags/README.md Before enabling Feature Flags, initialize the core Datadog SDK with your client token, environment, and application variant. ```kotlin // Initialize the core Datadog SDK first val coreConfiguration = Configuration.Builder( clientToken = "", env = "", variant = "" ) .build() Datadog.initialize(this, coreConfiguration, trackingConsent) ``` -------------------------------- ### stopView Source: https://github.com/datadog/dd-sdk-android/wiki/RumMonitor Stops a previously started View associated with the provided key. Optional attributes can be attached to the view. ```APIDOC ## stopView ### Description Stops a previously started View, linked with the [key] instance. Optional attributes can be attached to the view. ### Method `abstract fun` ### Endpoint `RumMonitor.stopView(key: Any, attributes: Map? = emptyMap()) ### Parameters #### Path Parameters - **key** (Any) - Required - the instance that represents the active view (usually your [Activity] or [Fragment] instance). - **attributes** (Map) - Optional - additional custom attributes to attach to the view. Attributes can be nested up to 9 levels deep. Keys using more than 9 levels will be sanitized by SDK. ### See also - [RumMonitor.startView] ``` -------------------------------- ### Create and Configure OpenFeature Provider Source: https://github.com/datadog/dd-sdk-android/blob/develop/features/dd-sdk-android-flags-openfeature/README.md Create a FlagsClient and convert it to an OpenFeature provider using the `asOpenFeatureProvider()` extension function. Then, set this provider as the default for the OpenFeature API. ```kotlin import com.datadog.android.flags.FlagsClient import com.datadog.android.flags.openfeature.asOpenFeatureProvider import dev.openfeature.kotlin.sdk.OpenFeatureAPI // Create a FlagsClient and convert to OpenFeature provider val provider = FlagsClient.Builder().build().asOpenFeatureProvider() // Set it as the OpenFeature provider OpenFeatureAPI.setProviderAndWait(provider) ``` -------------------------------- ### Sample App Configuration with Remote API Keys Source: https://github.com/datadog/dd-sdk-android/blob/develop/sample/README.md Add these attributes to your configuration file to enable the download of logs for testing the 'Data List' screen. Obtain 'apiKey' and 'applicationKey' from your Datadog Organization Settings. ```json { "apiKey": "YOUR API ID", "applicationKey": "YOUR APPLICATION KEY" } ``` -------------------------------- ### addTiming Source: https://github.com/datadog/dd-sdk-android/wiki/RumMonitor Adds a specific timing to the active view. The duration is calculated as the difference between the view's start time and the time this function is called. ```APIDOC ## addTiming ### Description Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called. ### Method abstract fun ### Endpoint RumMonitor#addTiming ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (String) - Required - the name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK. ### Request Example ```json { "name": "custom_timing_name" } ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Datadog SDK Initialization Source: https://github.com/datadog/dd-sdk-android/wiki/Datadog Methods for initializing the Datadog SDK, with options for named instances or the default instance. ```APIDOC ## POST /api/initialize ### Description Initializes a named instance of the Datadog SDK or the default instance. ### Method POST ### Endpoint /api/initialize ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **instanceName** (String) - Optional - The name of the instance (or null to initialize the default instance). Note that the instance name should be stable across builds. - **context** (Context) - Required - Your application context. - **configuration** (Configuration) - Required - The configuration for the SDK library. - **trackingConsent** (TrackingConsent) - Required - The initial state of the tracking consent flag. ### Request Example ```json { "instanceName": "my_app_instance", "context": "", "configuration": { "clientToken": "", "env": "" }, "trackingConsent": "GRANTED" } ``` ### Response #### Success Response (200) - **sdkCore** (SdkCore) - The initialized SDK instance, or null if something prevents the SDK from being initialized. #### Response Example ```json { "sdkCore": "" } ``` ### Throws - **IllegalArgumentException** - If the env name is using illegal characters and your application is in debug mode, otherwise returns null and stops initializing the SDK. ``` ```APIDOC ## POST /api/initialize ### Description Initializes the Datadog SDK without a specific instance name (uses the default instance). ### Method POST ### Endpoint /api/initialize ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **context** (Context) - Required - Your application context. - **configuration** (Configuration) - Required - The configuration for the SDK library. - **trackingConsent** (TrackingConsent) - Required - The initial state of the tracking consent flag. ### Request Example ```json { "context": "", "configuration": { "clientToken": "", "env": "" }, "trackingConsent": "GRANTED" } ``` ### Response #### Success Response (200) - **sdkCore** (SdkCore) - The initialized SDK instance, or null if something prevents the SDK from being initialized. #### Response Example ```json { "sdkCore": "" } ``` ### Throws - **IllegalArgumentException** - If the env name is using illegal characters and your application is in debug mode, otherwise returns null and stops initializing the SDK. ``` -------------------------------- ### ActivityViewTrackingStrategy Constructor Source: https://github.com/datadog/dd-sdk-android/wiki/ActivityViewTrackingStrategy Initializes a new instance of the ActivityViewTrackingStrategy class. This strategy monitors the lifecycle of Android Activities to start and stop RUM Views. ```APIDOC ## ActivityViewTrackingStrategy Constructor ### Description Initializes a new instance of the ActivityViewTrackingStrategy class. This strategy monitors the lifecycle of Android Activities to start and stop RUM Views. ### Method constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response None ## Constructors ### ActivityViewTrackingStrategy > @[JvmOverloads](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-overloads/index.html) constructor(trackExtras: [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html), componentPredicate: ComponentPredicate<[Activity](https://developer.android.com/reference/kotlin/android/app/Activity.html)> = AcceptAllActivities()) ###### Parameters | | | |---|---| | trackExtras | whether to track the Activity's Intent information (extra attributes, action, data URI) | | componentPredicate | to accept the Activities that will be taken into account as valid RUM View events. | ``` -------------------------------- ### Initialize and Manage Multiple SDK Instances Source: https://context7.com/datadog/dd-sdk-android/llms.txt Use this snippet to initialize, configure, and manage separate Datadog SDK instances for different tenants or applications. Ensure `applicationContext` is available. ```kotlin import com.datadog.android.Datadog import com.datadog.android.rum.GlobalRumMonitor import com.datadog.android.rum.Rum // Initialize named SDK instance val tenantConfig = Configuration.Builder( clientToken = "pub-tenant-token", env = "production" ).build() val tenantSdk = Datadog.initialize( instanceName = "tenant-a", context = applicationContext, configuration = tenantConfig, trackingConsent = TrackingConsent.GRANTED ) // Enable features for specific instance val rumConfig = RumConfiguration.Builder("tenant-a-app-id").build() Rum.enable(rumConfig, tenantSdk!!) // Get monitors for specific instance val tenantRumMonitor = GlobalRumMonitor.get(tenantSdk) tenantRumMonitor.startView(this, "TenantDashboard") // Check if instance is initialized if (Datadog.isInitialized("tenant-a")) { val sdk = Datadog.getInstance("tenant-a") // Use sdk... } // Stop specific instance Datadog.stopInstance("tenant-a") ``` -------------------------------- ### startAction Source: https://github.com/datadog/dd-sdk-android/wiki/RumMonitor Notifies that an action has started. This is used for tracking long-running actions. The action must be stopped using stopAction or will be stopped automatically after 10 seconds. ```APIDOC ## startAction ### Description Notifies that an action started. This is used to track long running actions (e.g.: scroll). Such an action must be stopped with stopAction, and will be stopped automatically if it lasts more than 10 seconds. ### Method abstract fun ### Endpoint RumMonitor#startAction ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **type** (RumActionType) - Required - the action type - **name** (String) - Required - the action identifier - **attributes** (Map) - Optional - additional custom attributes to attach to the action. Attributes can be nested up to 9 levels deep. Keys using more than 9 levels will be sanitized by SDK. ### Request Example ```json { "type": "CLICK", "name": "Login Button", "attributes": { "custom_attribute": "example_value" } } ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### stopResourceWithError Source: https://github.com/datadog/dd-sdk-android/wiki/AdvancedNetworkRumMonitor Stops a previously started Resource that failed loading, linked with the key instance by providing the intercepted stacktrace. This method should only be used from hybrid applications. ```APIDOC ## stopResourceWithError ### Description Stops a previously started Resource that failed loading, linked with the key instance by providing the intercepted stacktrace. Note: This method should only be used from hybrid application. ### Method abstract fun ### Endpoint stopResourceWithError ### Parameters #### Path Parameters - **key** (ResourceId) - Required - the instance that represents the active view (usually your request or network call instance). - **statusCode** (Int?) - Optional - the status code of the resource (if any) - **message** (String) - Required - a message explaining the error - **source** (RumErrorSource) - Required - the source of the error - **stackTrace** (String) - Required - the error stacktrace - **errorType** (String?) - Optional - the type of the error. Usually it should be the canonical name of the of the Exception class. - **attributes** (Map?) - Optional - additional custom attributes to attach to the error. Attributes can be nested up to 9 levels deep. Keys using more than 9 levels will be sanitized by SDK. Users that want to supply a custom fingerprint for this error can add a value under the key RumAttributes.ERROR_FINGERPRINT ### Request Example ```json { "key": "some-resource-id", "statusCode": 500, "message": "Internal Server Error", "source": "NETWORK", "stackTrace": "com.example.MyException: Something went wrong\n\tat com.example.MyClass.myMethod(MyClass.java:10)", "errorType": "com.example.MyException", "attributes": { "custom_attribute": "value", "nested": { "level1": "data" } } } ``` ### Response #### Success Response (200) - **None** - This method does not return a value. #### Response Example ```json // No response body for this operation ``` ``` -------------------------------- ### _InternalWebViewProxy Constructor Source: https://github.com/datadog/dd-sdk-android/wiki/WebViewTracking._InternalWebViewProxy Initializes the internal WebView proxy with an SDK core instance and an optional WebView ID. ```APIDOC ## _InternalWebViewProxy Constructor ### Description Initializes the internal WebView proxy. ### Method constructor ### Parameters #### Path Parameters - **sdkCore** (SdkCore) - Required - The SDK core instance. - **webViewId** (String?) - Optional - The ID of the WebView. ### Request Example ```json { "sdkCore": "SdkCoreInstance", "webViewId": "optionalWebViewId" } ``` ### Response #### Success Response (200) - **_InternalWebViewProxy** (object) - The initialized WebView proxy instance. ### Response Example ```json { "_InternalWebViewProxy": "initializedInstance" } ``` ``` -------------------------------- ### Track Swipe and Scroll Events with TrackInteractionsEffect Source: https://github.com/datadog/dd-sdk-android/blob/develop/integrations/dd-sdk-android-compose/README.md Use the TrackInteractionsEffect with a Modifier.swipeable to report swipe and scroll events. This example demonstrates tracking swipe interactions on a Box composable. ```kotlin val swipeableState = rememberSwipeableState(...) val swipeOrientation = Orientation.Horizontal val interactionSource = remember { MutableInteractionSource( ).apply { TrackInteractionEffect( targetName = "Item row", interactionSource = this, interactionType = InteractionType.Swipe( swipeableState, orientation = swipeOrientation ), attributes = mapOf("foo" to "bar") ) } } Box( modifier = Modifier .swipeable( interactionSource = interactionSource, state = swipeableState, orientation = swipeOrientation, ... ) .offset { IntOffset(swipeableState.offset.value.roundToInt(), 0) } ) { ... } ``` -------------------------------- ### Enable RUM Product Source: https://github.com/datadog/dd-sdk-android/blob/develop/MIGRATION.MD Enable the RUM product by building a RumConfiguration and calling Rum.enable(). Ensure you have the necessary RUM Application ID. ```kotlin val rumConfig = RumConfiguration.Builder(rumApplicationId) ... .build() Rum.enable(rumConfig) ``` -------------------------------- ### Kotlin Class Method Folding Regions Example Source: https://github.com/datadog/dd-sdk-android/blob/develop/CONTRIBUTING.md Demonstrates how to group class methods into folding regions named after the declaring class, with private methods grouped under 'Internal'. ```kotlin class Foo : Observable(), Runnable { // region Foo fun fooSpecificMethod(){} // endregion // region Observable override fun addObserver(o: Observer?) { super.addObserver(o) doSomething() } // endregion // region Runnable override fun run() {} // endregion // region Internal private fun doSomething() {} // endregion } ``` -------------------------------- ### Configure ActivityViewTrackingStrategy to Exclude Compose Activities Source: https://github.com/datadog/dd-sdk-android/blob/develop/integrations/dd-sdk-android-compose/README.md When using ActivityViewTrackingStrategy, reject Activities or Fragments that host Compose views to prevent them from being counted as separate views. This example excludes MyComposeActivity. ```kotlin val configuration = RumConfiguration.Builder(applicationId = applicationId) .useViewTrackingStrategy( ActivityViewTrackingStrategy( trackExtras = ..., componentPredicate = object : ComponentPredicate { override fun accept(component: Activity): Boolean { return component !is MyComposeActivity } override fun getViewName(component: Activity): String? = null }) ) ... .build() ``` -------------------------------- ### Enable WebView Tracking Source: https://github.com/datadog/dd-sdk-android/blob/develop/MIGRATION.MD Enable WebView Tracking by calling WebViewTracking.enable() with the WebView instance and a list of allowed hosts. ```kotlin WebViewTracking.enable(webView, allowedHosts) ``` -------------------------------- ### AdvancedNetworkRumMonitor - startResource Source: https://github.com/datadog/dd-sdk-android/wiki/AdvancedNetworkRumMonitor Notifies that a new Resource is being loaded, linked with the provided key. ```APIDOC ## POST /api/v1/rum/resources/start ### Description Notify that a new Resource is being loaded, linked with the key instance. ### Method POST ### Endpoint /api/v1/rum/resources/start ### Parameters #### Query Parameters - **key** (ResourceId) - Required - The instance that represents the resource being loaded (usually your request or network call instance). - **method** (RumResourceMethod) - Required - The method used to load the resource (E.g., for network: "GET" or "POST"). - **url** (String) - Required - The url or local path of the resource being loaded. - **attributes** (Map) - Optional - Additional custom attributes to attach to the resource. Attributes can be nested up to 9 levels deep. Keys using more than 9 levels will be sanitized by SDK. ### Request Example ```json { "key": "some-resource-id", "method": "GET", "url": "https://example.com/data", "attributes": { "custom_attribute": "value" } } ``` ### Response #### Success Response (200) - **status** (String) - Indicates the success of the operation. #### Response Example ```json { "status": "OK" } ``` ### See Also - [AdvancedNetworkRumMonitor.stopResource] - [AdvancedNetworkRumMonitor.stopResourceWithError] ``` -------------------------------- ### Add DatadogApolloInterceptor to Apollo Client Source: https://github.com/datadog/dd-sdk-android/blob/develop/integrations/dd-sdk-android-apollo/README.md Add the DatadogApolloInterceptor to your Apollo Client setup to automatically include Datadog headers in GraphQL requests. This allows Datadog to track 'query' and 'mutation' operations. ```kotlin val apolloClient = ApolloClient.Builder() .serverUrl([graphQLEndpoint]) .addInterceptor(DatadogApolloInterceptor()) .okHttpClient([okhttpClientConfiguration]) .build() ``` -------------------------------- ### Create DatadogMeter Source: https://github.com/datadog/dd-sdk-android/blob/develop/tools/benchmark/README.md Instantiate the DatadogMeter using the previously built configuration. This meter is used to manage and start/stop gauges. ```kotlin val meter = DatadogMeter.create(configuration) ``` -------------------------------- ### Initialize DatadogTree with Logger Source: https://github.com/datadog/dd-sdk-android/blob/develop/integrations/dd-sdk-android-timber/README.md Configure and build a logger instance, then add DatadogTree to Timber. This ensures all Timber logs are automatically sent to Datadog. Network info, logcat logs, remote sampling, and trace bundling can be configured. ```kotlin val logger = Logger.Builder() .setNetworkInfoEnabled(true) .setLogcatLogsEnabled(true) .setRemoteSampleRate(100f) .setBundleWithTraceEnabled(true) .setName("") .build() Timber.plant(Timber.DebugTree(), DatadogTree(logger)) ``` -------------------------------- ### Enable and Configure Session Replay Source: https://context7.com/datadog/dd-sdk-android/llms.txt Enable the Session Replay feature with customizable privacy settings and recording behavior. Control image, touch, and text input privacy, and manage when recording starts. ```kotlin import com.datadog.android.sessionreplay.ImagePrivacy import com.datadog.android.sessionreplay.SessionReplay import com.datadog.android.sessionreplay.SessionReplayConfiguration import com.datadog.android.sessionreplay.TextAndInputPrivacy import com.datadog.android.sessionreplay.TouchPrivacy val sessionReplayConfig = SessionReplayConfiguration.Builder(sampleRate = 100f) // Configure privacy levels .setImagePrivacy(ImagePrivacy.MASK_LARGE_ONLY) .setTouchPrivacy(TouchPrivacy.SHOW) .setTextAndInputPrivacy(TextAndInputPrivacy.MASK_SENSITIVE_INPUTS) // Control recording start .startRecordingImmediately(true) // Enable dynamic optimization .setDynamicOptimizationEnabled(true) .build() // Enable Session Replay SessionReplay.enable(sessionReplayConfig) // Manual recording control SessionReplay.startRecording() SessionReplay.stopRecording() ``` -------------------------------- ### NavigationViewTrackingStrategy Constructor Source: https://github.com/datadog/dd-sdk-android/wiki/NavigationViewTrackingStrategy Initializes a new instance of the NavigationViewTrackingStrategy. This strategy tracks Fragments within a NavigationHost as RUM Views. ```APIDOC ## NavigationViewTrackingStrategy Constructor ### Description Initializes a new instance of the NavigationViewTrackingStrategy. This strategy tracks Fragments within a NavigationHost as RUM Views. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Constructor Signature `NavigationViewTrackingStrategy(@IdRes navigationViewId: Int, trackArguments: Boolean, componentPredicate: ComponentPredicate = AcceptAllNavDestinations())` ### Parameters - **navigationViewId** (Int) - Required - The id of the NavHost view within the hosting Activity. - **trackArguments** (Boolean) - Required - Whether to track navigation arguments. - **componentPredicate** (ComponentPredicate) - Optional - The predicate to keep/discard/rename the tracked NavDestinations. Defaults to `AcceptAllNavDestinations()`. ```