-
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.
Implement Log Payload Source to populate the payload.
- Loading branch information
1 parent
033a88b
commit 09e60ac
Showing
13 changed files
with
104 additions
and
57 deletions.
There are no files selected for viewing
10 changes: 5 additions & 5 deletions
10
...oid-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/LogEnvelopeSource.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 |
---|---|---|
@@ -1,23 +1,23 @@ | ||
package io.embrace.android.embracesdk.capture.envelope | ||
|
||
import io.embrace.android.embracesdk.capture.envelope.log.LogSource | ||
import io.embrace.android.embracesdk.capture.envelope.log.LogPayloadSource | ||
import io.embrace.android.embracesdk.capture.envelope.metadata.EnvelopeMetadataSource | ||
import io.embrace.android.embracesdk.capture.envelope.resource.EnvelopeResourceSource | ||
import io.embrace.android.embracesdk.internal.payload.Envelope | ||
import io.embrace.android.embracesdk.internal.payload.Log | ||
import io.embrace.android.embracesdk.internal.payload.LogPayload | ||
import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType | ||
|
||
internal class LogEnvelopeSource( | ||
private val metadataSource: EnvelopeMetadataSource, | ||
private val resourceSource: EnvelopeResourceSource, | ||
private val logSource: LogSource, | ||
) : EnvelopeSource<Log> { | ||
private val logPayloadSource: LogPayloadSource, | ||
) : EnvelopeSource<LogPayload> { | ||
|
||
override fun getEnvelope(endType: SessionSnapshotType) = Envelope( | ||
resourceSource.getEnvelopeResource(), | ||
metadataSource.getEnvelopeMetadata(), | ||
null, | ||
null, | ||
logSource.getLogPayload() | ||
logPayloadSource.getLogPayload() | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
...-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/log/LogPayloadSource.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,7 @@ | ||
package io.embrace.android.embracesdk.capture.envelope.log | ||
|
||
import io.embrace.android.embracesdk.internal.payload.LogPayload | ||
|
||
internal interface LogPayloadSource { | ||
fun getLogPayload(): LogPayload | ||
} |
16 changes: 16 additions & 0 deletions
16
.../src/main/java/io/embrace/android/embracesdk/capture/envelope/log/LogPayloadSourceImpl.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,16 @@ | ||
package io.embrace.android.embracesdk.capture.envelope.log | ||
|
||
import io.embrace.android.embracesdk.internal.logs.EmbraceLogRecordData | ||
import io.embrace.android.embracesdk.internal.logs.LogSink | ||
import io.embrace.android.embracesdk.internal.payload.LogPayload | ||
import io.embrace.android.embracesdk.internal.payload.toNewPayload | ||
|
||
internal class LogPayloadSourceImpl( | ||
private val logSink: LogSink | ||
) : LogPayloadSource { | ||
override fun getLogPayload(): LogPayload { | ||
return LogPayload( | ||
logs = logSink.completedLogs().map(EmbraceLogRecordData::toNewPayload) | ||
) | ||
} | ||
} |
7 changes: 0 additions & 7 deletions
7
...android-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/log/LogSource.kt
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...oid-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/log/LogSourceImpl.kt
This file was deleted.
Oops, something went wrong.
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
19 changes: 11 additions & 8 deletions
19
...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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package io.embrace.android.embracesdk.internal.payload | ||
|
||
import io.opentelemetry.sdk.logs.data.LogRecordData | ||
import io.embrace.android.embracesdk.internal.logs.EmbraceLogRecordData | ||
|
||
internal fun LogRecordData.toNewPayload(): Log = Log( | ||
timeUnixNano = observedTimestampEpochNanos, | ||
severityNumber = severity.severityNumber, | ||
internal fun EmbraceLogRecordData.toNewPayload(): Log = Log( | ||
timeUnixNano = timeUnixNanos, | ||
severityNumber = severityNumber, | ||
severityText = severityText, | ||
body = LogBody(body.asString()), | ||
attributes = attributes.asMap().map { (key, value) -> Attribute(key.key, value.toString()) }, | ||
traceId = spanContext.traceId, | ||
spanId = spanContext.spanId, | ||
body = LogBody(body.message), | ||
attributes = attributes.toNewPayload(), | ||
traceId = traceId, | ||
spanId = spanId, | ||
) | ||
|
||
internal fun Map<String, Any>.toNewPayload(): List<Attribute> = | ||
map { (key, value) -> Attribute(key, value.toString()) } |
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
34 changes: 34 additions & 0 deletions
34
.../test/java/io/embrace/android/embracesdk/capture/envelope/log/LogPayloadSourceImplTest.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,34 @@ | ||
package io.embrace.android.embracesdk.capture.envelope.log | ||
|
||
import io.embrace.android.embracesdk.fakes.FakeLogRecordData | ||
import io.embrace.android.embracesdk.internal.logs.LogSinkImpl | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
internal class LogPayloadSourceImplTest { | ||
|
||
private lateinit var impl: LogPayloadSourceImpl | ||
private lateinit var sink: LogSinkImpl | ||
private val fakeLog = FakeLogRecordData() | ||
|
||
@Before | ||
fun setUp() { | ||
sink = LogSinkImpl().apply { | ||
storeLogs(listOf(fakeLog)) | ||
} | ||
impl = LogPayloadSourceImpl(sink) | ||
} | ||
|
||
@Test | ||
fun getLogPayload() { | ||
val payload = impl.getLogPayload() | ||
val log = checkNotNull(payload.logs?.single()) | ||
assertEquals(1, payload.logs?.size) | ||
assertEquals(fakeLog.timestampEpochNanos, log.timeUnixNano) | ||
assertEquals(fakeLog.severityText, log.severityText) | ||
assertEquals(fakeLog.severity.severityNumber, log.severityNumber) | ||
assertEquals(fakeLog.attributes.size(), log.attributes?.size) | ||
assertEquals(fakeLog.body.asString(), log.body?.message) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeLogPayloadSource.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,11 @@ | ||
package io.embrace.android.embracesdk.fakes | ||
|
||
import io.embrace.android.embracesdk.capture.envelope.log.LogPayloadSource | ||
import io.embrace.android.embracesdk.internal.payload.LogPayload | ||
|
||
internal class FakeLogPayloadSource : LogPayloadSource { | ||
|
||
var logs: LogPayload = LogPayload() | ||
|
||
override fun getLogPayload(): LogPayload = logs | ||
} |
11 changes: 0 additions & 11 deletions
11
embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeLogSource.kt
This file was deleted.
Oops, something went wrong.
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
15 changes: 8 additions & 7 deletions
15
...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