Skip to content

RUM-5387: Override Metrics telemetry sample rate#3022

Merged
kikoveiga merged 8 commits into
developfrom
kikoveiga/RUM-5387/set-metric-telemetry-sample-rate
Nov 26, 2025
Merged

RUM-5387: Override Metrics telemetry sample rate#3022
kikoveiga merged 8 commits into
developfrom
kikoveiga/RUM-5387/set-metric-telemetry-sample-rate

Conversation

@kikoveiga

@kikoveiga kikoveiga commented Nov 21, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

Creates a metricTelemetrySampleRateBypass field in CoreFeature and respective internal API setter, that will bypass any sample rates previously set throughout the codebase for metrics. Setting this and telemetrySampleRate to 100% will allow the Shopist app to send all metrics.

Motivation

Shopist metric telemetry was sampled the same way as our customers (low sample rate). We want to be able to customize this in order to have more events for dogfooding.

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)

@kikoveiga kikoveiga self-assigned this Nov 21, 2025
@codecov-commenter

codecov-commenter commented Nov 21, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.40%. Comparing base (f786365) to head (a412359).
⚠️ Report is 1054 commits behind head on develop.

Files with missing lines Patch % Lines
.../main/kotlin/com/datadog/android/_InternalProxy.kt 0.00% 0 Missing and 1 partial ⚠️
...n/com/datadog/android/core/internal/CoreFeature.kt 0.00% 1 Missing ⚠️
.../android/core/internal/logger/SdkInternalLogger.kt 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3022      +/-   ##
===========================================
+ Coverage    71.17%   71.40%   +0.23%     
===========================================
  Files          859      859              
  Lines        31444    31455      +11     
  Branches      5302     5306       +4     
===========================================
+ Hits         22378    22459      +81     
+ Misses        7555     7517      -38     
+ Partials      1511     1479      -32     
Files with missing lines Coverage Δ
.../main/kotlin/com/datadog/android/_InternalProxy.kt 62.50% <0.00%> (-2.72%) ⬇️
...n/com/datadog/android/core/internal/CoreFeature.kt 85.10% <0.00%> (-0.24%) ⬇️
.../android/core/internal/logger/SdkInternalLogger.kt 92.73% <83.33%> (+0.27%) ⬆️

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kikoveiga kikoveiga marked this pull request as ready for review November 21, 2025 14:55
@kikoveiga kikoveiga requested review from a team as code owners November 21, 2025 14:55
@datadog-official

datadog-official Bot commented Nov 21, 2025

Copy link
Copy Markdown

🎯 Code Coverage
Patch Coverage: 100.00%
Total Coverage: 71.35% (+0.00%)

View detailed report

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: a412359 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

ambushwork
ambushwork previously approved these changes Nov 24, 2025

@ambushwork ambushwork left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well done, just a few comments in the unit test

@FloatForgery(min = 0.0f, max = 100.0f) fakeSampleRate: Float
) {
// Given
val bypassSampleRate = 100.0f

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be faked as a random value by forge as well I think

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The idea of using 100.0f is to guarantee that the metric is always sent. Having a forged rate will make the tests flaky.

forge: Forge
) {
// Given
val hardcodedSampleRate = 100.0f

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same as above this can be a random value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please read my comment above.

}

@Test
fun `M not send metric W logMetric() {bypass rate is 0}`(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I don't miss anything, there should be a test like M send metric W logMetric() {bypass rate is 100} ?

fun setMetricTelemetrySampleRateBypass(
@FloatRange(from = 0.0, to = 100.0) sampleRate: Float
) {
(sdkCore as? DatadogCore)?.coreFeature?.metricTelemetrySampleRateBypass = sampleRate

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not quite sure it is a safe thing to do, given that here we apply the same rate for all the metrics logged and right now the rate used for metrics call vary from 0.75f to 100f, but at worst case Shopist shouldn't bring a huge amount of data.

Also by setting it to non-100 we increase the rate for some metrics and decrease for some others.

Although I would question if we still need this change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's true that some metrics will go from a sample rate of 0.75f to 100f, representing a 133x increase. I estimated that, in the Shopist Android app, there will be a 40x overall increase throughout all the metrics. Still, this will be a very small number when taking into account the intake from all the customers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe a better API would be a sampling callback which can decide if particular metric can be sampled or not. And if decision is not made by this callback, then default sampling mechanism should be applied.

This would allow a granular control, because with the current change we apply the same rate for all metrics, meaning some will go down, some will go up.

But this API is not blocking for me.

Comment thread sample/kotlin/src/main/kotlin/com/datadog/android/sample/SampleApplication.kt Outdated
@kikoveiga kikoveiga requested review from 0xnm and ambushwork November 25, 2025 14:20
fun setMetricTelemetrySampleRateBypass(
@FloatRange(from = 0.0, to = 100.0) sampleRate: Float
) {
(sdkCore as? DatadogCore)?.coreFeature?.metricTelemetrySampleRateBypass = sampleRate

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe a better API would be a sampling callback which can decide if particular metric can be sampled or not. And if decision is not made by this callback, then default sampling mechanism should be applied.

This would allow a granular control, because with the current change we apply the same rate for all metrics, meaning some will go down, some will go up.

But this API is not blocking for me.

@kikoveiga kikoveiga merged commit 8f7122f into develop Nov 26, 2025
26 of 27 checks passed
@kikoveiga kikoveiga deleted the kikoveiga/RUM-5387/set-metric-telemetry-sample-rate branch November 26, 2025 11:31
@ncreated ncreated restored the kikoveiga/RUM-5387/set-metric-telemetry-sample-rate branch April 9, 2026 10:18
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.

4 participants