Allow DD initialization from the native side using DdSdkConfiguration
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- android, kotlin, react-native, typescript
- Domain
- developer-experience, mobile-dev
Research direction
Start with android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt and the existing initFromNative entry point, then read how DdSdkConfiguration is passed through native initialization. Review the JavaScript FileBasedConfiguration and DatadogProvider usage described in the issue. Done means native startup can use a runtime DdSdkConfiguration without requiring a repository JSON file.
Written by the indexing model from the issue text.
Description
Feature description
Hello! We have an app with a lot of native code that initializes before the JS side and runs in the background. The native code needs the ability to send logs to DD, and so the SDK must be initialized on application start.
Recently dd-sdk-reactnative added the new DdSdkNativeInitialization.initFromNative API to load configuration from JSON file. Unfortunately, it is a bit limiting since JSON configurations need to be stored in the repo, and it doesn't support environment variables or build environments.
Proposed solution
It would be nice to be able to init dd-sdk-reactnative with just DdSdkConfiguration instance. That would fix the limitations since we can generate it in the runtime using BuildConfig for tokens.
Here is the patch I ended up with:
diff --git a/node_modules/@datadog/mobile-react-native/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt b/node_modules/@datadog/mobile-react-native/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt
index 1b352a1..d6e6028 100644
--- a/node_modules/@datadog/mobile-react-native/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt
+++ b/node_modules/@datadog/mobile-react-native/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt
@@ -345,6 +345,24 @@ class DdSdkNativeInitialization internal constructor(
)
}
}
+
+ /**
+ * Initializes the Datadog React Native SDK using the provided configuration.
+ */
+ @JvmStatic
+ fun initFromNative(appContext: Context, ddSdkConfiguration: DdSdkConfiguration) {
+ val nativeInitialization = DdSdkNativeInitialization(appContext.applicationContext)
+ try {
+ nativeInitialization.initialize(ddSdkConfiguration)
+ } catch (@Suppress("TooGenericExceptionCaught") error: Exception) {
+ Log.w(
+ DdSdkNativeInitialization::class.java.canonicalName,
+ "Failed to initialize the Datadog SDK: $error"
+ )
+ }
+ }
}
}
Alternatively, making internal constructor public also works.
Other relevant information
For more context, this is how my whole setup works:
- On application start, I initialize a new
DdSdkConfigurationwith settings based on runtime / build environment. - Then I initialize dd-sdk-reactnative via
DdSdkNativeInitialization.initFromNativewithDdSdkConfiguration. - I also have a native module that provides access to the current
DdSdkConfigurationto the JS side (it generatesdatadog-configuration.jsonfromDdSdkConfiguration). - When JS side starts, I initialize
DatadogProviderlike this:
const config = new FileBasedConfiguration({
configuration: NativeModules.Telemetry.datadogConfiguration(),
});
<DatadogProvider configuration={config}>{children}</DatadogProvider>
- Dominant language
- TypeScript
- Stars
- 146
- Forks
- 63
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 13
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DataDog/dd-sdk-reactnative
-
Difficulty 3/5 1-2 days Newbie friendliness 76/100
DataDog/dd-sdk-reactnative#1426 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
DataDog/dd-sdk-reactnative#1377 · 1 comment · 1 reaction ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 76/100
DataDog/dd-sdk-reactnative#1353 · 1 comment ·
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 58/100
DataDog/dd-sdk-reactnative#1338 · 2 comments ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 52/100
DataDog/dd-sdk-reactnative#1327 ·
All issues in DataDog/dd-sdk-reactnative
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
vercel-labs/just-bash#464 ·
-
looksLikeSlug() is ASCII-only, so non-Latin entity slugs (e.g. Korean) skip exact match and collapse Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
TanStack/tanstack.com#1293 ·