Skip to content

RUM-9940: Make getDatadogContext read on the context thread#2645

Merged
0xnm merged 1 commit into
nogorodnikov/rum-8170/feature-context-syncfrom
nogorodnikov/rum-9940/return-datadog-context-on-context-thread
May 14, 2025
Merged

RUM-9940: Make getDatadogContext read on the context thread#2645
0xnm merged 1 commit into
nogorodnikov/rum-8170/feature-context-syncfrom
nogorodnikov/rum-9940/return-datadog-context-on-context-thread

Conversation

@0xnm

@0xnm 0xnm commented May 13, 2025

Copy link
Copy Markdown
Member

What does this PR do?

This PR makes DatadogCore.getDatadogContext call read DatadogContext on the context thread in the blocking manner to align with context changes.

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)

@0xnm
0xnm requested review from a team as code owners May 13, 2025 09:45
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented May 13, 2025

Copy link
Copy Markdown

Datadog Summary

✅ Code Quality    ✅ Code Security    ✅ Dependencies


Was this helpful? Give us feedback!

@0xnm
0xnm force-pushed the nogorodnikov/rum-9940/return-datadog-context-on-context-thread branch from f5803d3 to ae8aedd Compare May 13, 2025 09:58
@codecov-commenter

codecov-commenter commented May 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.62500% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.07%. Comparing base (a3206f3) to head (ae8aedd).
⚠️ Report is 186 commits behind head on nogorodnikov/rum-8170/feature-context-sync.

Files with missing lines Patch % Lines
...adog/android/core/internal/utils/ConcurrencyExt.kt 65.22% 8 Missing ⚠️
...n/com/datadog/android/core/internal/DatadogCore.kt 40.00% 3 Missing ⚠️
Additional details and impacted files
@@                              Coverage Diff                               @@
##           nogorodnikov/rum-8170/feature-context-sync    #2645      +/-   ##
==============================================================================
- Coverage                                       70.09%   70.07%   -0.02%     
==============================================================================
  Files                                             819      819              
  Lines                                           30615    30611       -4     
  Branches                                         5111     5111              
==============================================================================
- Hits                                            21458    21449       -9     
+ Misses                                           7742     7740       -2     
- Partials                                         1415     1422       +7     
Files with missing lines Coverage Δ
...in/com/datadog/android/core/internal/SdkFeature.kt 91.67% <100.00%> (+2.10%) ⬆️
...roid/core/internal/user/DatadogUserInfoProvider.kt 100.00% <ø> (ø)
...n/com/datadog/android/core/internal/DatadogCore.kt 82.40% <40.00%> (+1.10%) ⬆️
...adog/android/core/internal/utils/ConcurrencyExt.kt 86.21% <65.22%> (-13.79%) ⬇️

... and 29 files with indirect coverage changes

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

override fun getDatadogContext(): DatadogContext? {
return contextProvider?.context
return coreFeature.contextExecutorService
.submitSafe("getDatadogContext", internalLogger, Callable { contextProvider?.context })

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.

is this going to block if the queue is not ready ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it will. This call is blocking on purpose.

internal val dataWriter: DataWriter<UserInfo>
) : MutableUserInfoProvider {

@Volatile

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.

shouldn't this be atomic instead ? Volatile only guarantees the visibility between 2 threads.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There is no difference between AtomicReference.get / AtomicReference.set usage and volatile modifier usage (link). There is a difference in case of CAS usage, but it is not needed here.

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.

Should things like CoreFeature.clientToken link become volatile as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the thing to address in the future PRs, but so far it is good without it, because it is used only in the upload cycle which is scheduled only few seconds after SDK is initialized (-> when CoreFeature gets clientToken set).

And it is reset to empty string only when SDK is stopped anyway.

Overall I will align the properties used in the DatadogContext creation later.

@0xnm
0xnm requested a review from mariusc83 May 13, 2025 14:50
@0xnm
0xnm merged commit 4431985 into nogorodnikov/rum-8170/feature-context-sync May 14, 2025
@0xnm
0xnm deleted the nogorodnikov/rum-9940/return-datadog-context-on-context-thread branch May 14, 2025 08:36
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