-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c198c4
commit 68fbe61
Showing
5 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/Log.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,54 @@ | ||
package io.embrace.android.embracesdk.internal.payload | ||
|
||
import com.squareup.moshi.Json | ||
|
||
/** | ||
* A recording of an event. Typically the record includes a timestamp indicating when the event | ||
* happened, as well as other data that describes what happened, where it happened, etc. | ||
* | ||
* @param timeUnixNano The time the log was captured, in nanoseconds since the Unix epoch | ||
* @param severityNumber Numerical value of the severity, normalized to values going from 1 to 24, | ||
* where 1 is the least severe and 24 is the most severe. The ranges are as follows: 1-4: Trace, | ||
* 5-8: Debug, 9-12: Info, 13-16: Warn, 17-20: Error, 21-24: Fatal. | ||
* @param severityText Also known as log level. This is the original string representation of the | ||
* severity as it is known at the source. | ||
* @param body | ||
* @param attributes | ||
* @param traceId Request trace ID as defined in W3C Trace Context. Can be set for logs that are | ||
* part of request processing and have an assigned trace id. | ||
* @param spanId The span ID of the log. Can be set for logs that are part of a particular | ||
* processing span. If span_id is present, trace_id SHOULD be also present. | ||
*/ | ||
internal data class Log( | ||
|
||
/* The time the log was captured, in nanoseconds since the Unix epoch */ | ||
@Json(name = "time_unix_nano") | ||
val timeUnixNano: Long? = null, | ||
|
||
/* Numerical value of the severity, normalized to values going from 1 to 24, where | ||
1 is the least severe and 24 is the most severe. The ranges are as follows: 1-4: Trace, | ||
5-8: Debug, 9-12: Info, 13-16: Warn, 17-20: Error, 21-24: Fatal. */ | ||
@Json(name = "severity_number") | ||
val severityNumber: Int? = null, | ||
|
||
/* Also known as log level. This is the original string representation of the severity | ||
as it is known at the source. */ | ||
@Json(name = "severity_text") | ||
val severityText: String? = null, | ||
|
||
@Json(name = "body") | ||
val body: LogBody? = null, | ||
|
||
@Json(name = "attributes") | ||
val attributes: List<Attribute>? = null, | ||
|
||
/* Request trace ID as defined in W3C Trace Context. Can be set for logs that are part of | ||
request processing and have an assigned trace id. */ | ||
@Json(name = "trace_id") | ||
val traceId: String? = null, | ||
|
||
/* The span ID of the log. Can be set for logs that are part of a particular processing span. | ||
If span_id is present, trace_id SHOULD be also present. */ | ||
@Json(name = "span_id") | ||
val spanId: String? = null | ||
) |
15 changes: 15 additions & 0 deletions
15
embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/LogBody.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,15 @@ | ||
package io.embrace.android.embracesdk.internal.payload | ||
|
||
import com.squareup.moshi.Json | ||
|
||
/** | ||
* A value containing the body of the log record | ||
* | ||
* @param message The log message | ||
*/ | ||
internal data class LogBody( | ||
|
||
/* The log message */ | ||
@Json(name = "message") | ||
val message: String? = null | ||
) |
13 changes: 13 additions & 0 deletions
13
...ace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/LogMapper.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,13 @@ | ||
package io.embrace.android.embracesdk.internal.payload | ||
|
||
import io.opentelemetry.sdk.logs.data.LogRecordData | ||
|
||
internal fun LogRecordData.toNewPayload(): Log = Log( | ||
timeUnixNano = observedTimestampEpochNanos, | ||
severityNumber = severity.severityNumber, | ||
severityText = severityText, | ||
body = LogBody(body.asString()), | ||
attributes = attributes.asMap().map { (key, value) -> Attribute(key.key, value.toString()) }, | ||
traceId = spanContext.traceId, | ||
spanId = spanContext.spanId, | ||
) |
14 changes: 14 additions & 0 deletions
14
...ce-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/LogPayload.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,14 @@ | ||
package io.embrace.android.embracesdk.internal.payload | ||
|
||
import com.squareup.moshi.Json | ||
|
||
/** | ||
* A set of log messages sent by the user | ||
* | ||
* @param logs | ||
*/ | ||
internal data class LogPayload( | ||
Check warning on line 10 in embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/LogPayload.kt
|
||
|
||
@Json(name = "logs") | ||
val logs: List<Log>? = null | ||
Check warning on line 13 in embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/payload/LogPayload.kt
|
||
) |
24 changes: 24 additions & 0 deletions
24
...android-sdk/src/test/java/io/embrace/android/embracesdk/internal/payload/LogMapperTest.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,24 @@ | ||
package io.embrace.android.embracesdk.internal.payload | ||
|
||
import io.embrace.android.embracesdk.fakes.FakeLogRecordData | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
internal class LogMapperTest { | ||
|
||
@Test | ||
fun `convert to new payload`() { | ||
val input = FakeLogRecordData() | ||
val output = input.toNewPayload() | ||
assertEquals(input.observedTimestampEpochNanos, output.timeUnixNano) | ||
assertEquals(input.severity.severityNumber, output.severityNumber) | ||
assertEquals(input.severityText, output.severityText) | ||
assertEquals(input.body.asString(), checkNotNull(output.body).message) | ||
assertEquals(input.spanContext.traceId, output.traceId) | ||
assertEquals(input.spanContext.spanId, output.spanId) | ||
|
||
val inputMap = input.attributes.asMap().mapKeys { it.key.toString() }.mapValues { it.value.toString() } | ||
val outputMap = checkNotNull(output.attributes).associateBy { it.key }.mapValues { it.value.data } | ||
assertEquals(inputMap, outputMap) | ||
} | ||
} |