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

RUMM-924 Introduce the new InternalLogger#metric API #1581

Merged

Conversation

mariusc83
Copy link
Member

What does this PR do?

A brief description of the change being made with this pull request.

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@mariusc83 mariusc83 self-assigned this Aug 22, 2023
@mariusc83 mariusc83 marked this pull request as ready for review August 22, 2023 07:41
@mariusc83 mariusc83 requested a review from a team as a code owner August 22, 2023 07:41
@@ -96,6 +96,13 @@ interface InternalLogger {
additionalProperties: Map<String, Any?>? = null
)

/**
* Logs a metric from the internal implementation.
Copy link
Member

Choose a reason for hiding this comment

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

what is the meaning of internal implementation here? Also maybe we need to add the statement that metric will be sent to the telemetry (and say how), because from the method arguments it is not evident where is the metric here.

@@ -188,6 +192,21 @@ internal class SdkInternalLogger(
}
rumFeature.sendEvent(telemetryEvent)
}
private fun logMetric(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private fun logMetric(
private fun logMetric(

testedInternalLogger.metric(
mockLambda,
fakeAdditionalProperties
)
Copy link
Member

Choose a reason for hiding this comment

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

What is the point of the test without verification part?

Copy link
Member Author

Choose a reason for hiding this comment

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

I cannot verify anything there, I wanted to make sure is not throwing anything...maybe there is a method to assert that isNotThrowing

Copy link
Member

Choose a reason for hiding this comment

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

you can wrap the invocation in assertNotThrows.

Copy link
Member Author

Choose a reason for hiding this comment

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

yup, that's what I also have in mind ;)

@@ -39,4 +39,8 @@ internal class Telemetry(
(GlobalRumMonitor.get(sdkCore) as? AdvancedRumMonitor)
?.sendDebugTelemetryEvent(message, additionalProperties)
}
fun metric(message: String, additionalProperties: Map<String, Any?>? = null) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fun metric(message: String, additionalProperties: Map<String, Any?>? = null) {
fun metric(message: String, additionalProperties: Map<String, Any?>? = null) {

@@ -113,7 +113,7 @@ internal class TelemetryEventHandler(

val eventIdentity = event.identity

if (seenInCurrentSession.contains(eventIdentity)) {
if (!event.isMetric && seenInCurrentSession.contains(eventIdentity)) {
Copy link
Member

Choose a reason for hiding this comment

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

do we have a risk of sending too much metrics by disabling this check and thus adding a lot of pressure on the storage and also on the Datadog servers?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was following what was done in iOS here. I guess the risk was assessed already there, in the end we are going to have an extra sampler in the MetricsDispatcher which will come in the next PR. We have a 15% extra sampler there.

}

@Test
fun `𝕄 handle metric event 𝕎 onReceive(){no additionalProperties}`(
Copy link
Member

Choose a reason for hiding this comment

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

probably test with missing message is missing

jonathanmos
jonathanmos previously approved these changes Aug 22, 2023
val fakeAdditionalProperties = forge.exhaustiveAttributes()
testedFeature.onInitialize(appContext.mockInstance)
val event = mapOf(
"type" to "mobile_metric",
Copy link
Member

Choose a reason for hiding this comment

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

minor: "mobile_metric" is hardcoded in the tests in several places - perhaps it could be taken from a constant so as to only change in one place in future if the value changed?

@mariusc83 mariusc83 force-pushed the mconstantin/rumm-924/add-the-internalloggger-metrics-method branch from cfde8e0 to 35e8143 Compare August 22, 2023 12:51
@mariusc83 mariusc83 requested review from 0xnm and jonathanmos August 22, 2023 12:59
@@ -444,6 +446,53 @@ internal class SdkInternalLoggerTest {
)
}

@Test
fun `𝕄 send metric 𝕎 metric`(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fun `𝕄 send metric 𝕎 metric`(
fun `𝕄 send metric 𝕎 metric()`(

* @param messageBuilder the lambda building the metric message
* @param additionalProperties additional properties to add to the metric
*/
fun metric(messageBuilder: () -> String, additionalProperties: Map<String, Any?>)
Copy link
Member

Choose a reason for hiding this comment

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

Function name should be action verbs. We should consider logMetric. Alternatively, we could instead use an InternalLogger.Level.METRIC instead, and reuse the existing top level methods. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

i'd rather keep a new method here to match what iOS added in the InternalLogger but will change it to logMetric

