Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def getExtOrIntegerDefault(name) {

// Test mode is a build flag, never API: -PotelTestMode=true (or otelTestMode=true in the app's gradle.properties).
def otelTestMode = (findProperty("otelTestMode") ?: "false").toString() == "true"
// telemetry.distro.version = the npm package version
def otelDistroVersion = new groovy.json.JsonSlurper().parse(file("../package.json")).version

android {
namespace "com.margelo.nitro.callstack.otel"
Expand All @@ -29,6 +31,9 @@ android {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
buildConfigField "boolean", "OTEL_TEST_MODE", otelTestMode.toString()
buildConfigField "String", "OTEL_DISTRO_VERSION", "\"${otelDistroVersion}\""
// apps that minify (Expo's release default) need these
consumerProguardFiles "consumer-rules.pro"

externalNativeBuild {
cmake {
Expand All @@ -47,6 +52,11 @@ android {
cmake { path "CMakeLists.txt" }
}

// the pure Kotlin core (also compiled and tested on the JVM by android/core-jvm)
sourceSets {
main { java.srcDirs += "src/core/kotlin" }
}

packagingOptions {
excludes = [
"META-INF",
Expand Down Expand Up @@ -95,8 +105,12 @@ repositories {
dependencies {
implementation "com.facebook.react:react-android"
implementation project(":react-native-nitro-modules")
// ProcessLifecycleOwner: background flush on ON_STOP (same version React Native already resolves)
implementation "androidx.lifecycle:lifecycle-process:2.6.2"

implementation platform("io.opentelemetry:opentelemetry-bom:1.68.0")
// RNOtel's public signatures expose Tracer, Span and Context: the API is part of ours
api platform("io.opentelemetry:opentelemetry-bom:1.68.0")
api "io.opentelemetry:opentelemetry-api"
implementation "io.opentelemetry:opentelemetry-sdk"
// The OkHttp sender runs on React Native's own OkHttp (every okhttp3 member the 1.68 sender uses exists in 4.9.2);
// excluding it keeps otel-java from pulling the app up to OkHttp 5.
Expand Down
11 changes: 11 additions & 0 deletions android/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Guarded by the minified Expo release e2e (Task 28): recheck these rules on every otel-java bump.
# otel-java references optional, compile-only classes it never loads at runtime here (no autoconfigure, no incubator,
# annotations only); R8 in a minifying app fails on them as missing.
-dontwarn com.google.auto.value.**
-dontwarn com.google.errorprone.annotations.**
-dontwarn io.opentelemetry.api.incubator.**
-dontwarn io.opentelemetry.sdk.autoconfigure.spi.**

# otel-java's ResourceMarshaler reaches Resource/ResourceBuilder entity methods by reflection (EntityUtil) on every
# export; renamed or merged, the export throws and nothing is sent.
-keep class io.opentelemetry.sdk.resources.** { *; }
25 changes: 25 additions & 0 deletions android/core-jvm/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
kotlin("jvm") version "2.1.21"
}

kotlin { jvmToolchain(17) }

sourceSets.main { kotlin.srcDir("../src/core/kotlin") }

dependencies {
implementation(platform("io.opentelemetry:opentelemetry-bom:1.68.0"))
implementation("io.opentelemetry:opentelemetry-sdk")
// No OkHttp exclusion here: the JVM tests run otel-java's own OkHttp 5; devices run React Native's 4.9.2.
implementation("io.opentelemetry:opentelemetry-exporter-otlp")
testImplementation(kotlin("test"))
testImplementation("com.google.code.gson:gson:2.11.0")
}

tasks.test {
useJUnitPlatform()
// fast-jvm passes the live collector URL; the export test fails without it.
environment("VERIFY_COLLECTOR", System.getenv("VERIFY_COLLECTOR") ?: "")
environment("VERIFY_FIXTURES", file("../../verify/fixtures").absolutePath)
outputs.upToDateWhen { false }
testLogging { events("passed", "failed", "skipped"); exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL }
}
Binary file not shown.
7 changes: 7 additions & 0 deletions android/core-jvm/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
248 changes: 248 additions & 0 deletions android/core-jvm/gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions android/core-jvm/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// JVM-only project over android/src/core: the pure Kotlin core, tested without Android or Nitro.
rootProject.name = "core-jvm"

dependencyResolutionManagement {
repositories { mavenCentral() }
}
32 changes: 32 additions & 0 deletions android/core-jvm/src/test/kotlin/AttributesTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import com.callstack.otel.core.AttrValue
import com.callstack.otel.core.SeamAttribute
import com.callstack.otel.core.attributesOf
import io.opentelemetry.api.common.AttributeKey.doubleArrayKey
import io.opentelemetry.api.common.AttributeKey.doubleKey
import io.opentelemetry.api.common.AttributeKey.longArrayKey
import io.opentelemetry.api.common.AttributeKey.longKey
import kotlin.test.Test
import kotlin.test.assertEquals

class AttributesTest {
private fun num(v: Double) = attributesOf(listOf(SeamAttribute("k", AttrValue.Num(v))))

@Test fun wholeIsLong() = assertEquals(1L, num(1.0).get(longKey("k")))
@Test fun fractionIsDouble() = assertEquals(1.5, num(1.5).get(doubleKey("k")))
@Test fun bigWholeIsLong() = assertEquals(9007199254740994L, num(9.007199254740994E15).get(longKey("k")))
@Test fun nanIsDouble() = assertEquals(Double.NaN, num(Double.NaN).get(doubleKey("k")))
@Test fun infIsDouble() = assertEquals(Double.NEGATIVE_INFINITY, num(Double.NEGATIVE_INFINITY).get(doubleKey("k")))
// C28: Number.isInteger(-0) is true, so -0 is intValue 0 (the reviewed odd-attributes contract)
@Test fun negZeroIsLong() = assertEquals(0L, num(-0.0).get(longKey("k")))
@Test fun beyondLongIsDouble() = assertEquals(1e19, num(1e19).get(doubleKey("k")))

@Test fun wholeArrayIsLongArray() {
val a = attributesOf(listOf(SeamAttribute("k", AttrValue.Nums(listOf(1.0, 2.0)))))
assertEquals(listOf(1L, 2L), a.get(longArrayKey("k")))
}

@Test fun mixedArrayIsDoubleArray() {
val a = attributesOf(listOf(SeamAttribute("k", AttrValue.Nums(listOf(1.0, 2.5)))))
assertEquals(listOf(1.0, 2.5), a.get(doubleArrayKey("k")))
}
}
Loading