forked from open-telemetry/opentelemetry-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the current screen name to crash events (open-telemetry#704)
* move SessionIdLogRecordAppender.kt into internal package * fix test * add screen appender log processor * wire up to builder and fix tests * spotless
- Loading branch information
1 parent
56dbb88
commit c10adba
Showing
6 changed files
with
79 additions
and
5 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
22 changes: 22 additions & 0 deletions
22
...n/java/io/opentelemetry/android/internal/processors/ScreenAttributesLogRecordProcessor.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,22 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.internal.processors | ||
|
||
import io.opentelemetry.android.common.RumConstants | ||
import io.opentelemetry.android.internal.services.visiblescreen.VisibleScreenService | ||
import io.opentelemetry.context.Context | ||
import io.opentelemetry.sdk.logs.LogRecordProcessor | ||
import io.opentelemetry.sdk.logs.ReadWriteLogRecord | ||
|
||
class ScreenAttributesLogRecordProcessor(val visibleScreenService: VisibleScreenService) : LogRecordProcessor { | ||
override fun onEmit( | ||
context: Context, | ||
logRecord: ReadWriteLogRecord, | ||
) { | ||
val currentScreen = visibleScreenService.currentlyVisibleScreen | ||
logRecord.setAttribute(RumConstants.SCREEN_NAME_KEY, currentScreen) | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
...va/io/opentelemetry/android/internal/processors/ScreenAttributesLogRecordProcessorTest.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,30 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.internal.processors | ||
|
||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import io.opentelemetry.android.common.RumConstants.SCREEN_NAME_KEY | ||
import io.opentelemetry.android.internal.services.visiblescreen.VisibleScreenService | ||
import io.opentelemetry.api.common.AttributeKey | ||
import io.opentelemetry.sdk.logs.ReadWriteLogRecord | ||
import org.junit.Test | ||
|
||
private const val CURRENT_SCREEN = "party favors" | ||
|
||
class ScreenAttributesLogRecordProcessorTest { | ||
@Test | ||
fun `current screen name is appended`() { | ||
val visibleScreenService: VisibleScreenService = mockk() | ||
val logRecord: ReadWriteLogRecord = mockk() | ||
every { visibleScreenService.currentlyVisibleScreen }.returns(CURRENT_SCREEN) | ||
every { logRecord.setAttribute(any<AttributeKey<String>>(), any<String>()) } returns logRecord | ||
val testClass = ScreenAttributesLogRecordProcessor(visibleScreenService) | ||
testClass.onEmit(mockk(), logRecord) | ||
verify { logRecord.setAttribute(SCREEN_NAME_KEY, CURRENT_SCREEN) } | ||
} | ||
} |
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