Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release 2.2.0 branch into develop #1657

Merged
merged 10 commits into from
Oct 4, 2023
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 2.2.0 / 2023-10-02
# 2.2.0 / 2023-10-04

* [FEATURE] Session Replay: Serialize TextViews/Buttons to base64. See [#1592](https://github.com/DataDog/dd-sdk-android/pull/1592)
* [FEATURE] WebView Tracking: Add sampler to `WebViewLogEventConsumer`. See [#1629](https://github.com/DataDog/dd-sdk-android/pull/1629)
Expand Down Expand Up @@ -32,8 +32,8 @@
* [IMPROVEMENT] Trace: Use `networkInfoEnabled` to serialize or not network info in spans. See [#1637](https://github.com/DataDog/dd-sdk-android/pull/1637)
* [IMPROVEMENT] Telemetry: Add more information into the batch telemetry. See [#1641](https://github.com/DataDog/dd-sdk-android/pull/1641)
* [IMPROVEMENT] Session Replay: Implement heuristic image classification. See [#1640](https://github.com/DataDog/dd-sdk-android/pull/1640)
* [IMPROVEMENT] Session Replay: Implement Base64 for `ImageViews`. See [#1644](https://github.com/DataDog/dd-sdk-android/pull/1644)
* [IMPROVEMENT] Global: `DataUploadWorker` is scheduled every time and on non-roaming network. See [#1647](https://github.com/DataDog/dd-sdk-android/pull/1647)
* [IMPROVEMENT] RUM: Use enum for HTTP method parameter of `RumMonitor#startResource API`. See [#1653](https://github.com/DataDog/dd-sdk-android/pull/1653)
* [MAINTENANCE] Align the Base64 feature branch with develop. See [#1594](https://github.com/DataDog/dd-sdk-android/pull/1594)
* [MAINTENANCE] Integrate latest changes from develop into base64 feature. See [#1599](https://github.com/DataDog/dd-sdk-android/pull/1599)
* [MAINTENANCE] Base64 feature branch integration. See [#1597](https://github.com/DataDog/dd-sdk-android/pull/1597)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@

package com.datadog.android.core.internal.receiver

import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import java.util.concurrent.atomic.AtomicBoolean

internal abstract class ThreadSafeReceiver : BroadcastReceiver() {

val isRegistered = AtomicBoolean(false)

@SuppressLint("UnspecifiedRegisterReceiverFlag")
fun registerReceiver(
context: Context,
filter: IntentFilter
): Intent? {
val intent = context.registerReceiver(this, filter)
val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.registerReceiver(this, filter, Context.RECEIVER_NOT_EXPORTED)
} else {
context.registerReceiver(this, filter)
}
isRegistered.set(true)
return intent
}
Expand Down
1 change: 1 addition & 0 deletions detekt_custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ datadog:
- "android.content.Context.getSystemService(kotlin.String)"
- "android.content.Context.registerComponentCallbacks(android.content.ComponentCallbacks)"
- "android.content.Context.registerReceiver(android.content.BroadcastReceiver?, android.content.IntentFilter)"
- "android.content.Context.registerReceiver(android.content.BroadcastReceiver?, android.content.IntentFilter, kotlin.Int)"
- "android.content.Context.unregisterReceiver(android.content.BroadcastReceiver)"
- "android.content.Intent.getBooleanExtra(kotlin.String, kotlin.Boolean)"
- "android.content.Intent.getIntExtra(kotlin.String, kotlin.Int)"
Expand Down
10 changes: 9 additions & 1 deletion features/dd-sdk-android-rum/api/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ interface com.datadog.android.rum.RumMonitor
fun addAction(RumActionType, String, Map<String, Any?>)
fun startAction(RumActionType, String, Map<String, Any?>)
fun stopAction(RumActionType, String, Map<String, Any?> = emptyMap())
fun startResource(String, String, String, Map<String, Any?> = emptyMap())
DEPRECATED fun startResource(String, String, String, Map<String, Any?> = emptyMap())
fun startResource(String, RumResourceMethod, String, Map<String, Any?> = emptyMap())
fun stopResource(String, Int?, Long?, RumResourceKind, Map<String, Any?>)
fun stopResourceWithError(String, Int?, String, RumErrorSource, Throwable, Map<String, Any?> = emptyMap())
fun stopResourceWithError(String, Int?, String, RumErrorSource, String, String?, Map<String, Any?> = emptyMap())
Expand Down Expand Up @@ -130,6 +131,13 @@ enum com.datadog.android.rum.RumResourceKind
- OTHER
companion object
fun fromMimeType(String): RumResourceKind
enum com.datadog.android.rum.RumResourceMethod
- POST
- GET
- HEAD
- PUT
- DELETE
- PATCH
interface com.datadog.android.rum.RumSessionListener
fun onSessionStarted(String, Boolean)
class com.datadog.android.rum._RumInternalProxy
Expand Down
13 changes: 13 additions & 0 deletions features/dd-sdk-android-rum/api/dd-sdk-android-rum.api
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public abstract interface class com/datadog/android/rum/RumMonitor {
public abstract fun removeAttribute (Ljava/lang/String;)V
public abstract fun setDebug (Z)V
public abstract fun startAction (Lcom/datadog/android/rum/RumActionType;Ljava/lang/String;Ljava/util/Map;)V
public abstract fun startResource (Ljava/lang/String;Lcom/datadog/android/rum/RumResourceMethod;Ljava/lang/String;Ljava/util/Map;)V
public abstract fun startResource (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;)V
public abstract fun startView (Ljava/lang/Object;Ljava/lang/String;Ljava/util/Map;)V
public abstract fun stopAction (Lcom/datadog/android/rum/RumActionType;Ljava/lang/String;Ljava/util/Map;)V
Expand All @@ -155,6 +156,7 @@ public abstract interface class com/datadog/android/rum/RumMonitor {
}

public final class com/datadog/android/rum/RumMonitor$DefaultImpls {
public static synthetic fun startResource$default (Lcom/datadog/android/rum/RumMonitor;Ljava/lang/String;Lcom/datadog/android/rum/RumResourceMethod;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)V
public static synthetic fun startResource$default (Lcom/datadog/android/rum/RumMonitor;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)V
public static synthetic fun startView$default (Lcom/datadog/android/rum/RumMonitor;Ljava/lang/Object;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)V
public static synthetic fun stopAction$default (Lcom/datadog/android/rum/RumMonitor;Lcom/datadog/android/rum/RumActionType;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)V
Expand Down Expand Up @@ -197,6 +199,17 @@ public final class com/datadog/android/rum/RumResourceKind$Companion {
public final fun fromMimeType (Ljava/lang/String;)Lcom/datadog/android/rum/RumResourceKind;
}

public final class com/datadog/android/rum/RumResourceMethod : java/lang/Enum {
public static final field DELETE Lcom/datadog/android/rum/RumResourceMethod;
public static final field GET Lcom/datadog/android/rum/RumResourceMethod;
public static final field HEAD Lcom/datadog/android/rum/RumResourceMethod;
public static final field PATCH Lcom/datadog/android/rum/RumResourceMethod;
public static final field POST Lcom/datadog/android/rum/RumResourceMethod;
public static final field PUT Lcom/datadog/android/rum/RumResourceMethod;
public static fun valueOf (Ljava/lang/String;)Lcom/datadog/android/rum/RumResourceMethod;
public static fun values ()[Lcom/datadog/android/rum/RumResourceMethod;
}

public abstract interface class com/datadog/android/rum/RumSessionListener {
public abstract fun onSessionStarted (Ljava/lang/String;Z)V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,35 @@ interface RumMonitor {
* @see [stopResource]
* @see [stopResourceWithError]
*/
@Deprecated(
"This method is deprecated and will be removed in the future versions." +
" Use `startResource` method which takes `RumHttpMethod` as `method` parameter instead."
)
fun startResource(
key: String,
method: String,
url: String,
attributes: Map<String, Any?> = emptyMap()
)

/**
* Notify that a new Resource is being loaded, linked with the [key] instance.
* @param key the instance that represents the resource being loaded (usually your
* request or network call instance).
* @param method the method used to load the resource (E.g., for network: "GET" or "POST")
* @param url the url or local path of the resource being loaded
* @param attributes 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 [stopResource]
* @see [stopResourceWithError]
*/
fun startResource(
key: String,
method: RumResourceMethod,
url: String,
attributes: Map<String, Any?> = emptyMap()
)

/**
* Stops a previously started Resource, linked with the [key] instance.
* @param key the instance that represents the active view (usually your
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.rum

/**
* Describes the type of a method associated with resource call.
* @see [RumMonitor]
*/
enum class RumResourceMethod {
/**
* POST Method.
*/
POST,

/**
* GET Method.
*/
GET,

/**
* HEAD Method.
*/
HEAD,

/**
* PUT Method.
*/
PUT,

/**
* DELETE Method.
*/
DELETE,

/**
* PATCH Method.
*/
PATCH
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.datadog.android.api.context.NetworkInfo
import com.datadog.android.rum.RumActionType
import com.datadog.android.rum.RumErrorSource
import com.datadog.android.rum.RumResourceKind
import com.datadog.android.rum.RumResourceMethod
import com.datadog.android.rum.internal.RumErrorSourceType
import com.datadog.android.rum.internal.domain.event.ResourceTiming
import com.datadog.android.rum.model.ActionEvent
Expand All @@ -22,31 +23,25 @@ import com.datadog.android.rum.model.ResourceEvent
import com.datadog.android.rum.model.ViewEvent
import java.util.Locale

internal fun String.toMethod(internalLogger: InternalLogger): ResourceEvent.Method {
return try {
ResourceEvent.Method.valueOf(this.uppercase(Locale.US))
} catch (e: IllegalArgumentException) {
internalLogger.log(
InternalLogger.Level.ERROR,
listOf(InternalLogger.Target.MAINTAINER, InternalLogger.Target.TELEMETRY),
{ "Unable to convert [$this] to a valid http method" },
e
)
ResourceEvent.Method.GET
internal fun RumResourceMethod.toResourceMethod(): ResourceEvent.Method {
return when (this) {
RumResourceMethod.GET -> ResourceEvent.Method.GET
RumResourceMethod.POST -> ResourceEvent.Method.POST
RumResourceMethod.HEAD -> ResourceEvent.Method.HEAD
RumResourceMethod.PUT -> ResourceEvent.Method.PUT
RumResourceMethod.DELETE -> ResourceEvent.Method.DELETE
RumResourceMethod.PATCH -> ResourceEvent.Method.PATCH
}
}

internal fun String.toErrorMethod(internalLogger: InternalLogger): ErrorEvent.Method {
return try {
ErrorEvent.Method.valueOf(this.uppercase(Locale.US))
} catch (e: IllegalArgumentException) {
internalLogger.log(
InternalLogger.Level.ERROR,
listOf(InternalLogger.Target.MAINTAINER, InternalLogger.Target.TELEMETRY),
{ "Unable to convert [$this] to a valid http method" },
e
)
ErrorEvent.Method.GET
internal fun RumResourceMethod.toErrorMethod(): ErrorEvent.Method {
return when (this) {
RumResourceMethod.GET -> ErrorEvent.Method.GET
RumResourceMethod.POST -> ErrorEvent.Method.POST
RumResourceMethod.HEAD -> ErrorEvent.Method.HEAD
RumResourceMethod.PUT -> ErrorEvent.Method.PUT
RumResourceMethod.DELETE -> ErrorEvent.Method.DELETE
RumResourceMethod.PATCH -> ErrorEvent.Method.PATCH
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.datadog.android.rum.RumActionType
import com.datadog.android.rum.RumErrorSource
import com.datadog.android.rum.RumPerformanceMetric
import com.datadog.android.rum.RumResourceKind
import com.datadog.android.rum.RumResourceMethod
import com.datadog.android.rum.internal.RumErrorSourceType
import com.datadog.android.rum.internal.domain.Time
import com.datadog.android.rum.internal.domain.event.ResourceTiming
Expand Down Expand Up @@ -51,7 +52,7 @@ internal sealed class RumRawEvent {
internal data class StartResource(
val key: String,
val url: String,
val method: String,
val method: RumResourceMethod,
val attributes: Map<String, Any?>,
override val eventTime: Time = Time()
) : RumRawEvent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.datadog.android.rum.GlobalRumMonitor
import com.datadog.android.rum.RumAttributes
import com.datadog.android.rum.RumErrorSource
import com.datadog.android.rum.RumResourceKind
import com.datadog.android.rum.RumResourceMethod
import com.datadog.android.rum.internal.FeaturesContextResolver
import com.datadog.android.rum.internal.domain.RumContext
import com.datadog.android.rum.internal.domain.Time
Expand All @@ -34,7 +35,7 @@ internal class RumResourceScope(
internal val parentScope: RumScope,
internal val sdkCore: InternalSdkCore,
internal val url: String,
internal val method: String,
internal val method: RumResourceMethod,
internal val key: String,
eventTime: Time,
initialAttributes: Map<String, Any?>,
Expand Down Expand Up @@ -201,7 +202,7 @@ internal class RumResourceScope(
type = kind.toSchemaType(),
url = url,
duration = duration,
method = method.toMethod(sdkCore.internalLogger),
method = method.toResourceMethod(),
statusCode = statusCode,
size = size,
dns = finalTiming?.dns(),
Expand Down Expand Up @@ -323,7 +324,7 @@ internal class RumResourceScope(
isCrash = false,
resource = ErrorEvent.Resource(
url = url,
method = method.toErrorMethod(sdkCore.internalLogger),
method = method.toErrorMethod(),
statusCode = statusCode ?: 0,
provider = resolveErrorProvider()
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.datadog.android.rum.RumErrorSource
import com.datadog.android.rum.RumMonitor
import com.datadog.android.rum.RumPerformanceMetric
import com.datadog.android.rum.RumResourceKind
import com.datadog.android.rum.RumResourceMethod
import com.datadog.android.rum.RumSessionListener
import com.datadog.android.rum._RumInternalProxy
import com.datadog.android.rum.internal.CombinedRumSessionListener
Expand Down Expand Up @@ -161,11 +162,46 @@ internal class DatadogRumMonitor(
)
}

@Deprecated(
"This method is deprecated and will be removed in the future versions." +
" Use `startResource` method which takes `RumHttpMethod` as `method` parameter instead."
)
override fun startResource(
key: String,
method: String,
url: String,
attributes: Map<String, Any?>
) {
// enum value names may be changed if obfuscation is aggressive
val rumResourceMethod = when (method.uppercase(Locale.US)) {
"POST" -> RumResourceMethod.POST
"GET" -> RumResourceMethod.GET
"HEAD" -> RumResourceMethod.HEAD
"PUT" -> RumResourceMethod.PUT
"DELETE" -> RumResourceMethod.DELETE
"PATCH" -> RumResourceMethod.PATCH
else -> {
sdkCore.internalLogger.log(
InternalLogger.Level.WARN,
InternalLogger.Target.USER,
{
"Unsupported HTTP method %s reported, using GET instead".format(
Locale.US,
method
)
}
)
RumResourceMethod.GET
}
}
startResource(key, rumResourceMethod, url, attributes)
}

override fun startResource(
key: String,
method: RumResourceMethod,
url: String,
attributes: Map<String, Any?>
) {
val eventTime = getEventTime(attributes)
handleEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.datadog.android.api.SdkCore
import com.datadog.android.rum.GlobalRumMonitor
import com.datadog.android.rum.RumErrorSource
import com.datadog.android.rum.RumResourceKind
import com.datadog.android.rum.RumResourceMethod
import com.datadog.android.rum.internal.domain.event.ResourceTiming
import com.datadog.android.rum.internal.monitor.AdvancedRumMonitor
import java.io.InputStream
Expand Down Expand Up @@ -176,7 +177,7 @@ class RumResourceInputStream @JvmOverloads constructor(
// endregion

internal companion object {
internal const val METHOD: String = "GET"
internal val METHOD: RumResourceMethod = RumResourceMethod.GET

internal const val ERROR_CLOSE = "Error closing input stream"
internal const val ERROR_MARK = "Error marking input stream"
Expand Down
Loading
Loading