-
Notifications
You must be signed in to change notification settings - Fork 376
feat: tel crash reporting #2511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Adding disk-buffering to otel logging required bumping to Kotlin 2.2. Adding the code to implement this in a follow up commit.
When the app is started again we send any pending crash reports.
Also refactored crash handle classes into their own namespace. Refactored IOneSignalOpenTelemetry properties into suspend functions, as some values we want to add to all Otel requests were suspend.
Also made all otel types internal and a few other misc cleanup.
We need to start it sooner to catch crashes in things like other IStartableService's.
Models can throw if something goes wrong initializing them.
📊 Diff Coverage ReportDiff Coverage ReportThreshold: 80% Changed Files Coverage
Overall Coverage292/1558 lines covered (18.7%) ❌ Coverage Check FailedFiles below 80% threshold:
|
|
|
||
| object SdkLoggerProviderConfig { | ||
| // NOTE: Switch to https://sdklogs.onesignal.com:443/sdk/otel when ready | ||
| const val BASE_URL = "https://api.staging.onesignal.com/sdk/otel" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkasten2 we need to externalize this.
| /** | ||
| * Hardcoded error appId prefix when appId cannot be resolved. | ||
| */ | ||
| private const val ERROR_APP_ID_RESOLVE = "00000000-0000-4000-a000-000000000000" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkasten2 @jlbelmonte please check this out.
we will be adding this in the ConfigCat
Issue 1: Infinite recursion in crashApp()File: Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/application/MainApplicationKT.kt:116 This recursive call to The function calls itself immediately, so the code below (creating the date and throwing the RuntimeException) will never execute. This line should be removed. See: Lines 109 to 121 in 2cfbfba
Issue 2: Test expects wrong attribute keyFile: OneSignalSDK/onesignal/otel/src/test/java/com/onesignal/otel/attributes/OtelFieldsPerEventTest.kt:32 The test expects the attribute key Implementation (OtelFieldsPerEvent.kt:38): // Use platform-agnostic attribute name (works for both Android and iOS)
attributes["app.state"] = platformProvider.appStateTest (OtelFieldsPerEventTest.kt:32 and 49): attributes["android.app.state"] shouldBe "foreground"
attributes["android.app.state"] shouldBe "background"The test should use See:
Issue 3: Missing removeCallbacks in ANR detector stop()File: OneSignalSDK/onesignal/core/src/main/java/com/onesignal/debug/internal/crash/OtelAnrDetector.kt:148 The Before setting mainHandler.removeCallbacks(mainThreadRunnable)This ensures no callbacks execute after the ANR detector has been stopped. See: Lines 135 to 149 in 2cfbfba
Issue 4: API compatibility issue - crashes on API 21-23File: OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/time/impl/Time.kt:13 The The override val processUptimeMillis: Long
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
SystemClock.uptimeMillis() - android.os.Process.getStartUptimeMillis()
} else {
// Fallback for API < 24
// Consider using an alternative approach or returning -1 to indicate unavailable
SystemClock.uptimeMillis()
}See: Lines 10 to 14 in 2cfbfba
|
|
@jkasten2 lets try to add units tests for the newly added files so as to cover at least 80% of the code. This is a new feature that we are launching after we have added the code coverage check. Lets set a standard here. |
| logger.info("OtelCrashHandler: Uncaught exception detected - ${throwable.javaClass.simpleName}: ${throwable.message}") | ||
|
|
||
| // Check if this is an ANR exception (though standalone ANR detector already handles ANRs) | ||
| // This would only catch ANRs if they're thrown as exceptions, which is rare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abdulraqeeb33 I am not familiar with the cases where an ANR throws an exception. Can you provides details or a link to a page explaining this?
Description
One Line Summary
Logging, Crash handling using Otel
Details
Motivation
We want to be able to capture logs, crashes and ANRs - report them to our servers so that we can inspect and fix them on devices.
Scope
Major Architectural Changes and Improvements from this implementation PR
1. Platform-Agnostic Design & Dependency Reduction
OtelIdResolver- Reads OneSignal IDs directly from SharedPreferences (no service dependencies)OtelPlatformProvider- UsesOtelIdResolverinternally, removing all service dependenciescreateAndroidOtelPlatformProvider(context)- Single parameter, no services neededinitializeOtelLogging()- No longer needsIInstallIdService,ConfigModelStore,IdentityModelStore2. Initialization Consolidation
OneSignalCrashLogInitfromobjecttoclass- Manages platform provider lifecycle as instance variable3. Component Simplification
OneSignalCrashHandlerFactory- Simplified to only needContextandIOtelLoggerOtelFactory.createCrashHandler- Refactored to compose other factory methods, reducing duplicationCode Organization & Centralization
4. Constants & Utilities
AnrConstants.kt- CentralizedDEFAULT_ANR_THRESHOLD_MSandDEFAULT_CHECK_INTERVAL_MSisOneSignalAtFault()logic - Moved toOtelCrashHandler.kt(shared by crash handler and ANR detector)CONFIG_NAME_SPACE,IDENTITY_NAME_SPACEto match naming conventions (updated 77 usages across 8 files)5. Code Quality Improvements
OtelAnrDetector- Reduced complexity (LongMethod, NestedBlockDepth)@Suppressannotations where neededTest Coverage & Reliability
6. Comprehensive Test Suite
OtelIdResolverTest.kt- Comprehensive tests for all ID resolution methods with fallback scenariosOtelPlatformProviderTest.kt- Tests for platform provider properties and factory functionOneSignalCrashUploaderWrapperTest.kt- Tests for wrapper initialization and error handlingOtelIntegrationTest,CrashReportUploadTestnow use Context + SharedPreferencesOPTIONAL - Other
OPTIONAL - Feel free to add any other sections or sub-sections that can explain your PR better.
Testing
Unit testing
Lot of unit testing
Manual testing
Tested by manually crashing the app
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is