Skip to content

Commit

Permalink
Merge pull request #433 from DataDog/xgouchet/RUMM-911/remove_deprecated
Browse files Browse the repository at this point in the history
RUMM-911 Remove deprecated APIs
  • Loading branch information
xgouchet authored Dec 7, 2020
2 parents 15cd012 + 0018e9a commit c13a0e8
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 119 deletions.
3 changes: 2 additions & 1 deletion dd-sdk-android-glide/apiSurface
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
open class com.datadog.android.glide.DatadogGlideModule : com.bumptech.glide.module.AppGlideModule
DEPRECATED open class com.datadog.android.glide.DatadogGlideModule : com.bumptech.glide.module.AppGlideModule
constructor(List<String>)
constructor()
override fun registerComponents(android.content.Context, com.bumptech.glide.Glide, com.bumptech.glide.Registry)
override fun applyOptions(android.content.Context, com.bumptech.glide.GlideBuilder)
open fun getClientBuilder(): okhttp3.OkHttpClient.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ import okhttp3.OkHttpClient
* This sets up an OkHttp based downloader that will send Traces and RUM Resource events.
* Also any Glide related error (Disk cache, source transformation, …) will be sent as RUM Errors.
*/
@Deprecated(
"Hosts should be defined in the DatadogConfig.setFirstPartyHosts()",
ReplaceWith(
expression = "DatadogInterceptor(tracedRequestListener)"
)
)
open class DatadogGlideModule(
private val tracedHosts: List<String>
) : AppGlideModule() {

constructor() : this (emptyList())

// region AppGlideModule

/** @inheritdoc */
Expand Down
9 changes: 2 additions & 7 deletions dd-sdk-android/apiSurface
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
object com.datadog.android.Datadog
DEPRECATED const val DATADOG_US: String
DEPRECATED const val DATADOG_EU: String
DEPRECATED fun initialize(android.content.Context, DatadogConfig)
fun initialize(android.content.Context, com.datadog.android.privacy.TrackingConsent, DatadogConfig)
DEPRECATED fun setEndpointUrl(String, com.datadog.android.log.EndpointUpdateStrategy)
fun isInitialized(): Boolean
fun clearAllData()
fun setVerbosity(Int)
Expand Down Expand Up @@ -65,14 +62,12 @@ class com.datadog.android.DatadogEventListener : okhttp3.EventListener
class Factory : okhttp3.EventListener.Factory
override fun create(okhttp3.Call): okhttp3.EventListener
open class com.datadog.android.DatadogInterceptor : com.datadog.android.tracing.TracingInterceptor
constructor(List<String>, com.datadog.android.tracing.TracedRequestListener = NoOpTracedRequestListener())
DEPRECATED constructor(List<String>, com.datadog.android.tracing.TracedRequestListener = NoOpTracedRequestListener())
constructor(com.datadog.android.tracing.TracedRequestListener = NoOpTracedRequestListener())
override fun intercept(okhttp3.Interceptor.Chain): okhttp3.Response
override fun onRequestIntercepted(okhttp3.Request, io.opentracing.Span?, okhttp3.Response?, Throwable?)
override fun canSendSpan(): Boolean
companion object
DEPRECATED enum com.datadog.android.log.EndpointUpdateStrategy
- DISCARD_OLD_DATA
- SEND_OLD_DATA_TO_NEW_ENDPOINT
object com.datadog.android.log.LogAttributes
const val APPLICATION_PACKAGE: String
const val APPLICATION_VERSION: String
Expand Down
56 changes: 7 additions & 49 deletions dd-sdk-android/src/main/kotlin/com/datadog/android/Datadog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import com.datadog.android.core.internal.CoreFeature
import com.datadog.android.core.internal.lifecycle.ProcessLifecycleCallback
import com.datadog.android.core.internal.lifecycle.ProcessLifecycleMonitor
import com.datadog.android.core.internal.utils.devLogger
import com.datadog.android.core.internal.utils.warnDeprecated
import com.datadog.android.error.internal.CrashReportsFeature
import com.datadog.android.log.EndpointUpdateStrategy
import com.datadog.android.log.internal.LogsFeature
import com.datadog.android.log.internal.domain.Log
import com.datadog.android.log.internal.user.UserInfo
import com.datadog.android.privacy.TrackingConsent
import com.datadog.android.rum.internal.RumFeature
import com.datadog.android.tracing.internal.TracesFeature
import java.lang.IllegalArgumentException
import java.util.Locale
import java.util.concurrent.atomic.AtomicBoolean

/**
Expand All @@ -31,38 +30,6 @@ import java.util.concurrent.atomic.AtomicBoolean
@Suppress("TooManyFunctions")
object Datadog {

/**
* The endpoint for our US based servers, used by default by the SDK.
* @see [initialize]
* @deprecated Use the [DatadogEndpoint.LOGS_US] instead
*/
@Suppress("MemberVisibilityCanBePrivate")
@Deprecated(
"Use the DatadogEndpoint.LOGS_US instead",
ReplaceWith(
expression = "DatadogEndpoint.LOGS_US",
imports = ["com.datadog.android.DatadogEndpoint"]
)
)
const val DATADOG_US: String = "https://mobile-http-intake.logs.datadoghq.com"

/**
* The endpoint for our Europe based servers.
* Use this in your call to [initialize] if you log on
* [app.datadoghq.eu](https://app.datadoghq.eu/) instead of
* [app.datadoghq.com](https://app.datadoghq.com/)
* @deprecated Use the [DatadogEndpoint.LOGS_EU] instead
*/
@Suppress("MemberVisibilityCanBePrivate")
@Deprecated(
"Use the DatadogEndpoint.LOGS_EU instead",
ReplaceWith(
expression = "DatadogEndpoint.LOGS_EU",
imports = ["com.datadog.android.DatadogEndpoint"]
)
)
const val DATADOG_EU: String = "https://mobile-http-intake.logs.datadoghq.eu"

internal val initialized = AtomicBoolean(false)
internal val startupTimeNs = System.nanoTime()

Expand Down Expand Up @@ -96,6 +63,12 @@ object Datadog {
context: Context,
config: DatadogConfig
) {
warnDeprecated(
"Method Datadog.initialize(Context, DatadogConfig)",
"1.7.0",
"1.9.0",
"Datadog.initialize(Context, TrackingConsent, DatadogConfig)"
)
initialize(context, TrackingConsent.GRANTED, config)
}

Expand Down Expand Up @@ -200,21 +173,6 @@ object Datadog {
)
}

/**
* Changes the endpoint to which logging data is sent.
* @param endpointUrl the endpoint url to target, or null to use the default.
* Possible values are [DATADOG_US_LOGS], [DATADOG_EU_LOGS] or a custom endpoint.
* @param strategy the strategy defining how to handle logs created previously.
* Because logs are sent asynchronously, some logs intended for the previous endpoint
* might still be yet to sent.
*/
@Suppress("DeprecatedCallableAddReplaceWith")
@JvmStatic
@Deprecated("This was only meant as an internal feature and is not needed anymore.")
fun setEndpointUrl(endpointUrl: String, strategy: EndpointUpdateStrategy) {
devLogger.w(String.format(Locale.US, MESSAGE_DEPRECATED, "setEndpointUrl()"))
}

/**
* Checks if the Datadog SDK was already initialized.
* @return true if the SDK was initialized, false otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.datadog.android.core.internal.CoreFeature
import com.datadog.android.core.internal.net.FirstPartyHostDetector
import com.datadog.android.core.internal.net.identifyRequest
import com.datadog.android.core.internal.utils.devLogger
import com.datadog.android.core.internal.utils.warnDeprecated
import com.datadog.android.rum.GlobalRum
import com.datadog.android.rum.RumAttributes
import com.datadog.android.rum.RumErrorSource
Expand Down Expand Up @@ -95,6 +96,12 @@ internal constructor(
* the possibility to modify the created [io.opentracing.Span].
*/
@JvmOverloads
@Deprecated(
"Hosts should be defined in the DatadogConfig.setFirstPartyHosts()",
ReplaceWith(
expression = "DatadogInterceptor(tracedRequestListener)"
)
)
constructor(
tracedHosts: List<String>,
tracedRequestListener: TracedRequestListener = NoOpTracedRequestListener()
Expand All @@ -103,6 +110,30 @@ internal constructor(
tracedRequestListener,
CoreFeature.firstPartyHostDetector,
{ AndroidTracer.Builder().build() }
) {
warnDeprecated(
"Constructor DatadogInterceptor(List<String>, TracedRequestListener)",
"1.6.0",
"1.8.0",
"DatadogInterceptor(TracedRequestListener)"
)
}

/**
* Creates a [TracingInterceptor] to automatically create a trace around OkHttp [Request]s, and
* track RUM Resources.
*
* @param tracedRequestListener which listens on the intercepted [okhttp3.Request] and offers
* the possibility to modify the created [io.opentracing.Span].
*/
@JvmOverloads
constructor(
tracedRequestListener: TracedRequestListener = NoOpTracedRequestListener()
) : this(
emptyList(),
tracedRequestListener,
CoreFeature.firstPartyHostDetector,
{ AndroidTracer.Builder().build() }
)

// region Interceptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ internal abstract class DataOkHttpUploader(

// region DataOkHttpUploader

open fun setEndpoint(endpoint: String) {
this.url = endpoint
}

abstract fun buildQueryParams(): Map<String, Any>

// endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.datadog.android.log.Logger
import com.datadog.android.log.internal.logger.ConditionalLogHandler
import com.datadog.android.log.internal.logger.LogcatLogHandler
import com.datadog.android.log.internal.logger.NoOpLogHandler
import java.util.Locale

internal const val SDK_LOG_PREFIX = "DD_LOG"
internal const val DEV_LOG_PREFIX = "Datadog"
Expand Down Expand Up @@ -48,3 +49,37 @@ internal fun buildDevLogHandler(): ConditionalLogHandler {
i >= Datadog.libraryVerbosity
}
}

