Allow DD initialization from the native side using DdSdkConfiguration
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- android, kotlin, react-native, typescript
- Lĩnh vực
- developer-experience, mobile-dev
Hướng nghiên cứu
Bắt đầu với android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt và entry point initFromNative hiện có, sau đó xem cách DdSdkConfiguration được truyền qua quá trình khởi tạo native. Xem lại cách sử dụng JavaScript FileBasedConfiguration và DatadogProvider được mô tả trong issue. Công việc được xem là hoàn tất khi quá trình khởi động native có thể sử dụng DdSdkConfiguration trong runtime mà không yêu cầu tệp JSON trong repository.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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>
- Ngôn ngữ chính
- TypeScript
- Star
- 146
- Fork
- 63
- Merge trung bình
- 1 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 13
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của DataDog/dd-sdk-reactnative
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 76/100
DataDog/dd-sdk-reactnative#1426 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
DataDog/dd-sdk-reactnative#1377 · 1 bình luận · 1 reaction ·
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 76/100
DataDog/dd-sdk-reactnative#1353 · 1 bình luận ·
-
enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
DataDog/dd-sdk-reactnative#1338 · 2 bình luận ·
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
DataDog/dd-sdk-reactnative#1327 ·
Tất cả issue của DataDog/dd-sdk-reactnative
Issue tương tự
-
VerificationGate: ATTRIBUTION quote guard never matches a normal quotation (\b around the quote) Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
danielmiessler/LifeOS#2234 ·
-
T: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
Mend: dependency security vulnerability untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100