-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bd46ae
commit 2eccdbe
Showing
9 changed files
with
615 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...in/com/datadog/android/sessionreplay/internal/recorder/telemetry/MethodCalledTelemetry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* 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.sessionreplay.internal.recorder.telemetry | ||
|
||
import com.datadog.android.Datadog | ||
import com.datadog.android.api.InternalLogger | ||
import com.datadog.android.core.InternalSdkCore | ||
|
||
internal class MethodCalledTelemetry( | ||
private val operationName: String, | ||
private val callerClass: String, | ||
private val logger: InternalLogger, | ||
private val startTime: Long = System.nanoTime(), | ||
private val internalSdkCore: InternalSdkCore? = Datadog.getInstance() as? InternalSdkCore | ||
) { | ||
internal fun stopMethodCalled(isSuccessful: Boolean) { | ||
val executionTime = System.nanoTime() - startTime | ||
val additionalProperties: MutableMap<String, Any> = mutableMapOf() | ||
|
||
val deviceInfo = internalSdkCore?.getDatadogContext()?.deviceInfo | ||
|
||
additionalProperties[EXECUTION_TIME] = executionTime | ||
additionalProperties[OPERATION_NAME] = operationName | ||
additionalProperties[CALLER_CLASS] = callerClass | ||
additionalProperties[IS_SUCCESSFUL] = isSuccessful | ||
additionalProperties[METRIC_TYPE] = METRIC_TYPE_VALUE | ||
val deviceMap = mutableMapOf<String, Any>() | ||
val osMap = mutableMapOf<String, Any>() | ||
|
||
deviceInfo?.deviceModel?.let { | ||
deviceMap[DEVICE_MODEL] = it | ||
} | ||
|
||
deviceInfo?.deviceBrand?.let { | ||
deviceMap[DEVICE_BRAND] = it | ||
} | ||
|
||
deviceInfo?.architecture?.let { | ||
deviceMap[DEVICE_ARCHITECTURE] = it | ||
} | ||
|
||
deviceInfo?.osName?.let { | ||
osMap[OS_NAME] = it | ||
} | ||
|
||
deviceInfo?.osVersion?.let { | ||
osMap[OS_VERSION] = it | ||
} | ||
|
||
deviceInfo?.deviceBuildId?.let { | ||
osMap[OS_BUILD] = it | ||
} | ||
|
||
additionalProperties[DEVICE_KEY] = deviceMap | ||
additionalProperties[OS_KEY] = osMap | ||
|
||
logger.logMetric( | ||
messageBuilder = { METRIC_NAME }, | ||
additionalProperties = additionalProperties | ||
) | ||
} | ||
|
||
internal companion object { | ||
// Basic Metric type key. | ||
internal const val METRIC_TYPE = "metric_type" | ||
|
||
// Title of the metric to be sent | ||
internal const val METRIC_NAME = "[Mobile Metric] Method Called" | ||
|
||
// Metric type value. | ||
internal const val METRIC_TYPE_VALUE = "method called" | ||
|
||
// The key for operation name. | ||
internal const val OPERATION_NAME = "operation_name" | ||
|
||
// The key for caller class. | ||
internal const val CALLER_CLASS = "caller_class" | ||
|
||
// The key for is successful. | ||
internal const val IS_SUCCESSFUL = "is_successful" | ||
|
||
// The key for execution time. | ||
internal const val EXECUTION_TIME = "execution_time" | ||
|
||
// The key for device object. | ||
internal const val DEVICE_KEY = "device" | ||
|
||
// The key for device model name. | ||
internal const val DEVICE_MODEL = "model" | ||
|
||
// The key for device brand. | ||
internal const val DEVICE_BRAND = "brand" | ||
|
||
// The key for CPU architecture. | ||
internal const val DEVICE_ARCHITECTURE = "architecture" | ||
|
||
// The key for operating system object. | ||
internal const val OS_KEY = "os" | ||
|
||
// The key for OS name. | ||
internal const val OS_NAME = "name" | ||
|
||
// The key for OS version. | ||
internal const val OS_VERSION = "version" | ||
|
||
// The key for OS build. | ||
internal const val OS_BUILD = "build" | ||
|
||
// The value for operation name | ||
internal const val METHOD_CALL_OPERATION_NAME = "Capture Record" | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../kotlin/com/datadog/android/sessionreplay/internal/recorder/telemetry/TelemetryWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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.sessionreplay.internal.recorder.telemetry | ||
|
||
import com.datadog.android.api.InternalLogger | ||
import com.datadog.android.core.sampling.RateBasedSampler | ||
import com.datadog.android.core.sampling.Sampler | ||
|
||
internal class TelemetryWrapper( | ||
|
||
// The sampling rate of the method call. Value between `0.0` and `100.0`, | ||
// where `0.0` means NO event will be processed and `100.0` means ALL events will be processed. | ||
// Note that this value is multiplicated by telemetry sampling (by default 20%) and | ||
// metric events sampling (hardcoded to 15%). Making it effectively 3% sampling rate | ||
// for sending events, when this value is set to `100`. | ||
private val samplingRate: Float = 100.0f, | ||
|
||
private val logger: InternalLogger, | ||
private val sampler: Sampler = RateBasedSampler(samplingRate) | ||
) { | ||
internal fun startMethodCalled( | ||
// Platform agnostic name of the operation. | ||
operationName: String, | ||
|
||
// The name of the class that calls the method. | ||
callerClass: String | ||
): MethodCalledTelemetry? { | ||
return if (sampler.sample()) { | ||
MethodCalledTelemetry( | ||
operationName, | ||
callerClass, | ||
logger | ||
) | ||
} else { | ||
null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.