diff --git a/.github/renovate.json5 b/.github/renovate.json5 index d8dcc3559..cb25131a1 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -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" } ] } diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 953e99607..df4d3c237 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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: diff --git a/.github/workflows/codeql-daily.yml b/.github/workflows/codeql-daily.yml index b57de9bb3..215d106a2 100644 --- a/.github/workflows/codeql-daily.yml +++ b/.github/workflows/codeql-daily.yml @@ -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: diff --git a/.github/workflows/pr-check.yaml b/.github/workflows/pr-check.yaml index 1b0d553f6..b3afd1f1b 100644 --- a/.github/workflows/pr-check.yaml +++ b/.github/workflows/pr-check.yaml @@ -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: diff --git a/.github/workflows/remove-needs-author-feedback.yaml b/.github/workflows/remove-needs-author-feedback.yaml index 4130d38d1..06e9a3dba 100644 --- a/.github/workflows/remove-needs-author-feedback.yaml +++ b/.github/workflows/remove-needs-author-feedback.yaml @@ -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: diff --git a/.gitignore b/.gitignore index d2c2be31c..a0df3d643 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea .gradle /local.properties +demo-app/local.properties .DS_Store -**/build/ \ No newline at end of file +**/build/ diff --git a/android-agent/build.gradle.kts b/android-agent/build.gradle.kts index 12a0506a7..a10bb241c 100644 --- a/android-agent/build.gradle.kts +++ b/android-agent/build.gradle.kts @@ -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) diff --git a/android-agent/src/main/java/io/opentelemetry/android/OpenTelemetryRumBuilder.java b/android-agent/src/main/java/io/opentelemetry/android/OpenTelemetryRumBuilder.java index 479f8a38e..c9dccceae 100644 --- a/android-agent/src/main/java/io/opentelemetry/android/OpenTelemetryRumBuilder.java +++ b/android-agent/src/main/java/io/opentelemetry/android/OpenTelemetryRumBuilder.java @@ -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; diff --git a/android-agent/src/main/java/io/opentelemetry/android/SessionIdTimeoutHandler.java b/android-agent/src/main/java/io/opentelemetry/android/SessionIdTimeoutHandler.java index 8d1c150ce..4d1a1a943 100644 --- a/android-agent/src/main/java/io/opentelemetry/android/SessionIdTimeoutHandler.java +++ b/android-agent/src/main/java/io/opentelemetry/android/SessionIdTimeoutHandler.java @@ -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: @@ -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 @@ -56,7 +62,7 @@ boolean hasTimedOut() { return false; } long elapsedTime = clock.nanoTime() - timeoutStartNanos; - return elapsedTime >= SESSION_TIMEOUT_NANOS; + return elapsedTime >= sessionTimeout.toNanos(); } void bump() { diff --git a/android-agent/src/main/java/io/opentelemetry/android/config/OtelRumConfig.java b/android-agent/src/main/java/io/opentelemetry/android/config/OtelRumConfig.java index eacfd7b24..f26ec6271 100644 --- a/android-agent/src/main/java/io/opentelemetry/android/config/OtelRumConfig.java +++ b/android-agent/src/main/java/io/opentelemetry/android/config/OtelRumConfig.java @@ -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 @@ -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; + } } diff --git a/android-agent/src/test/java/io/opentelemetry/android/SessionIdTimeoutHandlerTest.java b/android-agent/src/test/java/io/opentelemetry/android/SessionIdTimeoutHandlerTest.java index 4ed7dbd6a..197f215c6 100644 --- a/android-agent/src/test/java/io/opentelemetry/android/SessionIdTimeoutHandlerTest.java +++ b/android-agent/src/test/java/io/opentelemetry/android/SessionIdTimeoutHandlerTest.java @@ -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; @@ -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(); @@ -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(); @@ -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(); @@ -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()); + } } diff --git a/demo-app/build.gradle.kts b/demo-app/build.gradle.kts index de5bd6049..0c2de8d08 100644 --- a/demo-app/build.gradle.kts +++ b/demo-app/build.gradle.kts @@ -2,7 +2,8 @@ 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() @@ -10,9 +11,12 @@ 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" @@ -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() } } @@ -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) @@ -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) diff --git a/demo-app/gradle.properties b/demo-app/gradle.properties new file mode 100644 index 000000000..3c5e11311 --- /dev/null +++ b/demo-app/gradle.properties @@ -0,0 +1,2 @@ +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +android.useAndroidX=true diff --git a/demo-app/gradle/libs.versions.toml b/demo-app/gradle/libs.versions.toml new file mode 100644 index 000000000..80e982d64 --- /dev/null +++ b/demo-app/gradle/libs.versions.toml @@ -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" } diff --git a/demo-app/gradle/wrapper/gradle-wrapper.jar b/demo-app/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..e6441136f Binary files /dev/null and b/demo-app/gradle/wrapper/gradle-wrapper.jar differ diff --git a/demo-app/gradle/wrapper/gradle-wrapper.properties b/demo-app/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..381baa9ce --- /dev/null +++ b/demo-app/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/demo-app/gradlew b/demo-app/gradlew new file mode 100755 index 000000000..1aa94a426 --- /dev/null +++ b/demo-app/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/demo-app/gradlew.bat b/demo-app/gradlew.bat new file mode 100644 index 000000000..25da30dbd --- /dev/null +++ b/demo-app/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/demo-app/proguard-rules.pro b/demo-app/proguard-rules.pro new file mode 100644 index 000000000..fd245fd47 --- /dev/null +++ b/demo-app/proguard-rules.pro @@ -0,0 +1,5 @@ +-dontwarn com.fasterxml.jackson.core.JsonFactory +-dontwarn com.fasterxml.jackson.core.JsonGenerator +-dontwarn com.google.auto.value.AutoValue$Builder +-dontwarn com.google.auto.value.AutoValue +-dontwarn com.google.auto.value.extension.memoized.Memoized diff --git a/demo-app/settings.gradle.kts b/demo-app/settings.gradle.kts new file mode 100644 index 000000000..10e3d2827 --- /dev/null +++ b/demo-app/settings.gradle.kts @@ -0,0 +1,17 @@ +rootProject.name = "opentelemetry-android-demo" + +pluginManagement { + repositories { + mavenCentral() + google() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + mavenCentral() + google() + } +} +includeBuild("..") \ No newline at end of file diff --git a/demo-app/src/main/res/drawable/otel_icon.png b/demo-app/src/main/res/drawable/otel_icon.png index 3d24a3408..06efcdff9 100644 Binary files a/demo-app/src/main/res/drawable/otel_icon.png and b/demo-app/src/main/res/drawable/otel_icon.png differ diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6f23a13b6..ad339720c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,19 +1,18 @@ [versions] -opentelemetry = "1.37.0" +opentelemetry = "1.38.0" opentelemetry-instrumentation = "2.3.0" opentelemetry-instrumentation-alpha = "2.3.0-alpha" opentelemetry-semconv = "1.25.0-alpha" opentelemetry-contrib = "1.34.0-alpha" -mockito = "5.11.0" +mockito = "5.12.0" junit = "5.10.2" -byteBuddy = "1.14.14" +byteBuddy = "1.14.15" okhttp = "4.12.0" spotless = "6.25.0" kotlin = "1.9.24" [libraries] opentelemetry-platform = { module = "io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom", version.ref = "opentelemetry-instrumentation" } -androidx-appcompat = "androidx.appcompat:appcompat:1.6.1" androidx-navigation-fragment = "androidx.navigation:navigation-fragment:2.7.7" androidx-core = "androidx.core:core:1.13.1" findbugs-jsr305 = "com.google.code.findbugs:jsr305:3.0.2" @@ -38,7 +37,7 @@ androidx-test-runner = "androidx.test:runner:1.5.2" androidx-junit = "androidx.test.ext:junit:1.1.5" mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" } mockito-junit-jupiter = { module = "org.mockito:mockito-junit-jupiter", version.ref = "mockito" } -mockk = "io.mockk:mockk:1.13.10" +mockk = "io.mockk:mockk:1.13.11" 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" } @@ -61,24 +60,6 @@ android-plugin = "com.android.tools.build:gradle:8.4.0" byteBuddy-plugin = { module = "net.bytebuddy:byte-buddy-gradle-plugin", version.ref = "byteBuddy" } kotlin-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } -# demo-app -androidx-core-ktx = "androidx.core:core-ktx:1.13.0" -androidx-lifecycle-runtime-ktx = "androidx.lifecycle:lifecycle-runtime-ktx:2.7.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.7.0" } -androidx-lifecycle-viewmodel-ktx = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version = "2.7.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] mocking = ["mockito-core", "mockito-junit-jupiter", "mockk"] junit = ["junit-jupiter-api", "junit-jupiter-engine", "junit-vintage-engine"] diff --git a/instrumentation/volley/library/build.gradle.kts b/instrumentation/volley/library/build.gradle.kts index 5f420137b..6f7eaab15 100644 --- a/instrumentation/volley/library/build.gradle.kts +++ b/instrumentation/volley/library/build.gradle.kts @@ -35,12 +35,10 @@ android { } dependencies { - implementation(libs.androidx.appcompat) implementation(libs.androidx.navigation.fragment) implementation(libs.opentelemetry.instrumentation.api) implementation(libs.opentelemetry.semconv.incubating) compileOnly(libs.volley) - coreLibraryDesugaring(libs.desugarJdkLibs) api(platform(libs.opentelemetry.platform)) api(libs.opentelemetry.api) diff --git a/settings.gradle.kts b/settings.gradle.kts index 6ef29b1dc..6ad7204c7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,4 +15,3 @@ include(":instrumentation:network") include(":instrumentation:slowrendering") include(":instrumentation:startup") include(":instrumentation:volley:library") -include(":demo-app")