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

[PC-588] 에러 로깅 추가 #66

Merged
merged 4 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
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
Binary file removed .github/ISSUE_TEMPLATE/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .github/workflows/android_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
echo "PIECE_PROD_BASE_URL=${{ secrets.PIECE_PROD_BASE_URL }}" >> local.properties
echo "GOOGLE_WEB_CLIENT_ID=${{ secrets.GOOGLE_WEB_CLIENT_ID }}" >> local.properties

- name: Create google-services.json
run: echo '${{ secrets.GOOGLE_SERVICES_JSON }}' > ./app/google-services.json

- name: Build with Gradle
run: ./gradlew assembleDebug --build-cache --stacktrace

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/android_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ jobs:
echo "PIECE_PROD_BASE_URL=${{ secrets.PIECE_PROD_BASE_URL }}" >> local.properties
echo "GOOGLE_WEB_CLIENT_ID=${{ secrets.GOOGLE_WEB_CLIENT_ID }}" >> local.properties

- name: Create google-services.json
run: echo '${{ secrets.GOOGLE_SERVICES_JSON }}' > ./app/google-services.json

- name: Build with Gradle
run: ./gradlew assembleDebug --build-cache --stacktrace

Expand Down
3 changes: 2 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
/build
google-services.json
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import java.util.Properties
plugins {
id("piece.android.application")
id("piece.android.compose")
id("com.google.firebase.crashlytics")
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package com.puzzle.build.logic

import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

internal fun Project.configureKotlinAndroid() {
pluginManager.apply("org.jetbrains.kotlin.android")
with(plugins) {
apply("org.jetbrains.kotlin.android")
apply("com.google.gms.google-services")
}

androidExtension.apply {
compileSdk = 35
Expand Down Expand Up @@ -40,6 +44,14 @@ internal fun Project.configureKotlinAndroid() {
}
}

val libs = extensions.libs
dependencies {
val bom = libs.findLibrary("firebase-bom").get()
add("implementation", platform(bom))
add("implementation", libs.findLibrary("firebase-analytics").get())
add("implementation", libs.findLibrary("firebase-crashlytics").get())
}

configureKotlin()
}

Expand Down
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ plugins {
alias(libs.plugins.android.test) apply false
alias(libs.plugins.ktlint)
alias(libs.plugins.android.library) apply false
alias(libs.plugins.google.services) apply false
alias(libs.plugins.firebase.crashlytics) apply false
}
8 changes: 8 additions & 0 deletions core/data/src/main/java/com/puzzle/data/di/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import com.puzzle.data.TokenManagerImpl
import com.puzzle.data.image.ImageResizer
import com.puzzle.data.image.ImageResizerImpl
import com.puzzle.data.repository.AuthRepositoryImpl
import com.puzzle.data.repository.ErrorRepositoryImpl
import com.puzzle.data.repository.MatchingRepositoryImpl
import com.puzzle.data.repository.ProfileRepositoryImpl
import com.puzzle.data.repository.TermsRepositoryImpl
import com.puzzle.data.repository.UserRepositoryImpl
import com.puzzle.domain.repository.AuthRepository
import com.puzzle.domain.repository.ErrorRepository
import com.puzzle.domain.repository.MatchingRepository
import com.puzzle.domain.repository.ProfileRepository
import com.puzzle.domain.repository.TermsRepository
Expand Down Expand Up @@ -54,6 +56,12 @@ abstract class DataModule {
matchingRepositoryImpl: MatchingRepositoryImpl,
): MatchingRepository

@Binds
@Singleton
abstract fun bindsErrorRepository(
errorRepositoryImpl: ErrorRepositoryImpl,
): ErrorRepository

@Binds
@Singleton
abstract fun bindsTokenManager(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.puzzle.data.repository

import com.puzzle.domain.repository.ErrorRepository
import com.puzzle.network.source.error.ErrorDataSource
import javax.inject.Inject

class ErrorRepositoryImpl @Inject constructor(
private val errorDataSource: ErrorDataSource,
) : ErrorRepository {
override suspend fun logError(exception: Throwable) = errorDataSource.logError(exception)
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.puzzle.domain.model.error

import com.puzzle.domain.repository.ErrorRepository
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ErrorHelper @Inject constructor() {
class ErrorHelper @Inject constructor(
private val errorRepository: ErrorRepository,
) {
private val _errorEvent = Channel<Throwable>(DEFAULT_BUFFER_SIZE)
val errorEvent = _errorEvent.receiveAsFlow()

fun sendError(error: Throwable) {
_errorEvent.trySend(error)
suspend fun sendError(error: Throwable) {
_errorEvent.send(error)
errorRepository.logError(error)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.puzzle.domain.repository

interface ErrorRepository {
suspend fun logError(exception: Throwable)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.puzzle.network.di

import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.puzzle.network.BuildConfig.BUILD_TYPE
import com.puzzle.network.source.auth.AuthDataSource
import com.puzzle.network.source.auth.AuthDataSourceImpl
import com.puzzle.network.source.error.DebugErrorDataSourceImpl
import com.puzzle.network.source.error.ErrorDataSource
import com.puzzle.network.source.error.ErrorDataSourceImpl
import com.puzzle.network.source.matching.MatchingDataSource
import com.puzzle.network.source.matching.MatchingDataSourceImpl
import com.puzzle.network.source.profile.ProfileDataSource
Expand All @@ -10,13 +15,15 @@ import com.puzzle.network.source.term.TermDataSource
import com.puzzle.network.source.term.TermDataSourceImpl
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Qualifier
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class NetworkModule {
abstract class NetworkBindsModule {

@Binds
@Singleton
Expand All @@ -42,3 +49,44 @@ abstract class NetworkModule {
matchingDataSourceImpl: MatchingDataSourceImpl,
): MatchingDataSource
}

@Module
@InstallIn(SingletonComponent::class)
object NetworkProvidesModule {
@Provides
@Singleton
fun provideFirebaseCrashlytics(): FirebaseCrashlytics =
FirebaseCrashlytics.getInstance()

@Provides
@Singleton
@Debug
fun provideDebugErrorDataSource(
debugErrorDataSourceImpl: DebugErrorDataSourceImpl
): ErrorDataSource = debugErrorDataSourceImpl

@Provides
@Singleton
@Release
fun provideReleaseErrorDataSource(
errorDataSourceImpl: ErrorDataSourceImpl
): ErrorDataSource = errorDataSourceImpl

@Provides
@Singleton
fun provideErrorDataSource(
@Debug debugErrorDataSource: ErrorDataSource,
@Release releaseErrorDataSource: ErrorDataSource,
Comment on lines +77 to +79
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 👍

): ErrorDataSource {
return if (BUILD_TYPE == "RELEASE") releaseErrorDataSource
else debugErrorDataSource
}
}

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class Debug

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class Release
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.puzzle.network.source.error

import android.util.Log
import javax.inject.Inject

class DebugErrorDataSourceImpl @Inject constructor() : ErrorDataSource {
override suspend fun logError(exception: Throwable) {
Log.e("DebugErrorDataSource", exception.stackTraceToString())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.puzzle.network.source.error

interface ErrorDataSource {
suspend fun logError(exception: Throwable)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.puzzle.network.source.error

import com.google.firebase.crashlytics.FirebaseCrashlytics
import javax.inject.Inject

class ErrorDataSourceImpl @Inject constructor(
private val firebaseCrashlytics: FirebaseCrashlytics,
) : ErrorDataSource {
override suspend fun logError(exception: Throwable) {
firebaseCrashlytics.recordException(exception)
}
}
Comment on lines +6 to +12
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 👍

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LoginViewModel @AssistedInject constructor(
.also { setState { copy(isLoading = false) } }
}

internal fun loginFailure(throwable: Throwable) {
internal fun loginFailure(throwable: Throwable) = viewModelScope.launch {
setState { copy(isLoading = false) }
errorHelper.sendError(throwable)
}
Expand Down
7 changes: 3 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ androidxEspresso = "3.6.1"

## firebase
googleServices = "4.4.2"
firebaseBom = "33.7.0"
crashlytics = "3.0.2"
messaging = "24.1.0"
firebaseBom = "33.9.0"
crashlytics = "3.0.3"

## OAuth
# https://developer.android.com/jetpack/androidx/releases/credentials
Expand Down Expand Up @@ -185,7 +184,7 @@ firebase-bom = { group = "com.google.firebase", name = "firebase-bom", version.r
firebase-analytics = { group = "com.google.firebase", name = "firebase-analytics" }
firebase-crashlytics = { group = "com.google.firebase", name = "firebase-crashlytics" }
firebase-config = { group = "com.google.firebase", name = "firebase-config-ktx" }
firebase-messaging = { module = "com.google.firebase:firebase-messaging", version.ref = "messaging" }
firebase-messaging = { module = "com.google.firebase:firebase-messaging" }

[bundles]

Expand Down