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

Ignore all failures while uploading analytics data #1858

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 39 additions & 33 deletions maestro-cli/src/main/java/maestro/cli/analytics/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,49 +113,55 @@ object Analytics {
* Uploads analytics if there was a version update.
*/
fun maybeUploadAnalyticsAsync() {
if (!hasRunBefore) {
logger.trace("First run, not uploading")
return
}
try {
if (!hasRunBefore) {
logger.trace("First run, not uploading")
return
}

if (analyticsDisabledWithEnvVar) {
logger.trace("Analytics disabled with env var, not uploading")
}
if (analyticsDisabledWithEnvVar) {
logger.trace("Analytics disabled with env var, not uploading")
}

if (!analyticsState.enabled) {
logger.trace("Analytics disabled with config file, not uploading")
return
}
if (!analyticsState.enabled) {
logger.trace("Analytics disabled with config file, not uploading")
return
}

if (!uploadConditionsMet) {
logger.trace("Upload conditions not met, not uploading")
return
}
if (!uploadConditionsMet) {
logger.trace("Upload conditions not met, not uploading")
return
}

val report = AnalyticsReport(
uuid = analyticsState.uuid,
freshInstall = !hasRunBefore,
cliVersion = EnvUtils.CLI_VERSION?.toString() ?: "Unknown",
os = EnvUtils.OS_NAME,
osArch = EnvUtils.OS_ARCH,
osVersion = EnvUtils.OS_VERSION,
javaVersion = EnvUtils.getJavaVersion().toString(),
xcodeVersion = IOSEnvUtils.xcodeVersion,
flutterVersion = EnvUtils.getFlutterVersionAndChannel().first,
flutterChannel = EnvUtils.getFlutterVersionAndChannel().second,
androidVersions = AndroidEnvUtils.androidEmulatorSdkVersions,
iosVersions = IOSEnvUtils.simulatorRuntimes,
)
val report = AnalyticsReport(
uuid = analyticsState.uuid,
freshInstall = !hasRunBefore,
cliVersion = EnvUtils.CLI_VERSION?.toString() ?: "Unknown",
os = EnvUtils.OS_NAME,
osArch = EnvUtils.OS_ARCH,
osVersion = EnvUtils.OS_VERSION,
javaVersion = EnvUtils.getJavaVersion().toString(),
xcodeVersion = IOSEnvUtils.xcodeVersion,
flutterVersion = EnvUtils.getFlutterVersionAndChannel().first,
flutterChannel = EnvUtils.getFlutterVersionAndChannel().second,
androidVersions = AndroidEnvUtils.androidEmulatorSdkVersions,
iosVersions = IOSEnvUtils.simulatorRuntimes,
)

logger.trace("Will upload analytics report")
logger.trace(report.toString())
logger.trace("Will upload analytics report")
logger.trace(report.toString())

try {
ApiClient(EnvUtils.BASE_API_URL).sendAnalyticsReport(report)
updateAnalyticsState()
} catch (e: ConnectException) {
// This is fine. We don't care that much about analytics to bug user about it.
// This is fine. The user probably doesn't have internet connection.
// We don't care that much about analytics to bug user about it.
return
} catch (e: Exception) {
// This is less fine. Don't crash, but ask the user to report this.
println("Exception ocurred while uploading analytics. This is not a fatal issue, but we ask you to report it.")
println(e.message)
println(e.stackTraceToString())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we want to print it on cli?

I don't think this would have any meaning for user. For us yes then maybe log this in maestro.log or some log file instead.

Copy link
Contributor Author

@bartekpacia bartekpacia Jul 31, 2024

Choose a reason for hiding this comment

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

We want to make sure analytics data is flowing to us. If we will just swallow the exception, we will never learn if we silently break sth in analytics.

So far the only known issue w.r.t analytics is #1850 (which will be fixed by this PR), so I don't expect this to cause a lot of noise.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't really see value of showing this to user. Maybe there is a better option to provide this observability then?

Users don't really care about analytics, we do. So, maybe we opt another way for this observability WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the best solution would be to connect Sentry (or any other log reporting service)? That would be a lot of work though.

Actually, we already have an ErrorReporter. I just took a look at BigQuery, and it looks pretty solid. (query link - internal only)

The problem is that we don't wrap our whole app with the ErrorReporter, so not all errors are reported. This is a separate issue though.

For now I agree with you, let's remove this message for the good of our users.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes you can create a separate issue for this. Its definitely useful though!

}
}

Expand Down