Allow DD initialization from the native side using DdSdkConfiguration
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 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 的使用方式。当原生启动可以使用运行时的 DdSdkConfiguration,而不需要仓库中的 JSON 文件时,即表示完成。
由索引模型根据 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 小时
- 30 天内合并 PR
- 13
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
DataDog/dd-sdk-reactnative 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 76/100
DataDog/dd-sdk-reactnative#1426 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
DataDog/dd-sdk-reactnative#1377 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 76/100
DataDog/dd-sdk-reactnative#1353 · 1 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 3/5 1-2 天 新手友好度 58/100
DataDog/dd-sdk-reactnative#1338 · 2 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 4/5 3-5 天 新手友好度 52/100
DataDog/dd-sdk-reactnative#1327 ·
维护者通常 1 天内回复
查看 DataDog/dd-sdk-reactnative 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
opengovsg/FormSG#10118 · 1 条评论 ·
维护者通常 1 天内回复
-
ai-driven-qa bug claude
难度 1/5 1 小时以内 新手友好度 75/100
linagora/twake-calendar-frontend#1434 · 1 条评论 ·
维护者通常 1 天内回复
-
check:passed streams:add
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 半天 新手友好度 78/100
jaegertracing/jaeger-ui#4512 ·
维护者通常 1 天内回复
-
area:ide documentation enhancement platform:macos platform:vscode
难度 1/5 1-3 小时 新手友好度 88/100
anthropics/claude-code#97389 ·
维护者通常 1 天内回复