Allow DD initialization from the native side using DdSdkConfiguration
まだ誰も着手していません。
評価
- 難易度
- 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 の本文から書いたものです。
説明
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>
- 主要言語
- TypeScript
- スター
- 146
- フォーク
- 63
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 13
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
DataDog/dd-sdk-reactnative のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
DataDog/dd-sdk-reactnative#1426 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
DataDog/dd-sdk-reactnative#1377 · コメント 1 件 · リアクション 1 件 ·
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
DataDog/dd-sdk-reactnative#1353 · コメント 1 件 ·
-
enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
DataDog/dd-sdk-reactnative#1338 · コメント 2 件 ·
-
enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
DataDog/dd-sdk-reactnative#1327 ·
DataDog/dd-sdk-reactnative の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
mksglu/context-mode#1200 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
jaegertracing/jaeger-ui#4506 ·
-
area:desktop area:ui bug platform:macos
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
anthropics/claude-code#96687 ·
-
good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
AOSSIE-Org/DebateAI#582 · コメント 2 件 ·