internal fun warnDeprecated(
target: String,
deprecatedSince: String,
removedInVersion: String,
alternative: String? = null
) {
if (alternative == null) {
devLogger.w(
WARN_DEPRECATED.format(
Locale.US,
target,
deprecatedSince,
removedInVersion
)
)
} else {
devLogger.w(
WARN_DEPRECATED_WITH_ALT.format(
Locale.US,
target,
deprecatedSince,
removedInVersion,
alternative
)
)
}
}

internal const val WARN_DEPRECATED = "%s has been deprecated since version %s, " +
"and will be removed in version %s."

internal const val WARN_DEPRECATED_WITH_ALT = "%s has been deprecated since version %s, " +
"and will be removed in version %s. Please use %s instead"

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ import okhttp3.OkHttpClient

internal open class LogsOkHttpUploader(
endpoint: String,
private val token: String,
token: String,
client: OkHttpClient
) : DataOkHttpUploader(buildUrl(endpoint, token), client) {

// region DataOkHttpUploader

override fun setEndpoint(endpoint: String) {
super.setEndpoint(buildUrl(endpoint, token))
}

override fun buildQueryParams(): Map<String, Any> {
return mutableMapOf(
QP_BATCH_TIME to System.currentTimeMillis(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import okhttp3.OkHttpClient

internal open class RumOkHttpUploader(
endpoint: String,
private val token: String,
token: String,
client: OkHttpClient
) : DataOkHttpUploader(buildUrl(endpoint, token), client, CONTENT_TYPE_TEXT_UTF8) {

Expand All @@ -31,10 +31,6 @@ internal open class RumOkHttpUploader(

// region DataOkHttpUploader

override fun setEndpoint(endpoint: String) {
super.setEndpoint(buildUrl(endpoint, token))
}

override fun buildQueryParams(): MutableMap<String, Any> {
return mutableMapOf(
QP_BATCH_TIME to System.currentTimeMillis(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.datadog.android.core.internal.CoreFeature
import com.datadog.android.core.internal.net.FirstPartyHostDetector
import com.datadog.android.core.internal.utils.devLogger
import com.datadog.android.core.internal.utils.loggableStackTrace
import com.datadog.android.core.internal.utils.warnDeprecated
import com.datadog.android.tracing.internal.TracesFeature
import com.datadog.opentracing.DDTracer
import com.datadog.trace.api.DDTags
Expand Down Expand Up @@ -95,7 +96,12 @@ open class TracingInterceptor
* @param tracedRequestListener a listener for automatically created [Span]s
*/
@JvmOverloads
@Deprecated("hosts should be defined in the DatadogConfig.setFirstPartyHosts()")
@Deprecated(
"Hosts should be defined in the DatadogConfig.setFirstPartyHosts().",
ReplaceWith(
expression = "TracingInterceptor(tracedRequestListener)"
)
)
constructor(
tracedHosts: List<String>,
tracedRequestListener: TracedRequestListener = NoOpTracedRequestListener()
Expand All @@ -105,7 +111,14 @@ open class TracingInterceptor
CoreFeature.firstPartyHostDetector,
null,
{ AndroidTracer.Builder().build() }
)
) {
warnDeprecated(
"Constructor TracingInterceptor(List<String>, TracedRequestListener)",
"1.6.0",
"1.8.0",
"TracingInterceptor(TracedRequestListener)"
)
}

/**
* Creates a [TracingInterceptor] to automatically create a trace around OkHttp [Request]s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ import okhttp3.OkHttpClient

internal open class TracesOkHttpUploader(
endpoint: String,
private val token: String,
token: String,
client: OkHttpClient
) : DataOkHttpUploader(buildUrl(endpoint, token), client, CONTENT_TYPE_TEXT_UTF8) {

// region DataOkHttpUploader

override fun setEndpoint(endpoint: String) {
super.setEndpoint(buildUrl(endpoint, token))
}

override fun buildQueryParams(): Map<String, Any> {
return emptyMap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,6 @@ internal abstract class DataOkHttpUploaderTest<T : DataOkHttpUploader> {
assertThat(status).isEqualTo(UploadStatus.NETWORK_ERROR)
}

@Test
fun `uploads with updated endpoint`(forge: Forge) {
val data = forge.anHexadecimalString().toByteArray(Charsets.UTF_8)
mockWebServer.shutdown()
val mockWebServer2 = MockWebServer()
mockWebServer2.start(forge.anInt(2000, 8000))
mockWebServer2.enqueue(forgeMockResponse(200))
fakeEndpoint = mockWebServer2.url("/").toString().removeSuffix("/")

testedUploader.setEndpoint(fakeEndpoint)
val status = testedUploader.upload(data)
assertThat(status).isEqualTo(UploadStatus.SUCCESS)
}

// region Internal

private fun assertRequestIsValid(
Expand Down
Loading

0 comments on commit c13a0e8

Please sign in to comment.