Skip to content

[RUM-19223] Report each API usage telemetry once per SDK instance - #4037

Open
aleksandr-gringauz wants to merge 5 commits into
developfrom
dd/aleksandr-gringauz/RUM-19223/dedup-operation-usage-telemetry
Open

aleksandr-gringauz wants to merge 5 commits into
developfrom
dd/aleksandr-gringauz/RUM-19223/dedup-operation-usage-telemetry

Conversation

@aleksandr-gringauz

@aleksandr-gringauz aleksandr-gringauz commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Reporting usage telemetry logs only once so that we don't generate too much unnecessary telemetry.

Motivation

Additional Notes

Testing

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.md doc)

PR by Bits - View session in Datadog • Open in Slack

Comment @DataDog to request changes

logApiUsage sent a usage event on every call, so volume scaled with how
often apps call the API (e.g. operation steps). Deduplicate each usage
type and configuration per SDK instance, before sampling.

Ref: RUM-19223
Co-authored-by: aleksandr-gringauz <200633589+aleksandr-gringauz@users.noreply.github.com>
@aleksandr-gringauz
aleksandr-gringauz requested review from a team as code owners October 23, 2026 13:34
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

View session in Datadog

Bits Code status: ✅ Done

CI Auto-fix: Disabled | Enable

Comment @DataDog to request changes

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T14:34:46.811850Z 8f8c294 New commits
🔒 Security Review ✅ Completed 2026-10-23T14:36:24.647464Z 8f8c294 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

private val onlyOnceMaintainerMessages = mutableSetOf<String>()
private val onlyOnceTelemetryMessages = mutableSetOf<String>()

@Suppress("UnsafeThirdPartyFunctionCall") // the argument is always empty

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.

don't suppress, put into the yaml detekt config responsible for it

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.

@aleksandr-gringauz you need to use @\Datadog handle

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can only run on private repositories.

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bits Code Review: FAIL

A usage call racing with RUM initialization can permanently suppress that usage’s telemetry, even when later calls occur after initialization completes.

Open Bits AI session

🤖 Bits Code Review · Commit 9cf44db

val event = apiUsageEventBuilder()
// Deduplicate before sampling, so that each usage gets a single sampling decision
// and the effective sample rate remains accurate.
if (!onlyOnceApiUsages.add(event.onlyOnceKey()) || !sample(samplingRate)) return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Wait for telemetry readiness before consuming the usage key

If WebViewTracking.enable races with Rum.enable, a sampled-in TrackWebView event can be dropped after its key is permanently consumed here. DatadogCore.registerFeature exposes RUM before initialization completes, and the global monitor is registered afterward; SdkFeature.sendEvent or the no-op monitor discards events during that interval. Later WebView tracking calls previously could report usage, but now remain suppressed for the SDK instance. Coordinate deduplication with telemetry readiness or buffer the first event; this requires changes across the logger and RUM initialization path.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 71.84% (+0.13%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: beacc97 | Docs | View more details | Give us feedback!

Replace the suppressed Collections.newSetFromMap with a ConcurrentHashMap
and list its putIfAbsent call as a known safe call.

Ref: RUM-19223
Co-authored-by: aleksandr-gringauz <200633589+aleksandr-gringauz@users.noreply.github.com>
datadog-bits and others added 2 commits October 23, 2026 13:59
Ref: RUM-19223
Co-authored-by: aleksandr-gringauz <200633589+aleksandr-gringauz@users.noreply.github.com>
Keep configuration only for usages that have one; other usages are keyed
by type through an else branch.

Ref: RUM-19223
Co-authored-by: aleksandr-gringauz <200633589+aleksandr-gringauz@users.noreply.github.com>
@aleksandr-gringauz aleksandr-gringauz added the ready-for-human-review All agentic review feedback was addressed and PR is ready for the human review. label Oct 26, 2026
@0xnm 0xnm changed the title [RUM-19223] RUM-19223: Report each API usage telemetry once per SDK instance [RUM-19223] Report each API usage telemetry once per SDK instance Oct 26, 2026
satween
satween previously approved these changes Oct 26, 2026
}

private fun allDistinctApiUsageEvents(): List<InternalTelemetryEvent.ApiUsage> {
val booleans = listOf(true, false)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: could be less nested

val addViewLoadingTimeEvents = List(8) { index ->
    InternalTelemetryEvent.ApiUsage.AddViewLoadingTime(
        overwrite = (index and 0b100) == 0,
        noView = (index and 0b010) == 0,
        noActiveView = (index and 0b001) == 0
    )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bits AI ready-for-human-review All agentic review feedback was addressed and PR is ready for the human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants