Skip to content
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

Manually handle sending of crashes #43

Merged
merged 15 commits into from
Dec 18, 2024

Conversation

IeuanWalker
Copy link
Contributor

@IeuanWalker IeuanWalker commented Dec 17, 2024

Not sure if this is wanted or not, but we had a requirement that if the app crashed and the user has the analytics turned off, on the next launch, it would pop up saying the app crashed last time and then ask them if they want to enable analytics and send the report -
image
image


To achieve this I added 3 new methods, so I can manually handle the sending of the crashes -

  • bool HasCrashed();
  • Task SendCrashes();
  • void ResetCrashes();

And added 1 new property to handle the writing/ sending of the crashes -

  • bool WriteCrashes
    - This can be defaulted to true to prevent a breaking change
  • bool HandleCrashes
    - For some reason, I renamed IsTrackCrashesEnabled to HandleCrashes. This can be reverted to prevent a breaking change

What this allows me to do is have HandleCrashes (IsTrackCrashesEnabled) always set to true regardless of the users settings. So that all crashes get written to a file. And have WriteCrashes set too false, and have my own logic to send the crashes


As long as the stuff mentioned above is done, there aren't any breaking changes.

Added `HandleCrashes` and `WriteCrashes` properties to `ApplicationInsightsProvider` for better control over crash handling and reporting. Updated crash handling logic to use `HandleCrashes`. Made `SendCrashes` method public and added `HasCrashed` method. Updated `IInsights` and `IInsightsProvider` interfaces with new methods and properties. Modified `Insights` class to implement new interface methods and added logic to check and send crashes.
A new method `ResetCrashes` has been added to the `ApplicationInsightsProvider` class, changing its access modifier from private to public. The `IInsights` and `IInsightsProvider` interfaces have been updated to include the new `ResetCrashes` method. The `Insights` class has been modified to implement the `ResetCrashes` method, which iterates through all `insightsProviders` and calls their `ResetCrashes` method.
return;
}

if(!IsTrackPageViewsEnabled)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is missing, so regardless what happens to this PR, this should get added

@dhindrik
Copy link
Owner

I really like this! I added two comments on your comment.

Can you rebase against the latest code in main and make sure it works with that one too? It should, because GitHub says it can merge, but it would be great if you can to it to verify that it works as it should.

Added `HandleCrashes` and `WriteCrashes` properties to `ApplicationInsightsProvider` for better control over crash handling and reporting. Updated crash handling logic to use `HandleCrashes`. Made `SendCrashes` method public and added `HasCrashed` method. Updated `IInsights` and `IInsightsProvider` interfaces with new methods and properties. Modified `Insights` class to implement new interface methods and added logic to check and send crashes.
A new method `ResetCrashes` has been added to the `ApplicationInsightsProvider` class, changing its access modifier from private to public. The `IInsights` and `IInsightsProvider` interfaces have been updated to include the new `ResetCrashes` method. The `Insights` class has been modified to implement the `ResetCrashes` method, which iterates through all `insightsProviders` and calls their `ResetCrashes` method.
This commit focuses on enhancing the readability of the codebase by adding spaces after keywords and before parentheses in conditional statements. Key changes include:

- Standardizing formatting in the `Initialize` method and various error handling methods.
- Improving the clarity of global properties handling and telemetry client creation.
- Ensuring consistent spacing in loops and conditionals throughout the code.

These adjustments aim to maintain the existing functionality while making the code more maintainable and easier to read.
Updated `foreach` statements for consistent spacing and enhanced readability. Adjusted null check handling for the `properties` parameter in `TrackErrorAsync` to improve clarity.
Removed the `HandleCrashes` property and replaced it with `IsTrackCrashesEnabled` in both the `ApplicationInsightsProvider` class and the `IInsightsProvider` interface. Updated exception handling logic to use `IsTrackCrashesEnabled`, ensuring that crash tracking behavior remains consistent with a default value of `true`.
The property `IsTrackCrashesEnabled` was defined twice in the `ApplicationInsightsProvider` class. The duplicate definition has been removed, streamlining the code and ensuring that the property is only declared once. The remaining definition retains its default value of `true`.
Modified the code to execute `Task.Run(SendCrashes)` only when the `WriteCrashes` flag is true. This change improves performance by avoiding unnecessary crash reporting when not needed.
@IeuanWalker
Copy link
Contributor Author

@dhindrik PR updated, and tested with our app, all looks good :)

@IeuanWalker IeuanWalker changed the title Manually handling sending of crashes Manually handle sending of crashes Dec 18, 2024
@dhindrik dhindrik merged commit 968c49d into dhindrik:main Dec 18, 2024
1 check passed
@IeuanWalker IeuanWalker deleted the DynamicSettings branch December 18, 2024 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants