Skip to content

Diagnostics: Add jsonl file management for diagnostics#784

Merged
tonidero merged 1 commit into
diagnosticsfrom
diagnostics-jsonl-file-management
Feb 15, 2023
Merged

Diagnostics: Add jsonl file management for diagnostics#784
tonidero merged 1 commit into
diagnosticsfrom
diagnostics-jsonl-file-management

Conversation

@tonidero

@tonidero tonidero commented Feb 9, 2023

Copy link
Copy Markdown
Contributor

Description

Based on #783, this PR adds the logic to store and read JSONL files with the events we want to send to the backend.

This has been extracted from #766 and #771

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note that all these need to be synchronized. The idea is that all this code executes in a single background thread with a lower priority than other threads. To avoid race conditions, all these should run in that same thread.

@tonidero tonidero changed the title Add jsonl file management for diagnostics Diagnostics: Add jsonl file management for diagnostics Feb 9, 2023
@tonidero tonidero marked this pull request as ready for review February 9, 2023 15:11
@tonidero tonidero requested a review from a team February 9, 2023 15:11
@tonidero tonidero force-pushed the diagnostics-jsonl-file-management branch from e77f081 to 313ca01 Compare February 9, 2023 15:24
@codecov

codecov Bot commented Feb 9, 2023

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (diagnostics@8bc860c). Click here to learn what that means.
The diff coverage is n/a.

@@              Coverage Diff               @@
##             diagnostics     #784   +/-   ##
==============================================
  Coverage               ?   81.83%           
==============================================
  Files                  ?      125           
  Lines                  ?     4084           
  Branches               ?      517           
==============================================
  Hits                   ?     3342           
  Misses                 ?      536           
  Partials               ?      206           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Base automatically changed from diagnostics-events to diagnostics February 10, 2023 11:11
@tonidero tonidero force-pushed the diagnostics-jsonl-file-management branch from 313ca01 to b5e7f30 Compare February 10, 2023 11:12

@aboedo aboedo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:chefskiss:

Comment on lines +7 to +10
/**
* All methods in this file should be executed within the diagnostics thread to ensure there are no threading issues.
*/
class DiagnosticsFileHelper(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it'd be so nice to be able to use actors here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In iOS you mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think so yeah. And yeah, we don't have that in Android 😢

appendToFile(filePath, textToAppend)
}

fun fileIsEmpty(filePath: String): Boolean {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might be useful to document that this also returns true if the file doesn't exist.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, merged this without pushing this. Added it to the diagnostics branch though: 74d6c21

Comment on lines +7 to +10
/**
* All methods in this file should be executed within the diagnostics thread to ensure there are no threading issues.
*/
class DiagnosticsFileHelper(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In iOS you mean?

@Synchronized
fun deleteDiagnosticsFile() {
if (!fileHelper.deleteFile(DIAGNOSTICS_FILE_PATH)) {
verboseLog("Failed to delete diagnostics file.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be a warning instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I made all logs for diagnostics verbose, to not pollute the normal logs. Lmk if you think we should still send these as warnings/errors though, I'm not opposed to either approach.


private lateinit var applicationContext: Context

private lateinit var fileHelper: FileHelper

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd pay money to have lateinit in Swift

@tonidero tonidero merged commit f608016 into diagnostics Feb 15, 2023
@tonidero tonidero deleted the diagnostics-jsonl-file-management branch February 15, 2023 08:19
vegaro added a commit to RevenueCat/purchases-ios that referenced this pull request Apr 8, 2024
Based off #2672

Equivalent to RevenueCat/purchases-android#784

Adds DiagnosticsEntry classes and implements adding an entry to the
file, getting all entries, and deleting X first entries
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.

3 participants