-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] Firebase Performance Monitoring 추가 #117
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
Open
ikseong00
wants to merge
4
commits into
develop
Choose a base branch
from
feat/firebase-performance
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import com.kuit.findu.presentation.type.HomeReportDurationType | |
| import com.kuit.findu.presentation.type.HomeUserStatusType | ||
| import com.kuit.findu.presentation.type.view.LoadState | ||
| import com.kuit.findu.presentation.util.Nickname.GUEST_NAME | ||
| import com.google.firebase.perf.FirebasePerformance | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import kotlinx.coroutines.channels.Channel | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
|
|
@@ -137,8 +138,14 @@ class HomeViewModel @Inject constructor( | |
| private fun loadHomeData() { | ||
| viewModelScope.launch { | ||
| _uiState.update { it.copy(loadState = LoadState.Loading) } | ||
| val trace = FirebasePerformance.getInstance().newTrace("home_data_load") | ||
| trace.start() | ||
| homeUseCase().fold( | ||
| onSuccess = { data -> | ||
| trace.putAttribute("status", "success") | ||
| trace.putMetric("protect_animal_count", data.protectAnimalCards.size.toLong()) | ||
| trace.putMetric("report_animal_count", data.reportAnimalCards.size.toLong()) | ||
| trace.stop() | ||
|
Comment on lines
+141
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코루틴 취소 시 trace가 stop되지 않을 수 있습니다.
🛡️ 제안하는 수정 _uiState.update { it.copy(loadState = LoadState.Loading) }
val trace = FirebasePerformance.getInstance().newTrace("home_data_load")
trace.start()
- homeUseCase().fold(
- onSuccess = { data ->
- trace.putAttribute("status", "success")
- trace.putMetric("protect_animal_count", data.protectAnimalCards.size.toLong())
- trace.putMetric("report_animal_count", data.reportAnimalCards.size.toLong())
- trace.stop()
+ try {
+ homeUseCase().fold(
+ onSuccess = { data ->
+ trace.putAttribute("status", "success")
+ trace.putMetric("protect_animal_count", data.protectAnimalCards.size.toLong())
+ trace.putMetric("report_animal_count", data.reportAnimalCards.size.toLong())
+ trace.stop()
...
- onFailure = { error ->
- trace.putAttribute("status", "failure")
- trace.stop()
+ onFailure = { error ->
+ trace.putAttribute("status", "failure")
+ trace.stop()
...
- )
+ )
+ } catch (e: Exception) {
+ trace.putAttribute("status", "cancelled")
+ trace.stop()
+ throw e
+ }🤖 Prompt for AI Agents |
||
| _uiState.update { | ||
| it.copy( | ||
| loadState = LoadState.Success, | ||
|
|
@@ -148,6 +155,8 @@ class HomeViewModel @Inject constructor( | |
| } | ||
| }, | ||
| onFailure = { error -> | ||
| trace.putAttribute("status", "failure") | ||
| trace.stop() | ||
| Log.e("HomeViewModel", "loadHomeData: $error") | ||
| if(error.message?.contains("401") == true) { | ||
| _uiEffect.send(HomeUiEffect.NavigateToLogin) | ||
|
|
||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remember블록 안에서 trace를 생성하면 재사용 시 문제가 될 수 있습니다.remember(animal.thumbnailImageUrl)블록 안에서 trace 객체가 생성됩니다. Coil이 캐시에서 이미지를 로드하면onStart→onSuccess가 빠르게 호출되어 정상 동작하지만, 만약 같은 composable이 LazyList에서 재활용되면서 동일 URL로 재구성될 경우,remember가 캐시된ImageRequest를 반환하므로 이미stop()된 trace에 대해 다시start()가 호출될 수 있습니다.대부분의 경우 문제가 없겠지만, 안전하게 하려면 trace 생성을 listener 내부로 이동하거나, 매 요청마다 새 trace를 생성하는 구조를 고려해 보세요.
🤖 Prompt for AI Agents