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

Migrate native SDKs to v2 #523

Merged
merged 28 commits into from
Sep 21, 2023
Merged

Conversation

louiszawadzki
Copy link
Contributor

@louiszawadzki louiszawadzki commented Sep 6, 2023

What does this PR do?

Migrate native SDKs to v2.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • 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)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

@louiszawadzki louiszawadzki force-pushed the louiszawadzki/migrate-ios-sdk-v2 branch 2 times, most recently from c4a3dbf to 375636d Compare September 7, 2023 13:45
@louiszawadzki louiszawadzki marked this pull request as ready for review September 13, 2023 09:35
@louiszawadzki louiszawadzki requested a review from a team as a code owner September 13, 2023 09:35
@louiszawadzki louiszawadzki force-pushed the louiszawadzki/migrate-ios-sdk-v2 branch from 6fd80c4 to 2766f66 Compare September 14, 2023 16:16
fuzzybinary
fuzzybinary previously approved these changes Sep 15, 2023
Copy link
Member

@fuzzybinary fuzzybinary left a comment

Choose a reason for hiding this comment

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

Not gonna lie, I skimmed the changes to the main unit test files

I may come back and do a second pass on those files specifically.

@@ -53,22 +77,38 @@ internal class DatadogSDKWrapper : DatadogWrapper {
}

override fun telemetryDebug(message: String) {
Datadog._internal._telemetry.debug(message)
// Do not initialize the telemetry proxy before SDK is initialized
if (isInitialized()) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you simplify this a bit and have telemetryProxy return an optional, then move the check into that accessor? Same with webViewProxy.

@@ -274,7 +240,7 @@ class DdSdkImplementation(
}
)

