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-3103 remove global sdk core #1339

Merged
merged 8 commits into from
Mar 17, 2023

Conversation

xgouchet
Copy link
Collaborator

What does this PR do?

Remove all references to the globalSdkCore and general static fields of the Datadog class.

@xgouchet xgouchet requested review from a team as code owners March 15, 2023 16:49
@xgouchet xgouchet changed the base branch from develop to feature/sdkv2 March 15, 2023 16:49
@codecov-commenter
Copy link

codecov-commenter commented Mar 15, 2023

Codecov Report

Merging #1339 (c76c781) into feature/sdkv2 (a34ded3) will decrease coverage by 0.26%.
The diff coverage is 49.38%.

@@                Coverage Diff                @@
##           feature/sdkv2    #1339      +/-   ##
=================================================
- Coverage          81.69%   81.42%   -0.26%     
=================================================
  Files                373      373              
  Lines              13159    13139      -20     
  Branches            2201     2210       +9     
=================================================
- Hits               10749    10698      -51     
- Misses              1761     1784      +23     
- Partials             649      657       +8     
Impacted Files Coverage Δ
...n/com/datadog/android/okhttp/DatadogInterceptor.kt 70.09% <0.00%> (-2.56%) ⬇️
...in/kotlin/com/datadog/android/log/LogAttributes.kt 0.00% <ø> (ø)
...atadog/android/v2/core/internal/SdkCoreRegistry.kt 100.00% <ø> (ø)
...droid/rum/tracking/FragmentViewTrackingStrategy.kt 76.79% <0.00%> (-3.57%) ⬇️
...oid/rum/tracking/NavigationViewTrackingStrategy.kt 84.13% <0.00%> (ø)
...datadog/android/okhttp/trace/TracingInterceptor.kt 83.19% <25.00%> (-1.23%) ⬇️
.../main/kotlin/com/datadog/android/_InternalProxy.kt 68.18% <33.33%> (-3.25%) ⬇️
.../kotlin/com/datadog/android/v2/core/DatadogCore.kt 82.94% <33.33%> (-0.99%) ⬇️
.../kotlin/com/datadog/android/trace/AndroidTracer.kt 93.94% <42.86%> (-4.00%) ⬇️
.../android/core/internal/data/upload/UploadWorker.kt 72.97% <50.00%> (-14.21%) ⬇️
... and 5 more

... and 17 files with indirect coverage changes

Copy link
Contributor

@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.

nice work! I added few comments.

import com.datadog.android.v2.core.internal.net.DataUploader
import java.util.LinkedList
import java.util.Queue
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

@Suppress("DEPRECATION") // TODO RUMM-3103 remove deprecated references
internal class UploadWorker(
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't UploadWorker instance created by androidx.work library using the reflection? In this case it won't know how to inject this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh indeed that's an issue :/

val coreFeature = (Datadog.globalSdkCore as? DatadogCore)?.coreFeature
if (coreFeature != null) {
val idled = (coreFeature.persistenceExecutorService as? ThreadPoolExecutor)
if (sdkCore is InternalSdkCore) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can use force cast here instead? because if sdkCore is not InternalSdkCore by some reason (say we did some refactoring), then we won't notice the bug that sometimes crash may be not submitted (or it will be flaky and hard to debug). Throwing is ok here imo, because it is us who create SDK instances. wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Throwing an exception in the uncaughtException is a very bad practice IMHO. If there's another crash reporter around, it will report our SDK issue and not the original crash.
Maybe another option would be to have a method in the publicSdkCore that does what we want here (wait till idle or something similar).

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep it like that then, I'm not quite a fan of pulling this internal thing to the public SdkCore.

Regarding throwing an exception: my assumption is that if it is thrown, it will always be caught by our integration tests before leaking to the release, because it is us only who are creating the cores.

Copy link
Contributor

Choose a reason for hiding this comment

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

My concern is just to avoid places in the SDK where something gets unnoticed if it is not as what we expect, this can lead to the hard debugging, especially if it happens on the client side.

@xgouchet xgouchet changed the title Xgouchet/rumm 3103/remove global sdk core RUMM-3103 remove global sdk core Mar 17, 2023
@xgouchet xgouchet requested a review from 0xnm March 17, 2023 09:43
Copy link
Contributor

@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've added a comment regarding UploadWorker, so that it is not associated with default instance only.

// 2. we introduce FIFO queue also to avoid the bottleneck: if some feature batch cannot
// be uploaded we put retry task to the end of queue, so that batches of other features
// have a chance to go.
val sdkCore = Datadog.getInstance() as? InternalSdkCore
Copy link
Contributor

Choose a reason for hiding this comment

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

When we create uploadWorkRequest we can add the name of the instance it is created for and then read it here and get the instance needed.

@xgouchet xgouchet force-pushed the xgouchet/RUMM-3103/remove_globalSdkCore branch from c76c781 to 1559b91 Compare March 17, 2023 12:58
@xgouchet xgouchet merged commit 3bfe938 into feature/sdkv2 Mar 17, 2023
@xgouchet xgouchet deleted the xgouchet/RUMM-3103/remove_globalSdkCore branch March 17, 2023 13:55
@xgouchet xgouchet added this to the 2.0.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.

None yet

4 participants