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

fix: Telemetry blocks startup when offline #2794

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
22 changes: 15 additions & 7 deletions backend/data/src/main/kotlin/io/tolgee/service/TelemetryService.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package io.tolgee.service

import io.sentry.Sentry
import io.tolgee.component.HttpClient
import io.tolgee.configuration.tolgee.TelemetryProperties
import io.tolgee.dtos.TelemetryReportRequest
import io.tolgee.util.Logging
import io.tolgee.util.logger
import jakarta.persistence.EntityManager
import org.springframework.http.HttpMethod
import org.springframework.scheduling.annotation.Scheduled
Expand All @@ -15,7 +18,7 @@ class TelemetryService(
private val entityManager: EntityManager,
private val httpClient: HttpClient,
private val telemetryProperties: TelemetryProperties,
) {
) : Logging {
companion object {
const val TELEMETRY_REPORT_PERIOD_MS = 24 * 60 * 60 * 1000L
}
Expand All @@ -27,12 +30,17 @@ class TelemetryService(
val data: TelemetryReportRequest = getTelemetryData()
if (data.projectsCount == 0L) return
if (data.usersCount == 0L) return
httpClient.requestForJson(
"${telemetryProperties.server}/v2/public/telemetry/report",
data,
HttpMethod.POST,
Unit::class.java,
)
try {
httpClient.requestForJson(
"${telemetryProperties.server}/v2/public/telemetry/report",
data,
HttpMethod.POST,
Unit::class.java,
)
} catch (e: Throwable) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
} catch (e: Throwable) {
} catch (e: Exception) {

Catch exception only. Catching errors as well is probably a bad idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noob question... but... Why is it bad idea? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is usually discouraged because it is generally impossible to recover from such errors programmatically anyway, and ignoring them (by catching them) only makes the issue worse. See: https://stackoverflow.com/a/2274130.

Sentry.captureException(e)
logger.error("Cannot send telemetry data", e)
}
}

private fun getTelemetryData(): TelemetryReportRequest {
Expand Down
Loading