_InternalProxy.setTelemetryConfigurationEventMapper(
_RumInternalProxy.setTelemetryConfigurationEventMapper(
Copy link
Member

Choose a reason for hiding this comment

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

Weird that Android kept this and iOS didn't...

@@ -7,13 +7,14 @@
package com.datadog.reactnative

import android.content.Context
import com.datadog.android.api.SdkCore
import com.datadog.android.rum.tracking.ViewTrackingStrategy

/**
* No-op implementation of the [ViewTrackingStrategy].
*/
object NoOpViewTrackingStrategy : ViewTrackingStrategy {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't NoOpViewTrackingStrategy available in the SDK now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately it's internal.

Copy link
Member

Choose a reason for hiding this comment

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

maybe we could make it public 🤔

self.mainDispatchQueue = mainDispatchQueue
self.jsDispatchQueue = jsDispatchQueue
self.jsRefreshRateMonitor = jsRefreshRateMonitor
self.RUMMonitorProvider = RUMMonitorProvider
self.RUMMonitorInternalProvider = RUMMonitorInternalProvider
Copy link
Member

Choose a reason for hiding this comment

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

Maybe worth looking into this double injections now that ._internal isn't overly specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because _internal is an extension I cannot override it from a Monitor mock, so I need to inject it as well.

Let me know if you see a good way for doing this :)

Copy link
Member

Choose a reason for hiding this comment

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

I had MockRUMMonitor extend both RUMMonitorProtocol and RUMCommandSubscriber. It's a little white-boxy, but all of the _internal methods send commands to the subscriber, so I check the correct commands get sent to the Subscriber.

Relevant code from the Flutter repo: https://github.com/DataDog/dd-sdk-flutter/blob/79b2c00d4b2fcc81a55093cdbea63f9e3c9d735c/packages/datadog_flutter_plugin/example/ios/Tests/DatadogRumPluginTests.swift#L498

That said, in order for ._internal to be able to return your mock, it requires a change I made in iOS which I don't think is in a released version yet, so... this may be moot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it's not a huge change to make the change in the tests once your change makes it in a released version, I can make it in a separate PR if that's ok with you?

@louiszawadzki louiszawadzki force-pushed the louiszawadzki/migrate-ios-sdk-v2 branch from d16840a to d77f4bb Compare September 20, 2023 07:59
@louiszawadzki louiszawadzki mentioned this pull request Sep 20, 2023
4 tasks
@louiszawadzki louiszawadzki changed the title Migrate ios sdk to v2 Migrate native SDKs to v2 Sep 20, 2023
Copy link
Member

@maciejburda maciejburda left a comment

Choose a reason for hiding this comment

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

Looking good. Probably worth upgrading to 2.2.1

Other than that left some minor comments

Comment on lines 20 to 26
s.dependency 'DatadogCore', '~> 2.2.0'
s.dependency 'DatadogLogs', '~> 2.2.0'
s.dependency 'DatadogTrace', '~> 2.2.0'
s.dependency 'DatadogRUM', '~> 2.2.0'
s.dependency 'DatadogCrashReporting', '~> 2.2.0'
s.dependency 'DatadogWebViewTracking', '~> 2.2.0'

Copy link
Member

Choose a reason for hiding this comment

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

it's 2.2.1 now :)

Comment on lines 30 to 31
if (field == null) {
if (isInitialized()) {
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to use && to join nested if statements in cases like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure this leads to a huge improvement to performance, but I think this way conveys more meaning into the order in which we want to make the checks

Copy link
Member

Choose a reason for hiding this comment

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

normally logical checks are performed left to right and if something on the left of && fails it doesn't even compute the right statement.

It's more of a pyramind of doom concern.

Comment on lines 325 to 330
configBuilder.setAdditionalConfiguration(
additionalConfig?.filterValues { it != null }?.mapValues {
it.value!!
}
?: emptyMap()
)
Copy link
Member

@maciejburda maciejburda Sep 20, 2023

Choose a reason for hiding this comment

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

might be rusty on kotlin, but I think you can avoid force unwrap this way:

configBuilder.setAdditionalConfiguration(
    additionalConfig?.mapValues {
        it?.value
    }.filterNotNull() ?: emptyMap()
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather make that change in a separate PR to avoid adding more chances to break in this one which is already pretty big if that's ok with you

@@ -7,13 +7,14 @@
package com.datadog.reactnative

import android.content.Context
import com.datadog.android.api.SdkCore
import com.datadog.android.rum.tracking.ViewTrackingStrategy

/**
* No-op implementation of the [ViewTrackingStrategy].
*/
object NoOpViewTrackingStrategy : ViewTrackingStrategy {
Copy link
Member

Choose a reason for hiding this comment

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

maybe we could make it public 🤔

Comment on lines +46 to +47
public var uploadFrequency: Datadog.Configuration.UploadFrequency
public var batchSize: Datadog.Configuration.BatchSize
Copy link
Member

Choose a reason for hiding this comment

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

we probably should keep defaults for these

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe these defaults dont make any sense since we always set these values in the init function.
Actually we should probably remove all of them, as they could be misleading and this would allow us to detect if any value is not set by accident in the init function.
Do you agree or do you see a good reason to keep them?

@testable import DatadogInternal
@testable import DatadogSDKReactNative

internal class MockRUMMonitor: RUMMonitorProtocol {
Copy link
Member

Choose a reason for hiding this comment

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

Are you generating these using stencil or something?

I leverage Sourcery for these kind of tasks. Saves some minutes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm doing it by hand, but I'll improve the toolchain on iOS in a follow-up PR before releasing v2!

@louiszawadzki louiszawadzki force-pushed the louiszawadzki/migrate-ios-sdk-v2 branch from 92f5b5e to eee8f69 Compare September 20, 2023 12:32
Copy link
Member

@maciejburda maciejburda left a comment

Choose a reason for hiding this comment

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

LGTM

@louiszawadzki louiszawadzki merged commit 1157f6d into develop Sep 21, 2023
3 checks passed
@louiszawadzki louiszawadzki deleted the louiszawadzki/migrate-ios-sdk-v2 branch September 21, 2023 11:40
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.

3 participants