Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cesar roman committed Jan 31, 2024
2 parents d808590 + 9cc3fe9 commit a5777c4
Show file tree
Hide file tree
Showing 95 changed files with 2,379 additions and 1,797 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
jobs:
gradle-test:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
jdk-version: ["11"]
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/functional-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ env:
jobs:
test:
runs-on: macos-latest
timeout-minutes: 45
strategy:
matrix:
jdk-version: ["11"]
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/generate_baseline_profile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
jobs:
test:
runs-on: macos-latest
timeout-minutes: 30
strategy:
matrix:
jdk-version: [ "11" ]
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
name: Publish SDK to Maven Internal
needs: [functional, baseline-profile]
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
matrix:
jdk-version: ["11"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ internal open class BaseTest {

request()
action()
startSignal.await(500, TimeUnit.MILLISECONDS)
startSignal.await(1000, TimeUnit.MILLISECONDS)
validate(file)
}

Expand Down Expand Up @@ -317,9 +317,10 @@ internal open class BaseTest {
fun readFileContent(failedApiContent: String, failedCallFileName: String) {
val failedApiFilePath = storageDir.path + "/emb_" + failedCallFileName
val failedApiFile = File(failedApiFilePath)
val failedApiJsonString: String =
failedApiFile.reader().use { it.readText() }
assertTrue(failedApiJsonString.contains(failedApiContent))
GZIPInputStream(failedApiFile.inputStream()).use { stream ->
val jsonString = String(stream.readBytes())
assertTrue(jsonString.contains(failedApiContent))
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.pm.PackageManager
import android.content.res.Resources
import android.graphics.Bitmap
import android.os.Bundle
import android.os.Debug
import android.os.Handler
import android.os.Looper
import androidx.lifecycle.Lifecycle
Expand Down Expand Up @@ -60,8 +61,12 @@ public class EmbraceContext(public val context: Context) : Application() {
activity.setContext(context)
}

val latch = FailureLatch(2000)
val pauseLatch = FailureLatch(3000)
val factor = when {
Debug.isDebuggerConnected() -> 10L
else -> 1L
}
val latch = FailureLatch(2000 * factor)
val pauseLatch = FailureLatch(3000 * factor)

// invoke Activity callbacks on the Main Thread, like it would in a real application.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ import io.embrace.android.embracesdk.internal.ApkToolsConfig
import io.embrace.android.embracesdk.network.EmbraceNetworkRequest
import io.embrace.android.embracesdk.network.http.HttpMethod
import io.embrace.android.embracesdk.recordSession
import io.embrace.android.embracesdk.spans.ErrorCode
import io.opentelemetry.api.trace.StatusCode
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
import java.net.SocketException
import java.util.concurrent.TimeUnit

/**
* Validation of the internal API
Expand Down Expand Up @@ -272,6 +276,45 @@ internal class EmbraceInternalInterfaceTest {
}
}

@Test
fun `internal tracing APIs work as expected`() {
with(testRule) {
embrace.start(harness.fakeCoreModule.context)
val sessionPayload = harness.recordSession {
with(embrace.internalInterface) {
val parentSpanId = checkNotNull(startSpan(name = "tz-parent-span"))
harness.fakeClock.tick(10)
val childSpanId = checkNotNull(startSpan(name = "tz-child-span", parentSpanId = parentSpanId))
addSpanAttribute(spanId = parentSpanId, "testkey", "testvalue")
addSpanEvent(spanId = childSpanId, name = "cool event bro", attributes = mapOf("key" to "value"))
recordSpan(name = "tz-another-span", parentSpanId = parentSpanId) { }
recordCompletedSpan(
name = "tz-old-span",
startTimeNanos = TimeUnit.MILLISECONDS.toNanos(harness.fakeClock.now() - 1),
endTimeNanos = TimeUnit.MILLISECONDS.toNanos(harness.fakeClock.now()),
)
stopSpan(spanId = childSpanId, errorCode = ErrorCode.USER_ABANDON)
stopSpan(parentSpanId)
}
}

val spans = checkNotNull(sessionPayload?.spans?.filter { it.name.startsWith("tz-") }?.associateBy { it.name })
assertEquals(4, spans.size)
with(checkNotNull(spans["tz-parent-span"])) {
assertEquals("testvalue", attributes["testkey"])
}
with(checkNotNull(spans["tz-child-span"])) {
assertEquals("cool event bro", events[0].name)
assertEquals("value", events[0].attributes["key"])
assertEquals(StatusCode.ERROR, status)
}
with(checkNotNull(spans["tz-another-span"])) {
assertEquals(spans["tz-parent-span"]?.spanId, parentSpanId)
}
assertNotNull(spans["tz-old-span"])
}
}

companion object {
private const val URL = "https://embrace.io"
private const val START_TIME = 1692201601000L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.embrace.android.embracesdk.fixtures.TOO_LONG_ATTRIBUTE_VALUE
import io.embrace.android.embracesdk.internal.spans.EmbraceSpanData
import io.embrace.android.embracesdk.recordSession
import io.embrace.android.embracesdk.returnIfConditionMet
import io.embrace.android.embracesdk.session.SessionSnapshotType
import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType
import io.embrace.android.embracesdk.spans.EmbraceSpanEvent
import io.embrace.android.embracesdk.spans.ErrorCode
import io.opentelemetry.api.trace.SpanId
Expand Down
Loading

0 comments on commit a5777c4

Please sign in to comment.