@mariusc83 mariusc83 force-pushed the mconstantin/rumm-924/add-the-internalloggger-metrics-method branch 4 times, most recently from b2af158 to c2f62d2 Compare August 22, 2023 14:30
0xnm
0xnm previously approved these changes Aug 22, 2023
Copy link
Member

@0xnm 0xnm left a comment

Choose a reason for hiding this comment

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

lgtm. I left some comments, but they are not blocking.

@@ -77,6 +77,7 @@ public abstract interface class com/datadog/android/api/InternalLogger {
public static final field Companion Lcom/datadog/android/api/InternalLogger$Companion;
public abstract fun log (Lcom/datadog/android/api/InternalLogger$Level;Lcom/datadog/android/api/InternalLogger$Target;Lkotlin/jvm/functions/Function0;Ljava/lang/Throwable;ZLjava/util/Map;)V
public abstract fun log (Lcom/datadog/android/api/InternalLogger$Level;Ljava/util/List;Lkotlin/jvm/functions/Function0;Ljava/lang/Throwable;ZLjava/util/Map;)V
public abstract fun metric (Lkotlin/jvm/functions/Function0;Ljava/util/Map;)V
Copy link
Member

Choose a reason for hiding this comment

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

this has to be updated

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah it is something wrong with the api generation as I already ran that method 🤔

Comment on lines 100 to 101
* Logs a specific metric from the internal implementation. The metric will leverage the new
* added additionalProperties in the
Copy link
Member

Choose a reason for hiding this comment

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

I'm still not quite clear with the description. Does internal implementation mean from SDK-related code only? Also I guess there is a typo in new added, and not quite clear how additionalProperties will be leveraged. Maybe we can say that metric data (type, values, etc.) will be taken from additionalProperties? This way it is more clear imo.

Copy link
Member Author

Choose a reason for hiding this comment

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

the internal implementation is present in all the other methods description so I just followed the pattern. And yes for me it means that is meant for internal usage inside the SDK code. I will try to update the last part there ;)

@mariusc83 mariusc83 force-pushed the mconstantin/rumm-924/add-the-internalloggger-metrics-method branch from c2f62d2 to ac0ffa6 Compare August 23, 2023 07:22
@codecov-commenter
Copy link

codecov-commenter commented Aug 23, 2023

Codecov Report

Merging #1581 (71a10da) into develop (3bcb7ae) will decrease coverage by 0.04%.
Report is 4 commits behind head on develop.
The diff coverage is 88.37%.

@@             Coverage Diff             @@
##           develop    #1581      +/-   ##
===========================================
- Coverage    83.37%   83.34%   -0.04%     
===========================================
  Files          437      437              
  Lines        14910    14942      +32     
  Branches      2230     2237       +7     
===========================================
+ Hits         12431    12452      +21     
- Misses        1885     1894       +9     
- Partials       594      596       +2     
Files Changed Coverage Δ
...n/kotlin/com/datadog/android/api/InternalLogger.kt 100.00% <ø> (ø)
...om/datadog/android/telemetry/internal/Telemetry.kt 12.50% <0.00%> (-2.88%) ⬇️
...tlin/com/datadog/android/core/SdkInternalLogger.kt 89.01% <87.50%> (-0.15%) ⬇️
...lin/com/datadog/android/rum/internal/RumFeature.kt 92.72% <94.74%> (+0.25%) ⬆️
...g/android/rum/internal/domain/scope/RumRawEvent.kt 100.00% <100.00%> (ø)
.../android/rum/internal/monitor/DatadogRumMonitor.kt 88.58% <100.00%> (+1.24%) ⬆️
...ndroid/telemetry/internal/TelemetryEventHandler.kt 75.64% <100.00%> (-1.28%) ⬇️

... and 15 files with indirect coverage changes

@mariusc83 mariusc83 force-pushed the mconstantin/rumm-924/add-the-internalloggger-metrics-method branch from ac0ffa6 to 71a10da Compare August 23, 2023 07:33
@mariusc83 mariusc83 requested a review from 0xnm August 23, 2023 07:34
@mariusc83 mariusc83 force-pushed the mconstantin/rumm-924/add-the-internalloggger-metrics-method branch from 71a10da to 409b4e0 Compare August 23, 2023 09:31
@mariusc83 mariusc83 merged commit 2b41ee8 into develop Aug 23, 2023
@mariusc83 mariusc83 deleted the mconstantin/rumm-924/add-the-internalloggger-metrics-method branch August 23, 2023 11:07
@xgouchet xgouchet added this to the 2.1.0 milestone Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants