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

RUM-1844: Add Method Call Telemetry #1940

Merged
merged 9 commits into from
May 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,20 @@ sealed class TypeDefinition {
}
}

val mergedAdditionalProperties =
jonathanmos marked this conversation as resolved.
Show resolved Hide resolved
if (this.additionalProperties == null) {
other.additionalProperties
} else if (other.additionalProperties == null) {
this.additionalProperties
} else {
additionalProperties.mergedWith(other.additionalProperties)
}

return Class(
name,
mergedFields,
"$description\n${other.description}".trim()
"$description\n${other.description}".trim(),
mergedAdditionalProperties
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class JsonSchemaReaderTest(
val clazz = JsonSchemaReaderTest::class.java
val inputPath = clazz.getResource("/input/$inputSchema.json").file
val testedReader = JsonSchemaReader(
mapOf("all_of_merged.json" to "UserMerged"),
mapOf(
"all_of_merged.json" to "UserMerged",
"additional_props_merged.json" to "AdditionalPropsMerged",
"additional_props_single_merge.json" to "AdditionalPropsSingleMerge"
),
NoOpLogger()
)

Expand All @@ -55,6 +59,8 @@ class JsonSchemaReaderTest(
arrayOf("nested", Book),
arrayOf("additional_props", Comment),
arrayOf("additional_props_any", Company),
arrayOf("additional_props_merged", AdditionalPropsMerged),
arrayOf("additional_props_single_merge", AdditionalPropsSingleMerge),
arrayOf("definition_name_conflict", Conflict),
arrayOf("definition", Customer),
arrayOf("definition_with_id", Customer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,52 @@ val Country = TypeDefinition.Class(
)
)

// both items have additionalProperties explicitly defined
val AdditionalPropsMerged = TypeDefinition.Class(
name = "AdditionalPropsMerged",
properties = listOf(
TypeProperty("email", TypeDefinition.Primitive(JsonPrimitiveType.STRING), true),
TypeProperty("phone", TypeDefinition.Primitive(JsonPrimitiveType.STRING), true),
TypeProperty(
"info",
TypeDefinition.Class(
name = "Info",
properties = listOf(
TypeProperty("notes", TypeDefinition.Primitive(JsonPrimitiveType.STRING), true),
TypeProperty("source", TypeDefinition.Primitive(JsonPrimitiveType.STRING), true)
),
additionalProperties = TypeDefinition.Class("?", emptyList())
),
true
),
TypeProperty("firstname", TypeDefinition.Primitive(JsonPrimitiveType.STRING), true),
TypeProperty("lastname", TypeDefinition.Primitive(JsonPrimitiveType.STRING), false)
)
)

// only one item has additionalProperties explicitly defined
val AdditionalPropsSingleMerge = TypeDefinition.Class(
name = "AdditionalPropsSingleMerge",
properties = listOf(
TypeProperty("email", TypeDefinition.Primitive(JsonPrimitiveType.STRING), true),
TypeProperty("phone", TypeDefinition.Primitive(JsonPrimitiveType.STRING), true),
TypeProperty(
"info",
TypeDefinition.Class(
name = "Info",
properties = listOf(
TypeProperty("notes", TypeDefinition.Primitive(JsonPrimitiveType.STRING), true),
TypeProperty("source", TypeDefinition.Primitive(JsonPrimitiveType.STRING), true)
),
additionalProperties = TypeDefinition.Class("?", emptyList())
),
true
),
TypeProperty("firstname", TypeDefinition.Primitive(JsonPrimitiveType.STRING), true),
TypeProperty("lastname", TypeDefinition.Primitive(JsonPrimitiveType.STRING), false)
)
)

val UserMerged = TypeDefinition.Class(
name = "UserMerged",
properties = listOf(
Expand Down
61 changes: 61 additions & 0 deletions buildSrc/src/test/resources/input/additional_props_merged.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "User",
"type": "object",
"allOf": [
{
"$ref": "#/definitions/contact"
},
{
"$ref": "#/definitions/identity"
}
],
"definitions": {
"contact": {
"type": "object",
"properties": {
"email": {
"type": "string"
},
"phone": {
"type": "string"
},
"info": {
"type": "object",
"additionalProperties": true,
"properties": {
"notes": {
"type": "string"
}
}
}
}
},
"identity": {
"type": "object",
"properties": {
"firstname": {
"type": "string"
},
"lastname": {
"type": "string"
},
"email": {
"type": "string"
},
"info": {
"type": "object",
"additionalProperties": true,
"properties": {
"source": {
"type": "string"
}
}
}
},
"required": [
"lastname"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "User",
"type": "object",
"allOf": [
{
"$ref": "#/definitions/contact"
},
{
"$ref": "#/definitions/identity"
}
],
"definitions": {
"contact": {
"type": "object",
"properties": {
"email": {
"type": "string"
},
"phone": {
"type": "string"
},
"info": {
"type": "object",
"additionalProperties": true,
"properties": {
"notes": {
"type": "string"
}
}
}
}
},
"identity": {
"type": "object",
"properties": {
"firstname": {
"type": "string"
},
"lastname": {
"type": "string"
},
"email": {
"type": "string"
},
"info": {
"type": "object",
"properties": {
"source": {
"type": "string"
}
}
}
},
"required": [
"lastname"
]
}
}
}
19 changes: 19 additions & 0 deletions dd-sdk-android-core/api/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ interface com.datadog.android.api.feature.FeatureScope
fun withWriteContext(Boolean = false, (com.datadog.android.api.context.DatadogContext, com.datadog.android.api.storage.EventBatchWriter) -> Unit)
fun sendEvent(Any)
fun <T: Feature> unwrap(): T
fun startPerformanceMeasure(String, com.datadog.android.core.metrics.TelemetryMetricType, Float): com.datadog.android.core.metrics.PerformanceMetric?
interface com.datadog.android.api.feature.FeatureSdkCore : com.datadog.android.api.SdkCore
val internalLogger: com.datadog.android.api.InternalLogger
fun registerFeature(Feature)
Expand Down Expand Up @@ -262,6 +263,24 @@ fun java.math.BigInteger.toHexString(): String
fun Thread.State.asString(): String
fun Array<StackTraceElement>.loggableStackTrace(): String
fun Throwable.loggableStackTrace(): String
class com.datadog.android.core.metrics.MethodCalledTelemetry : PerformanceMetric
constructor(String, com.datadog.android.api.InternalLogger, Long = System.nanoTime())
override fun stopAndSend(Boolean)
companion object
const val METHOD_CALLED_METRIC_NAME: String
const val METRIC_TYPE_VALUE: String
const val OPERATION_NAME: String
const val CALLER_CLASS: String
const val IS_SUCCESSFUL: String
const val EXECUTION_TIME: String
const val METHOD_CALL_OPERATION_NAME: String
interface com.datadog.android.core.metrics.PerformanceMetric
fun stopAndSend(Boolean)
companion object
const val METRIC_TYPE: String
fun startMetric(com.datadog.android.api.InternalLogger, String, TelemetryMetricType, Float = 100.0f): PerformanceMetric?
enum com.datadog.android.core.metrics.TelemetryMetricType
- MethodCalled
interface com.datadog.android.core.persistence.PersistenceStrategy
interface Factory
fun create(String, Int, Long): PersistenceStrategy
Expand Down
36 changes: 36 additions & 0 deletions dd-sdk-android-core/api/dd-sdk-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ public abstract interface class com/datadog/android/api/feature/FeatureEventRece

public abstract interface class com/datadog/android/api/feature/FeatureScope {
public abstract fun sendEvent (Ljava/lang/Object;)V
public abstract fun startPerformanceMeasure (Ljava/lang/String;Lcom/datadog/android/core/metrics/TelemetryMetricType;F)Lcom/datadog/android/core/metrics/PerformanceMetric;
public abstract fun unwrap ()Lcom/datadog/android/api/feature/Feature;
public abstract fun withWriteContext (ZLkotlin/jvm/functions/Function2;)V
}
Expand Down Expand Up @@ -716,6 +717,41 @@ public final class com/datadog/android/core/internal/utils/ThrowableExtKt {
public static final fun loggableStackTrace (Ljava/lang/Throwable;)Ljava/lang/String;
}

public final class com/datadog/android/core/metrics/MethodCalledTelemetry : com/datadog/android/core/metrics/PerformanceMetric {
public static final field CALLER_CLASS Ljava/lang/String;
public static final field Companion Lcom/datadog/android/core/metrics/MethodCalledTelemetry$Companion;
public static final field EXECUTION_TIME Ljava/lang/String;
public static final field IS_SUCCESSFUL Ljava/lang/String;
public static final field METHOD_CALLED_METRIC_NAME Ljava/lang/String;
public static final field METHOD_CALL_OPERATION_NAME Ljava/lang/String;
public static final field METRIC_TYPE_VALUE Ljava/lang/String;
public static final field OPERATION_NAME Ljava/lang/String;
public fun <init> (Ljava/lang/String;Lcom/datadog/android/api/InternalLogger;J)V
public synthetic fun <init> (Ljava/lang/String;Lcom/datadog/android/api/InternalLogger;JILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun stopAndSend (Z)V
}

public final class com/datadog/android/core/metrics/MethodCalledTelemetry$Companion {
}

public abstract interface class com/datadog/android/core/metrics/PerformanceMetric {
public static final field Companion Lcom/datadog/android/core/metrics/PerformanceMetric$Companion;
public static final field METRIC_TYPE Ljava/lang/String;
public abstract fun stopAndSend (Z)V
}

public final class com/datadog/android/core/metrics/PerformanceMetric$Companion {
public static final field METRIC_TYPE Ljava/lang/String;
public final fun startMetric (Lcom/datadog/android/api/InternalLogger;Ljava/lang/String;Lcom/datadog/android/core/metrics/TelemetryMetricType;F)Lcom/datadog/android/core/metrics/PerformanceMetric;
public static synthetic fun startMetric$default (Lcom/datadog/android/core/metrics/PerformanceMetric$Companion;Lcom/datadog/android/api/InternalLogger;Ljava/lang/String;Lcom/datadog/android/core/metrics/TelemetryMetricType;FILjava/lang/Object;)Lcom/datadog/android/core/metrics/PerformanceMetric;
}

public final class com/datadog/android/core/metrics/TelemetryMetricType : java/lang/Enum {
public static final field MethodCalled Lcom/datadog/android/core/metrics/TelemetryMetricType;
public static fun valueOf (Ljava/lang/String;)Lcom/datadog/android/core/metrics/TelemetryMetricType;
public static fun values ()[Lcom/datadog/android/core/metrics/TelemetryMetricType;
}

public abstract interface class com/datadog/android/core/persistence/PersistenceStrategy {
public abstract fun currentMetadata ()[B
public abstract fun dropAll ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package com.datadog.android.api.feature

import com.datadog.android.api.context.DatadogContext
import com.datadog.android.api.storage.EventBatchWriter
import com.datadog.android.core.metrics.PerformanceMetric
import com.datadog.android.core.metrics.TelemetryMetricType

/**
* Represents a Datadog feature.
Expand Down Expand Up @@ -38,4 +40,18 @@ interface FeatureScope {
* Returns the original feature.
*/
fun <T : Feature> unwrap(): T

/**
* Start measuring a performance metric.
*
* @param callerClass name of the class calling the performance measurement.
* @param metric name of the metric that we want to measure.
* @param samplingRate value between 0-100 for sampling the event.
* @return a PerformanceMetric object that can later be used to send telemetry, or null if sampled out
*/
fun startPerformanceMeasure(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this one is a part of the FeatureScope? by looking on the implementation it has nothing to do with the Feature - it takes InternalLogger, which is bound to the SDK core and the rest is just the arguments passed to the method. Is it implemented the same way on iOS?

callerClass: String,
metric: TelemetryMetricType,
samplingRate: Float
): PerformanceMetric?
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import com.datadog.android.core.internal.persistence.file.FileReaderWriter
import com.datadog.android.core.internal.persistence.file.NoOpFileOrchestrator
import com.datadog.android.core.internal.persistence.file.advanced.FeatureFileOrchestrator
import com.datadog.android.core.internal.persistence.file.batch.BatchFileReaderWriter
import com.datadog.android.core.metrics.PerformanceMetric
import com.datadog.android.core.metrics.TelemetryMetricType
import com.datadog.android.core.persistence.PersistenceStrategy
import com.datadog.android.privacy.TrackingConsentProviderCallback
import java.util.Collections
Expand Down Expand Up @@ -141,6 +143,19 @@ internal class SdkFeature(

// region FeatureScope

override fun startPerformanceMeasure(
callerClass: String,
metric: TelemetryMetricType,
samplingRate: Float
): PerformanceMetric? {
return PerformanceMetric.startMetric(
logger = internalLogger,
callerClass = callerClass,
metric = metric,
samplingRate = samplingRate
)
}

override fun withWriteContext(
forceNewBatch: Boolean,
callback: (DatadogContext, EventBatchWriter) -> Unit
Expand Down
Loading