Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Allow DD initialization from the native side using DdSdkConfiguration

オープン
#653 コメント 11 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
48/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
android, kotlin, react-native, typescript

調査の方向性

android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt と既存の initFromNative エントリーポイントから始め、ネイティブ初期化で DdSdkConfiguration がどのように渡されるかを確認します。issue で説明されている JavaScript FileBasedConfiguration と DatadogProvider の使用方法を確認します。ネイティブ起動で、リポジトリの JSON ファイルを必要とせずに実行時の DdSdkConfiguration を使用できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

enhancement
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:

  1. On application start, I initialize a new DdSdkConfiguration with settings based on runtime / build environment.
  2. Then I initialize dd-sdk-reactnative via DdSdkNativeInitialization.initFromNative with DdSdkConfiguration.
  3. I also have a native module that provides access to the current DdSdkConfiguration to the JS side (it generates datadog-configuration.json from DdSdkConfiguration).
  4. When JS side starts, I initialize DatadogProvider like this:
const config = new FileBasedConfiguration({
    configuration: NativeModules.Telemetry.datadogConfiguration(),
});

<DatadogProvider configuration={config}>{children}</DatadogProvider>
主要言語
TypeScript
スター
146
フォーク
63
平均マージ
1日 11時間
マージ済み PR(30日)
13

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

DataDog/dd-sdk-reactnative のほかの issue

DataDog/dd-sdk-reactnative の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。