Skip to content

Commit

Permalink
Merge branch 'open-telemetry:main' into remove-target-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
bidetofevil authored May 18, 2024
2 parents a0b0ea9 + 34cdb52 commit dfe1e88
Show file tree
Hide file tree
Showing 24 changed files with 521 additions and 44 deletions.
15 changes: 14 additions & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,21 @@
{
// somehow renovate gets confused by the android property in gradle.properties,
// so let's just exclude it and hopefully clean up the dashboard
"matchPackageNames": ["string:rum.version"],
"matchPackageNames": [
"string:rum.version"
],
"enabled": false
},
{
// Try and force the demo app's kotlin and compose compilers to be in lockstep
// See https://github.com/renovatebot/renovate/issues/18354
"includePaths": ["demo-app/"],
"matchPackagePatterns": [
"^org.jetbrains.kotlin",
"^com.google.devtools.ksp",
"^androidx.compose.compiler"
],
"groupName": "kotlin"
}
]
}
5 changes: 5 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ jobs:
with:
distribution: temurin
java-version: 17
- name: touch local props
run: touch demo-app/local.properties
- name: run gradle check
run: ./gradlew check
- name: build demo app
working-directory: ./demo-app
run: ./gradlew check assemble
- name: publish snapshot
run: ./gradlew publishToSonatype
env:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/codeql-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
distribution: temurin
java-version: 17

- name: touch local props
run: touch demo-app/local.properties

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/pr-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ jobs:
distribution: temurin
java-version: 17
- name: touch local props
run: touch local.properties
run: touch demo-app/local.properties
- name: run gradle
run: ./gradlew check
- name: build demo app
working-directory: ./demo-app
run: ./gradlew check assemble

required-status-check:
needs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/remove-needs-author-feedback.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
github.event.comment.user.login == github.event.issue.user.login
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6

- name: Remove labels
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea
.gradle
/local.properties
demo-app/local.properties
.DS_Store
**/build/
**/build/
1 change: 0 additions & 1 deletion android-agent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ dependencies {
implementation(project(":instrumentation:crash"))
implementation(project(":instrumentation:network"))
implementation(project(":instrumentation:slowrendering"))
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core)
implementation(libs.androidx.navigation.fragment)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ private static TextMapPropagator buildDefaultPropagator() {

OpenTelemetryRumBuilder(Application application, OtelRumConfig config) {
this.application = application;
SessionIdTimeoutHandler timeoutHandler = new SessionIdTimeoutHandler();
final SessionIdTimeoutHandler timeoutHandler =
new SessionIdTimeoutHandler(config.getSessionTimeout());
this.sessionId = new SessionId(timeoutHandler);
this.resource = AndroidResource.createDefault(application);
this.config = config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import io.opentelemetry.android.instrumentation.common.ApplicationStateListener;
import io.opentelemetry.sdk.common.Clock;
import java.util.concurrent.TimeUnit;
import java.time.Duration;

/**
* This class encapsulates the following criteria about the sessionId timeout:
Expand All @@ -25,19 +25,25 @@
*/
final class SessionIdTimeoutHandler implements ApplicationStateListener {

private static final long SESSION_TIMEOUT_NANOS = TimeUnit.MINUTES.toNanos(15);
static final Duration DEFAULT_SESSION_TIMEOUT = Duration.ofMinutes(15);
private final Duration sessionTimeout;

private final Clock clock;
private volatile long timeoutStartNanos;
private volatile State state = State.FOREGROUND;

SessionIdTimeoutHandler() {
this(Clock.getDefault());
this(DEFAULT_SESSION_TIMEOUT);
}

// for testing
SessionIdTimeoutHandler(Clock clock) {
SessionIdTimeoutHandler(Duration sessionTimeout) {
this(Clock.getDefault(), sessionTimeout);
}

SessionIdTimeoutHandler(Clock clock, Duration sessionTimeout) {
this.clock = clock;
this.sessionTimeout = sessionTimeout;
}

@Override
Expand All @@ -56,7 +62,7 @@ boolean hasTimedOut() {
return false;
}
long elapsedTime = clock.nanoTime() - timeoutStartNanos;
return elapsedTime >= SESSION_TIMEOUT_NANOS;
return elapsedTime >= sessionTimeout.toNanos();
}

void bump() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class OtelRumConfig {
private Duration slowRenderingDetectionPollInterval =
DEFAULT_SLOW_RENDERING_DETECTION_POLL_INTERVAL;
private boolean crashReportingEnabled = true;
private Duration sessionTimeout = Duration.ofMinutes(15);

/**
* Configures the set of global attributes to emit with every span and event. Any existing
Expand Down Expand Up @@ -189,4 +190,15 @@ public OtelRumConfig disableCrashReporting() {
crashReportingEnabled = false;
return this;
}

/** Call this method to set session timeout in minutes */
public OtelRumConfig setSessionTimeout(Duration sessionTimeout) {
this.sessionTimeout = sessionTimeout;
return this;
}

/** Call this method to retrieve session timeout */
public Duration getSessionTimeout() {
return sessionTimeout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.android;

import static io.opentelemetry.android.SessionIdTimeoutHandler.DEFAULT_SESSION_TIMEOUT;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -18,7 +19,8 @@ class SessionIdTimeoutHandlerTest {
@Test
void shouldNeverTimeOutInForeground() {
TestClock clock = TestClock.create();
SessionIdTimeoutHandler timeoutHandler = new SessionIdTimeoutHandler(clock);
SessionIdTimeoutHandler timeoutHandler =
new SessionIdTimeoutHandler(clock, DEFAULT_SESSION_TIMEOUT);

assertFalse(timeoutHandler.hasTimedOut());
timeoutHandler.bump();
Expand All @@ -31,7 +33,8 @@ void shouldNeverTimeOutInForeground() {
@Test
void shouldApply15MinutesTimeoutToAppsInBackground() {
TestClock clock = TestClock.create();
SessionIdTimeoutHandler timeoutHandler = new SessionIdTimeoutHandler(clock);
SessionIdTimeoutHandler timeoutHandler =
new SessionIdTimeoutHandler(clock, DEFAULT_SESSION_TIMEOUT);

timeoutHandler.onApplicationBackgrounded();
timeoutHandler.bump();
Expand Down Expand Up @@ -62,7 +65,8 @@ void shouldApply15MinutesTimeoutToAppsInBackground() {
@Test
void shouldApplyTimeoutToFirstSpanAfterAppBeingMovedToForeground() {
TestClock clock = TestClock.create();
SessionIdTimeoutHandler timeoutHandler = new SessionIdTimeoutHandler(clock);
SessionIdTimeoutHandler timeoutHandler =
new SessionIdTimeoutHandler(clock, DEFAULT_SESSION_TIMEOUT);

timeoutHandler.onApplicationBackgrounded();
timeoutHandler.bump();
Expand All @@ -77,4 +81,24 @@ void shouldApplyTimeoutToFirstSpanAfterAppBeingMovedToForeground() {
clock.advance(Duration.ofHours(4));
assertFalse(timeoutHandler.hasTimedOut());
}

@Test
void shouldApplyCustomTimeoutToFirstSpanAfterAppBeingMovedToForeground() {
TestClock clock = TestClock.create();
SessionIdTimeoutHandler timeoutHandler =
new SessionIdTimeoutHandler(clock, Duration.ofNanos(5));

timeoutHandler.onApplicationBackgrounded();
timeoutHandler.bump();

// the first span after app is moved to the foreground gets timed out
timeoutHandler.onApplicationForegrounded();
clock.advance(6, TimeUnit.MINUTES);
assertTrue(timeoutHandler.hasTimedOut());
timeoutHandler.bump();

// after the initial span it's the same as the usual foreground scenario
clock.advance(Duration.ofHours(4));
assertFalse(timeoutHandler.hasTimedOut());
}
}
24 changes: 20 additions & 4 deletions demo-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ import java.io.FileInputStream
import java.util.Properties

plugins {
id("otel.android-app-conventions")
id("com.android.application") version "8.4.0"
id("org.jetbrains.kotlin.android") version "1.9.24"
}

val localProperties = Properties()
localProperties.load(FileInputStream(rootProject.file("local.properties")))

android {
namespace = "io.opentelemetry.android.demo"
compileSdk = 34

defaultConfig {
applicationId = "io.opentelemetry.android.demo"
minSdk = 21
targetSdk = 34
versionCode = 1
versionName = "1.0"

Expand Down Expand Up @@ -40,7 +44,17 @@ android {
viewBinding = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.13"
kotlinCompilerExtensionVersion = "1.5.14"
}
val javaVersion = JavaVersion.VERSION_11
compileOptions {
sourceCompatibility(javaVersion)
targetCompatibility(javaVersion)
isCoreLibraryDesugaringEnabled = true
}

kotlinOptions {
jvmTarget = javaVersion.toString()
}
}

Expand All @@ -52,9 +66,10 @@ dependencies {
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.androidx.navigation.fragment.ktx)
implementation(libs.androidx.navigation.ui.ktx)

coreLibraryDesugaring(libs.desugarJdkLibs)

implementation(project(":android-agent"))
implementation("io.opentelemetry.android:android-agent") //parent dir
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
Expand All @@ -63,8 +78,9 @@ dependencies {
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.opentelemetry.sdk)

implementation(libs.opentelemetry.exporter.otlp)

testImplementation(libs.bundles.junit)
androidTestImplementation(libs.androidx.junit)
debugImplementation(libs.androidx.ui.tooling)
Expand Down
2 changes: 2 additions & 0 deletions demo-app/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
43 changes: 43 additions & 0 deletions demo-app/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[versions]
opentelemetry = "1.38.0"
junit = "5.10.2"
spotless = "6.25.0"
kotlin = "1.9.24"

[libraries]
androidx-appcompat = "androidx.appcompat:appcompat:1.6.1"
opentelemetry-exporter-otlp = { module = "io.opentelemetry:opentelemetry-exporter-otlp", version.ref = "opentelemetry" }

#Test tools
androidx-junit = "androidx.test.ext:junit:1.1.5"
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junit-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junit" }

#Compilation tools
desugarJdkLibs = "com.android.tools:desugar_jdk_libs:2.0.4"

# demo-app
androidx-core-ktx = "androidx.core:core-ktx:1.13.1"
androidx-lifecycle-runtime-ktx = "androidx.lifecycle:lifecycle-runtime-ktx:2.8.0"
androidx-compose-bom = "androidx.compose:compose-bom:2024.05.00"
androidx-activity-compose = "androidx.activity:activity-compose:1.9.0"
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version = "2.1.4" }
material = { group = "com.google.android.material", name = "material", version = "1.12.0" }
androidx-lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version = "2.8.0" }
androidx-lifecycle-viewmodel-ktx = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version = "2.8.0" }
androidx-navigation-fragment-ktx = { group = "androidx.navigation", name = "navigation-fragment-ktx", version = "2.7.7" }
androidx-navigation-ui-ktx = { group = "androidx.navigation", name = "navigation-ui-ktx", version = "2.7.7" }

[bundles]
junit = ["junit-jupiter-api", "junit-jupiter-engine", "junit-vintage-engine"]

[plugins]
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
Binary file added demo-app/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
8 changes: 8 additions & 0 deletions demo-app/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=544c35d6bd849ae8a5ed0bcea39ba677dc40f49df7d1835561582da2009b961d
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit dfe1e88

Please sign in to comment.