Skip to content

Commit a7839ec

Browse files
committed
RUM-8098: improving LocalAttribute documentation & params
RUM-8098: post-review fixes
1 parent 74f52eb commit a7839ec

File tree

12 files changed

+70
-70
lines changed

12 files changed

+70
-70
lines changed

dd-sdk-android-core/api/dd-sdk-android-core.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ public final class com/datadog/android/core/internal/attributes/LocalAttribute$K
728728
public static final field CREATION_SAMPLING_RATE Lcom/datadog/android/core/internal/attributes/LocalAttribute$Key;
729729
public static final field REPORTING_SAMPLING_RATE Lcom/datadog/android/core/internal/attributes/LocalAttribute$Key;
730730
public static final field VIEW_SCOPE_INSTRUMENTATION_TYPE Lcom/datadog/android/core/internal/attributes/LocalAttribute$Key;
731-
public final fun getString ()Ljava/lang/String;
731+
public fun toString ()Ljava/lang/String;
732732
public static fun valueOf (Ljava/lang/String;)Lcom/datadog/android/core/internal/attributes/LocalAttribute$Key;
733733
public static fun values ()[Lcom/datadog/android/core/internal/attributes/LocalAttribute$Key;
734734
}

dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/attributes/LocalAttribute.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,23 @@ interface LocalAttribute {
1818
* Enumeration of all local attributes keys used in the application.
1919
* Made via **enum** to make sure that all such attributes will be removed before sending the event to the backend.
2020
*
21-
* @property string - Unique string value for a local attribute key.
21+
* @param string - Unique string value for a local attribute key.
2222
*/
2323
@InternalApi
2424
enum class Key(
25-
val string: String
25+
private val string: String
2626
) {
27-
/* Some of the metrics like [PerformanceMetric] being sampled on the
28-
* metric creation place and then reported with 100% probability.
29-
* In such cases we need to use *creationSampleRate* to compute effectiveSampleRate correctlyThe sampling
30-
* rate is used when creating metrics.
31-
* Creation(head) sampling rate exist only for long-lived metrics like method performance.
32-
* Created metric still could not be sent it depends on [REPORTING_SAMPLING_RATE] sampling rate
27+
/*
28+
* Some of the metrics such as [PerformanceMetric] are sampled at the point of
29+
* metric creation and then reported with 100% probability.
30+
* In such cases we need to use *creationSampleRate* to correctly calculate effectiveSampleRate.
31+
* The creation(head) sample rate only exists for long-lived metrics such as method performance.
32+
* Created metric still could not be sent, it depends on the [REPORTING_SAMPLING_RATE] sample rate.
3333
*/
3434
CREATION_SAMPLING_RATE("_dd.local.head_sampling_rate_key"),
3535

36-
/* Sampling rate that is used to decide to send or not to send the metric.
36+
/*
37+
* Sampling rate that is used to decide to send or not to send the metric.
3738
* Each metric should have reporting(tail) sampling rate.
3839
* It's possible that metric has only reporting(tail) sampling rate.
3940
*/
@@ -43,7 +44,11 @@ interface LocalAttribute {
4344
* Indicates which instrumentation was used to track the view scope.
4445
* See [ViewScopeInstrumentationType] for possible values.
4546
*/
46-
VIEW_SCOPE_INSTRUMENTATION_TYPE("_dd.local.view_instrumentation_type_key")
47+
VIEW_SCOPE_INSTRUMENTATION_TYPE("_dd.local.view_instrumentation_type_key");
48+
49+
override fun toString(): String {
50+
return string
51+
}
4752
}
4853

4954
/**
@@ -56,9 +61,6 @@ interface LocalAttribute {
5661
interface Constant {
5762
/** Constant attribute key. For enum constants will be same for all values. */
5863
val key: Key
59-
60-
/** Constant attribute value. One item from set of possible finite values for a given constant attribute.*/
61-
val value: Any
6264
}
6365
}
6466

@@ -99,5 +101,5 @@ fun MutableMap<String, Any?>.enrichWithLocalAttribute(
99101
key: LocalAttribute.Key,
100102
value: Any?
101103
) = apply {
102-
this[key.string] = value
104+
this[key.toString()] = value
103105
}

dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/attributes/ViewScopeInstrumentationType.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,18 @@ import com.datadog.android.lint.InternalApi
1111
* A set of constants describing the instrumentation that were used to define the view scope.
1212
*/
1313
@InternalApi
14-
enum class ViewScopeInstrumentationType(
15-
override val value: String
16-
) : LocalAttribute.Constant {
14+
enum class ViewScopeInstrumentationType : LocalAttribute.Constant {
1715
/** Tracked manually through the RUMMonitor API. */
18-
MANUAL("manual"),
16+
MANUAL,
1917

2018
/** Tracked through ComposeNavigationObserver instrumentation. */
21-
COMPOSE("compose"),
19+
COMPOSE,
2220

2321
/** Tracked through ActivityViewTrackingStrategy instrumentation. */
24-
ACTIVITY("activity"),
22+
ACTIVITY,
2523

2624
/** Tracked through FragmentViewTrackingStrategy instrumentation. */
27-
FRAGMENT("fragment");
25+
FRAGMENT;
2826

2927
/** @inheritdoc */
3028
override val key: LocalAttribute.Key = LocalAttribute.Key.VIEW_SCOPE_INSTRUMENTATION_TYPE

dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/logger/SdkInternalLoggerTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ internal class SdkInternalLoggerTest {
453453
// Given
454454
val samplingRate = 100.0f
455455
val fakeAdditionalProperties = forge.exhaustiveAttributes().also {
456-
it[LocalAttribute.Key.REPORTING_SAMPLING_RATE.string] = samplingRate
456+
it[LocalAttribute.Key.REPORTING_SAMPLING_RATE.toString()] = samplingRate
457457
}
458458
val mockLambda: () -> String = mock()
459459
whenever(mockLambda.invoke()) doReturn fakeMessage
@@ -505,13 +505,13 @@ internal class SdkInternalLoggerTest {
505505
val metricEvent = firstValue as InternalTelemetryEvent.Metric
506506

507507
assertThat(
508-
metricEvent.additionalProperties?.get(LocalAttribute.Key.CREATION_SAMPLING_RATE.string)
508+
metricEvent.additionalProperties?.get(LocalAttribute.Key.CREATION_SAMPLING_RATE.toString())
509509
).isEqualTo(
510510
expectedCreationSampleRate
511511
)
512512

513513
assertThat(
514-
metricEvent.additionalProperties?.get(LocalAttribute.Key.REPORTING_SAMPLING_RATE.string)
514+
metricEvent.additionalProperties?.get(LocalAttribute.Key.REPORTING_SAMPLING_RATE.toString())
515515
).isEqualTo(
516516
samplingRate
517517
)
@@ -544,11 +544,11 @@ internal class SdkInternalLoggerTest {
544544
assertThat(
545545
apiUsageEvent.additionalProperties
546546
).doesNotContainKeys(
547-
LocalAttribute.Key.CREATION_SAMPLING_RATE.string
547+
LocalAttribute.Key.CREATION_SAMPLING_RATE.toString()
548548
)
549549

550550
assertThat(
551-
apiUsageEvent.additionalProperties[LocalAttribute.Key.REPORTING_SAMPLING_RATE.string]
551+
apiUsageEvent.additionalProperties[LocalAttribute.Key.REPORTING_SAMPLING_RATE.toString()]
552552
).isEqualTo(
553553
samplingRate
554554
)
@@ -569,7 +569,7 @@ internal class SdkInternalLoggerTest {
569569
),
570570
target = InternalLogger.Target.TELEMETRY,
571571
messageBuilder = { forge.aString() },
572-
additionalProperties = mapOf(LocalAttribute.Key.REPORTING_SAMPLING_RATE.string to samplingRate)
572+
additionalProperties = mapOf(LocalAttribute.Key.REPORTING_SAMPLING_RATE.toString() to samplingRate)
573573
)
574574

575575
// Then
@@ -581,11 +581,11 @@ internal class SdkInternalLoggerTest {
581581
assertThat(
582582
debugEvent.additionalProperties
583583
).doesNotContainKeys(
584-
LocalAttribute.Key.CREATION_SAMPLING_RATE.string
584+
LocalAttribute.Key.CREATION_SAMPLING_RATE.toString()
585585
)
586586

587587
assertThat(
588-
debugEvent.additionalProperties?.get(LocalAttribute.Key.REPORTING_SAMPLING_RATE.string)
588+
debugEvent.additionalProperties?.get(LocalAttribute.Key.REPORTING_SAMPLING_RATE.toString())
589589
).isEqualTo(
590590
samplingRate
591591
)
@@ -604,7 +604,7 @@ internal class SdkInternalLoggerTest {
604604
target = InternalLogger.Target.TELEMETRY,
605605
throwable = forge.aThrowable(),
606606
messageBuilder = { forge.aString() },
607-
additionalProperties = mapOf(LocalAttribute.Key.REPORTING_SAMPLING_RATE.string to samplingRate)
607+
additionalProperties = mapOf(LocalAttribute.Key.REPORTING_SAMPLING_RATE.toString() to samplingRate)
608608
)
609609

610610
// Then
@@ -616,11 +616,11 @@ internal class SdkInternalLoggerTest {
616616
assertThat(
617617
debugEvent.additionalProperties
618618
).doesNotContainKeys(
619-
LocalAttribute.Key.CREATION_SAMPLING_RATE.string
619+
LocalAttribute.Key.CREATION_SAMPLING_RATE.toString()
620620
)
621621

622622
assertThat(
623-
debugEvent.additionalProperties?.get(LocalAttribute.Key.REPORTING_SAMPLING_RATE.string)
623+
debugEvent.additionalProperties?.get(LocalAttribute.Key.REPORTING_SAMPLING_RATE.toString())
624624
).isEqualTo(
625625
samplingRate
626626
)

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScope.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ internal open class RumViewScope(
14341434
}
14351435

14361436
private fun RumRawEvent.StartView.tryResolveInstrumentationType() =
1437-
attributes[LocalAttribute.Key.VIEW_SCOPE_INSTRUMENTATION_TYPE.string] as? ViewScopeInstrumentationType
1437+
attributes[LocalAttribute.Key.VIEW_SCOPE_INSTRUMENTATION_TYPE.toString()] as? ViewScopeInstrumentationType
14381438

14391439
@Suppress("CommentOverPrivateFunction")
14401440
/**

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/telemetry/internal/TelemetryEventHandler.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,10 @@ internal class TelemetryEventHandler(
498498
return (effectiveSampleRate * HUNDRED).toFloat()
499499
}
500500

501-
private fun Map<String, Any?>.getFloat(key: LocalAttribute.Key) = get(key.string) as? Float
501+
private fun Map<String, Any?>.getFloat(key: LocalAttribute.Key) = get(key.toString()) as? Float
502502

503503
private fun Map<String, Any?>.cleanUpInternalAttributes() = toMutableMap().apply {
504-
LocalAttribute.Key.values().forEach { key -> remove(key.string) }
504+
LocalAttribute.Key.values().forEach { key -> remove(key.toString()) }
505505
}
506506

507507
// endregion

features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/ActivityViewTrackingStrategyTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ internal class ActivityViewTrackingStrategyTest :
107107
verify(rumMonitor.mockInstance).startView(
108108
mockActivity,
109109
mockActivity.resolveViewName(),
110-
mapOf(ViewScopeInstrumentationType.ACTIVITY.key.string to ViewScopeInstrumentationType.ACTIVITY)
110+
mapOf(ViewScopeInstrumentationType.ACTIVITY.key.toString() to ViewScopeInstrumentationType.ACTIVITY)
111111
)
112112
}
113113

@@ -163,7 +163,7 @@ internal class ActivityViewTrackingStrategyTest :
163163
val expectedAttributes = mapOf<String, Any?>(
164164
"view.intent.action" to action,
165165
"view.intent.uri" to uri,
166-
ViewScopeInstrumentationType.ACTIVITY.key.string to ViewScopeInstrumentationType.ACTIVITY
166+
ViewScopeInstrumentationType.ACTIVITY.key.toString() to ViewScopeInstrumentationType.ACTIVITY
167167
)
168168

169169
testedStrategy.register(rumMonitor.mockSdkCore, mockActivity)
@@ -223,7 +223,7 @@ internal class ActivityViewTrackingStrategyTest :
223223
verify(rumMonitor.mockInstance).startView(
224224
mockActivity,
225225
fakeName,
226-
mapOf(ViewScopeInstrumentationType.ACTIVITY.key.string to ViewScopeInstrumentationType.ACTIVITY)
226+
mapOf(ViewScopeInstrumentationType.ACTIVITY.key.toString() to ViewScopeInstrumentationType.ACTIVITY)
227227
)
228228
}
229229

@@ -244,7 +244,7 @@ internal class ActivityViewTrackingStrategyTest :
244244
verify(rumMonitor.mockInstance).startView(
245245
mockActivity,
246246
mockActivity.resolveViewName(),
247-
mapOf(ViewScopeInstrumentationType.ACTIVITY.key.string to ViewScopeInstrumentationType.ACTIVITY)
247+
mapOf(ViewScopeInstrumentationType.ACTIVITY.key.toString() to ViewScopeInstrumentationType.ACTIVITY)
248248
)
249249
}
250250

features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/metric/ViewEndedMetricDispatcherTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ internal class ViewEndedMetricDispatcherTest {
8888
)
8989
}
9090

91-
fakeInstrumentationType = instrumentationType?.value
91+
fakeInstrumentationType = instrumentationType?.name?.lowercase()
9292

9393
dispatcherUnderTest = ViewEndedMetricDispatcher(
9494
viewType = fakeViewType,

features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/tracking/FragmentViewTrackingStrategyTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ internal class FragmentViewTrackingStrategyTest : ObjectTest<FragmentViewTrackin
261261
testedStrategy.register(rumMonitor.mockSdkCore, mockAppContext)
262262
val mockFragment: Fragment = mockFragmentWithArguments(forge)
263263
val expectedAttrs = mapOf(
264-
ViewScopeInstrumentationType.FRAGMENT.key.string to ViewScopeInstrumentationType.FRAGMENT
264+
ViewScopeInstrumentationType.FRAGMENT.key.toString() to ViewScopeInstrumentationType.FRAGMENT
265265
)
266266
val argumentCaptor = argumentCaptor<FragmentManager.FragmentLifecycleCallbacks>()
267267

@@ -478,7 +478,7 @@ internal class FragmentViewTrackingStrategyTest : ObjectTest<FragmentViewTrackin
478478
)
479479
testedStrategy.register(rumMonitor.mockSdkCore, mockAppContext)
480480
val expectedAttrs = mapOf(
481-
ViewScopeInstrumentationType.FRAGMENT.key.string to ViewScopeInstrumentationType.FRAGMENT
481+
ViewScopeInstrumentationType.FRAGMENT.key.toString() to ViewScopeInstrumentationType.FRAGMENT
482482
)
483483
val mockFragment: android.app.Fragment = mockDeprecatedFragmentWithArguments(forge)
484484
val argumentCaptor =

features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/tracking/NavigationViewTrackingStrategyTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ internal class NavigationViewTrackingStrategyTest {
314314
verify(rumMonitor.mockInstance).startView(
315315
mockNavDestination,
316316
fakeDestinationName,
317-
mapOf(ViewScopeInstrumentationType.FRAGMENT.key.string to ViewScopeInstrumentationType.FRAGMENT)
317+
mapOf(ViewScopeInstrumentationType.FRAGMENT.key.toString() to ViewScopeInstrumentationType.FRAGMENT)
318318
)
319319
}
320320

@@ -341,7 +341,7 @@ internal class NavigationViewTrackingStrategyTest {
341341
verify(rumMonitor.mockInstance).startView(
342342
mockNavDestination,
343343
customName,
344-
mapOf(ViewScopeInstrumentationType.FRAGMENT.key.string to ViewScopeInstrumentationType.FRAGMENT)
344+
mapOf(ViewScopeInstrumentationType.FRAGMENT.key.toString() to ViewScopeInstrumentationType.FRAGMENT)
345345
)
346346
}
347347

@@ -352,7 +352,7 @@ internal class NavigationViewTrackingStrategyTest {
352352
whenever(mockPredicate.accept(mockNavDestination)) doReturn true
353353
val arguments = Bundle()
354354
val expectedAttrs = mutableMapOf<String, Any?>(
355-
ViewScopeInstrumentationType.FRAGMENT.key.string to ViewScopeInstrumentationType.FRAGMENT
355+
ViewScopeInstrumentationType.FRAGMENT.key.toString() to ViewScopeInstrumentationType.FRAGMENT
356356
)
357357
repeat(10) {
358358
val key = forge.anAlphabeticalString()
@@ -391,7 +391,7 @@ internal class NavigationViewTrackingStrategyTest {
391391
verify(rumMonitor.mockInstance).startView(
392392
mockNavDestination,
393393
fakeDestinationName,
394-
mapOf(ViewScopeInstrumentationType.FRAGMENT.key.string to ViewScopeInstrumentationType.FRAGMENT)
394+
mapOf(ViewScopeInstrumentationType.FRAGMENT.key.toString() to ViewScopeInstrumentationType.FRAGMENT)
395395
)
396396
}
397397

@@ -413,12 +413,12 @@ internal class NavigationViewTrackingStrategyTest {
413413
verify(rumMonitor.mockInstance).startView(
414414
mockNavDestination,
415415
fakeDestinationName,
416-
mapOf(ViewScopeInstrumentationType.FRAGMENT.key.string to ViewScopeInstrumentationType.FRAGMENT)
416+
mapOf(ViewScopeInstrumentationType.FRAGMENT.key.toString() to ViewScopeInstrumentationType.FRAGMENT)
417417
)
418418
verify(rumMonitor.mockInstance).startView(
419419
newDestination,
420420
newDestinationName,
421-
mapOf(ViewScopeInstrumentationType.FRAGMENT.key.string to ViewScopeInstrumentationType.FRAGMENT)
421+
mapOf(ViewScopeInstrumentationType.FRAGMENT.key.toString() to ViewScopeInstrumentationType.FRAGMENT)
422422
)
423423
}
424424
}

0 commit comments

Comments
 (0)