Repository navigation
Conversation
Tracing headers for first-party requests read the Datadog context through DatadogSdkPlugin.getCoreContext(), which waited with no timeout for the SDK's single context thread. That thread also processes RUM events, so on slow devices the wait from the Flutter UI thread could exceed the ANR threshold. getCoreContext() now uses CoreContextReader, which runs the read on a background thread, waits at most 100 ms, and otherwise returns the last context it read. Only one read runs at a time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5db958c46f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } catch (e: TimeoutException) { | ||
| lastKnownContext |
There was a problem hiding this comment.
Invalidate cached identities when user/account information changes
After an identified context has been cached, calling clearUserInfo() or clearAccountInfo() and then making a first-party request whose context read exceeds 100 ms still returns the pre-clear IDs here. The native clear handlers only update Datadog; they never invalidate this reader. The Dart tracing path subsequently passes those cached IDs to mergeW3CBaggageHeader(), so requests with baggage propagation enabled can continue sending a logged-out user's user.id or cleared account.id. This violates the clear APIs' documented guarantee that following traces omit that information. Invalidate or sanitize cached identity fields on these mutations, and prevent an older in-flight read from restoring them.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The timeout fallback can resend cleared user and account IDs in tracing baggage after logout or an account switch, violating the clearing APIs’ documented behavior.
🤖 Bits Code Review · Commit 5db958c
| return try { | ||
| pendingRead.get(timeoutMs, TimeUnit.MILLISECONDS) | ||
| } catch (e: TimeoutException) { | ||
| lastKnownContext |
There was a problem hiding this comment.
Invalidate cleared identities before reusing cached context
After a successful context read, clearUserInfo() and clearAccountInfo() update the SDK without invalidating this cache. If a later context read exceeds 100 ms, the fallback returns the cleared IDs. AndroidDatadogFlutterPlugin.getContext() passes them through to tracing baggage, so requests after logout or an account switch can propagate the previous identity, contrary to the clearing APIs’ documented behavior. Invalidate cached identities when they change and prevent older in-flight reads from restoring them, or omit identity fields from fallback contexts. This requires coordinated cache, API-handler, and test changes.
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
When several first-party requests start together, each one reads the context on the UI thread. After one read times out, later reads now return the last known context straight away until that read finishes, so a stalled read costs at most one wait instead of one per request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SDK applies user and account changes on the context thread, so when that thread is behind, an earlier context can still hold a user or account that has since been cleared. A caller now gets user and account IDs only from a read it started and that finished in time. Fallbacks keep the RUM context but remove user and account information. A caller that arrives while a read is in progress now gets the fallback without waiting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
More details
The PR caps Android tracing-context waits at 100 ms and returns immediately when another read is pending, preserving cached RUM context for fallback. The latest update removes user/account information from every fallback, fixing the earlier cleared-identity propagation issue; no findings remain open.
🤖 Bits Code Review · Commit 4f5a2aa
What and why?
On Android, apps can freeze with an "App Not Responding" (ANR) error when they send
requests to a first-party host:
the tracing headers.
one at a time.
thread is still waiting, so Android reports an ANR.
Why the fix is in the plugin: an ANR needs a busy SDK thread and a main thread
waiting on it. A busy SDK thread alone doesn't freeze the app. Native Android code never waits
on it from the main thread, and in testing a request to a host that isn't first-party didn't
freeze even with the SDK thread held for 6 s. So this PR limits the wait.
How?
getCoreContext()now goes through a newCoreContextReader. It asks the SDK on abackground thread and waits at most 100 ms for the answer.
What the request gets:
Two more rules:
don't wait. They use the session ID from the earlier answer right away (no user or account
IDs), so many requests started at once cost one 100 ms wait, not one each.
same busy thread, so an earlier answer can still hold a user who has since logged out. This
keeps the
clearUserInfo/clearAccountInfopromise that later traces won't includethem, including when the change was made from native code.
The method signature doesn't change, so the Dart code and generated bindings stay the same.
The iOS plugin also avoids waiting on the SDK, by keeping a cached context.
Trade-offs
These only apply while the SDK thread is more than 100 ms behind:
the
baggageheader.and the trace is sampled on its own instead of with its session.
requests use the previous session ID until the SDK catches up.
native Android tracing integration waits up to 1 s, but off the main thread. Happy to
change it or make it configurable.
Testing
CoreContextReaderTest: normal read, timeouts, fallback without userand account IDs, one request at a time, no waiting while a read is in progress, recovery,
failures, the SDK being stopped, and removing user and account from a real context.
Related, outside this PR
This PR fixes the freeze by itself. These changes would make the SDK thread faster and could
be raised with the Android SDK team:
InternalSdkCore.getDatadogContextFuture(). It's on the Android SDK'sdevelopbranch and would let callers set their own time limit. This plugin could then use it and
drop its own thread.
SecureRandomin internal log sampling.SdkInternalLogger.sample()createsa new one on every call, which can be slow on low-end devices and runs on the same queue.
it's fully processed, which is why a burst at launch delays every read. This is a larger
design change.
A batch
addFeatureFlagEvaluationsAPI in Flutter, which Android already has, would alsoshorten the queue.
Review checklist
🤖 Generated with Claude Code