Skip to content

Commit

Permalink
Merge pull request #594 from embrace-io/leandro/logs_add_framework
Browse files Browse the repository at this point in the history
Add app framework value to v2 logs
  • Loading branch information
leandro-godon committed Mar 19, 2024
2 parents 2d25a31 + 5a9813b commit c2b4ace
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.embrace.android.embracesdk.internal.logs

import io.embrace.android.embracesdk.Embrace.AppFramework
import io.embrace.android.embracesdk.LogExceptionType

internal class EmbraceLogAttributes(properties: Map<String, Any>?) {
Expand Down Expand Up @@ -43,6 +44,12 @@ internal class EmbraceLogAttributes(properties: Map<String, Any>?) {
private const val EXCEPTION_MESSAGE_ATTRIBUTE_NAME =
EMBRACE_ATTRIBUTE_NAME_PREFIX + "exception_message"

/**
* Attribute name for the app framework for a log representing an exception
*/
private const val APP_FRAMEWORK_ATTRIBUTE_NAME =
EMBRACE_ATTRIBUTE_NAME_PREFIX + "app_framework"

/**
* Attribute name for the exception context in a log representing an exception
*/
Expand Down Expand Up @@ -108,6 +115,13 @@ internal class EmbraceLogAttributes(properties: Map<String, Any>?) {
attributes[EXCEPTION_MESSAGE_ATTRIBUTE_NAME] = exceptionMessage
}

/**
* Set an app framework (native, unity, react native or flutter) for the log
*/
fun setAppFramework(framework: AppFramework) {
attributes[APP_FRAMEWORK_ATTRIBUTE_NAME] = framework.value.toString()
}

/**
* Set an exception context for the log
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ internal class EmbraceLogService(
properties: Map<String, Any>?,
stackTraceElements: Array<StackTraceElement>?,
customStackTrace: String?,
framework: AppFramework,
context: String?,
library: String?,
exceptionName: String?,
exceptionMessage: String?
) {
val attributes = EmbraceLogAttributes(properties)
attributes.setExceptionType(logExceptionType)
attributes.setAppFramework(framework)
// TBD: Add stacktrace elements
exceptionName?.let { attributes.setExceptionName(it) }
exceptionMessage?.let { attributes.setExceptionMessage(it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.embrace.android.embracesdk.internal.logs

import io.embrace.android.embracesdk.Embrace.AppFramework
import io.embrace.android.embracesdk.LogExceptionType
import io.embrace.android.embracesdk.Severity
import io.embrace.android.embracesdk.session.MemoryCleanerListener
Expand Down Expand Up @@ -30,18 +31,21 @@ internal interface LogService : MemoryCleanerListener {
* @param properties custom properties to send as part of the event
* @param stackTraceElements the stacktrace elements of a throwable
* @param customStackTrace stacktrace string for non-JVM exceptions
* @param framework the app framework (Native, Unity, etc) for the exception
* @param context context for a Dart exception from the Flutter SDK
* @param library library from a Dart exception from the Flutter SDK
* @param exceptionName the exception name of a Throwable is it is present
* @param exceptionMessage the exception message of a Throwable is it is present
*/
@Suppress("LongParameterList")
fun logException(
message: String,
severity: Severity,
logExceptionType: LogExceptionType,
properties: Map<String, Any>?,
stackTraceElements: Array<StackTraceElement>?,
customStackTrace: String?,
framework: AppFramework,
context: String?,
library: String?,
exceptionName: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ internal class EmbraceLogServiceTest {
null,
exception.stackTrace,
null,
AppFramework.NATIVE,
null,
null,
exception.javaClass.simpleName,
Expand All @@ -131,6 +132,7 @@ internal class EmbraceLogServiceTest {
assertEquals(Severity.WARNING, log.severity)
assertEquals("NullPointerException", log.attributes["emb.exception_name"])
assertEquals("exception message", log.attributes["emb.exception_message"])
assertEquals(AppFramework.NATIVE.value.toString(), log.attributes["emb.app_framework"])
assertNotNull(log.attributes["emb.log_id"])
assertEquals("session-123", log.attributes["emb.session_id"])
assertEquals("none", log.attributes["emb.exception_type"])
Expand Down Expand Up @@ -230,6 +232,7 @@ internal class EmbraceLogServiceTest {
null,
null,
"my stacktrace",
AppFramework.UNITY,
null,
null,
null,
Expand All @@ -239,6 +242,7 @@ internal class EmbraceLogServiceTest {
val log = logWriter.logEvents.single()
assertEquals("Unity".repeat(1000), log.message) // log limit higher on unity
// TBD: Assert stacktrace
assertEquals(AppFramework.UNITY.value.toString(), log.attributes["emb.app_framework"])
assertEquals(LogExceptionType.HANDLED.value, log.attributes["emb.exception_type"])
// TBD: Assert unhandled exceptions
// assertEquals(0, logMessageService.getUnhandledExceptionsSent())
Expand Down

0 comments on commit c2b4ace

Please sign in to comment.