-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: re-enabled sentry error logging
- Loading branch information
1 parent
d76b270
commit e51bbac
Showing
8 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
common/src/jvmMain/kotlin/com/monta/ocpp/emulator/user/AnalyticsHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.monta.ocpp.emulator.user | ||
|
||
import io.sentry.Sentry | ||
import io.sentry.protocol.User | ||
import org.koin.core.annotation.Singleton | ||
import org.slf4j.LoggerFactory | ||
|
||
@Singleton | ||
class AnalyticsHelper( | ||
private val appUserService: AppUserService | ||
) { | ||
|
||
companion object { | ||
@JvmStatic | ||
private val logger = LoggerFactory.getLogger(AnalyticsHelper::class.java) | ||
} | ||
|
||
fun initSentry() { | ||
try { | ||
Sentry.setUser( | ||
User().apply { | ||
id = appUserService.getUserId() | ||
} | ||
) | ||
} catch (e: Exception) { | ||
logger.warn("[sentry] failed to set user", e) | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
common/src/jvmMain/kotlin/com/monta/ocpp/emulator/user/AppUserService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.monta.ocpp.emulator.user | ||
|
||
import com.monta.ocpp.emulator.configuration.AppConfigService | ||
import org.koin.core.annotation.Singleton | ||
import java.util.UUID | ||
|
||
@Singleton | ||
class AppUserService( | ||
private val appConfigService: AppConfigService | ||
) { | ||
|
||
companion object { | ||
private const val USER_ID_KEY = "user_id" | ||
} | ||
|
||
fun getUserId(): String { | ||
val userIdConfig = appConfigService.getOrCreate( | ||
key = USER_ID_KEY, | ||
defaultValue = UUID.randomUUID().toString() | ||
) | ||
return userIdConfig.value ?: UUID.randomUUID().toString() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters