From b8c78b87cc70b35fc0f624f833ada41a7c9c153e Mon Sep 17 00:00:00 2001 From: Tom Mulcahy Date: Fri, 7 Nov 2025 09:11:59 -0800 Subject: [PATCH 1/3] Make PapaSafeTrace isTraceable configurable Change PapaSafeTrace from delegating to SafeTrace.isTraceable to accepting isTraceable as a constructor parameter. This gives clients direct control over whether tracing is enabled, removing the implicit dependency on SafeTrace.isTraceable, which will be removed soon. Update WorkflowPapaTracer's default to explicitly pass isTraceable=false to avoid overhead. Add tests to verify the new configuration capability for both PapaSafeTrace and WorkflowPapaTracer. --- .../api/workflow-tracing-papa.api | 2 ++ .../workflow1/tracing/papa/PapaSafeTrace.kt | 9 ++++++--- .../workflow1/tracing/papa/WorkflowPapaTracer.kt | 4 +++- .../tracing/papa/WorkflowPapaTracerTest.kt | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/workflow-tracing-papa/api/workflow-tracing-papa.api b/workflow-tracing-papa/api/workflow-tracing-papa.api index 30ff3d24c..99a19b30a 100644 --- a/workflow-tracing-papa/api/workflow-tracing-papa.api +++ b/workflow-tracing-papa/api/workflow-tracing-papa.api @@ -1,5 +1,7 @@ public final class com/squareup/workflow1/tracing/papa/PapaSafeTrace : com/squareup/workflow1/tracing/SafeTraceInterface { public fun ()V + public fun (Z)V + public synthetic fun (ZILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun beginAsyncSection (Ljava/lang/String;I)V public fun beginSection (Ljava/lang/String;)V public fun endAsyncSection (Ljava/lang/String;I)V diff --git a/workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/PapaSafeTrace.kt b/workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/PapaSafeTrace.kt index a8074b986..dfdfe59ad 100644 --- a/workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/PapaSafeTrace.kt +++ b/workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/PapaSafeTrace.kt @@ -5,10 +5,13 @@ import papa.SafeTrace /** * Production implementation of [SafeTraceInterface] that delegates to the actual [SafeTrace]. + * + * @param isTraceable Whether tracing is enabled. Clients should configure this directly. + * Defaults to false for backwards compatibility. */ -class PapaSafeTrace : SafeTraceInterface { - override val isTraceable: Boolean - get() = SafeTrace.isTraceable +class PapaSafeTrace( + override val isTraceable: Boolean = false +) : SafeTraceInterface { override val isCurrentlyTracing: Boolean get() = SafeTrace.isCurrentlyTracing diff --git a/workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/WorkflowPapaTracer.kt b/workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/WorkflowPapaTracer.kt index d317df659..7071b427a 100644 --- a/workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/WorkflowPapaTracer.kt +++ b/workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/WorkflowPapaTracer.kt @@ -30,9 +30,11 @@ import kotlin.reflect.KType * [WorkflowRuntimeTracer] plugin to add [SafeTraceInterface] traces. * By default this uses [PapaSafeTrace] which will use [androidx.tracing.Trace] calls that * will be received by the system and included in Perfetto traces. + * + * @param safeTrace The [SafeTraceInterface] implementation to use for tracing. */ class WorkflowPapaTracer( - private val safeTrace: SafeTraceInterface = PapaSafeTrace() + private val safeTrace: SafeTraceInterface = PapaSafeTrace(isTraceable = false) ) : WorkflowRuntimeTracer() { private data class NameAndCookie( diff --git a/workflow-tracing-papa/src/test/java/com/squareup/workflow1/tracing/papa/WorkflowPapaTracerTest.kt b/workflow-tracing-papa/src/test/java/com/squareup/workflow1/tracing/papa/WorkflowPapaTracerTest.kt index 8ddfd0780..4d5839767 100644 --- a/workflow-tracing-papa/src/test/java/com/squareup/workflow1/tracing/papa/WorkflowPapaTracerTest.kt +++ b/workflow-tracing-papa/src/test/java/com/squareup/workflow1/tracing/papa/WorkflowPapaTracerTest.kt @@ -102,6 +102,22 @@ internal class WorkflowPapaTracerTest { assertNotNull(papaTracer) } + @Test + fun `PapaSafeTrace can be configured with isTraceable`() { + val traceableTrace = PapaSafeTrace(isTraceable = true) + assertEquals(true, traceableTrace.isTraceable) + + val nonTraceableTrace = PapaSafeTrace(isTraceable = false) + assertEquals(false, nonTraceableTrace.isTraceable) + } + + @Test + fun `WorkflowPapaTracer can be configured with custom SafeTrace`() { + val customTrace = FakeSafeTrace(isTraceable = true) + val tracer = WorkflowPapaTracer(safeTrace = customTrace) + assertNotNull(tracer) + } + @Test fun `onPropsChanged delegates to proceed function`() { val testWorkflow = TestWorkflow() From 9d3b7afa7c709329a1eabd6027e16f91921044e5 Mon Sep 17 00:00:00 2001 From: Tom Mulcahy Date: Fri, 7 Nov 2025 09:32:10 -0800 Subject: [PATCH 2/3] Replace Papa SafeTrace with androidx.tracing Remove the dependency on papa.SafeTrace and replace it with androidx.tracing.Trace. This simplifies the dependency tree by using the standard AndroidX tracing library instead of the third-party Papa library. (Note: we have a test-only dependency on Papa still for papa.Choreographers) The PapaSafeTrace class now delegates to androidx.tracing.Trace methods which provide equivalent functionality. The isCurrentlyTracing property now uses Trace.isEnabled() instead of SafeTrace.isCurrentlyTracing, and logSection() now uses the trace {} inline function from androidx.tracing.ktx. --- workflow-tracing-papa/build.gradle.kts | 2 +- .../workflow1/tracing/papa/PapaSafeTrace.kt | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/workflow-tracing-papa/build.gradle.kts b/workflow-tracing-papa/build.gradle.kts index 6ab446497..2f50477a0 100644 --- a/workflow-tracing-papa/build.gradle.kts +++ b/workflow-tracing-papa/build.gradle.kts @@ -11,9 +11,9 @@ android { dependencies { api(libs.androidx.collection) + api(libs.androidx.tracing.ktx) api(libs.kotlin.jdk8) api(libs.kotlinx.coroutines.core) - api(libs.squareup.papa) api(project(":workflow-core")) api(project(":workflow-runtime")) diff --git a/workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/PapaSafeTrace.kt b/workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/PapaSafeTrace.kt index dfdfe59ad..4a1f03fde 100644 --- a/workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/PapaSafeTrace.kt +++ b/workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/PapaSafeTrace.kt @@ -1,10 +1,11 @@ package com.squareup.workflow1.tracing.papa +import androidx.tracing.Trace +import androidx.tracing.trace import com.squareup.workflow1.tracing.SafeTraceInterface -import papa.SafeTrace /** - * Production implementation of [SafeTraceInterface] that delegates to the actual [SafeTrace]. + * Production implementation of [SafeTraceInterface] that uses androidx.tracing.Trace. * * @param isTraceable Whether tracing is enabled. Clients should configure this directly. * Defaults to false for backwards compatibility. @@ -14,31 +15,31 @@ class PapaSafeTrace( ) : SafeTraceInterface { override val isCurrentlyTracing: Boolean - get() = SafeTrace.isCurrentlyTracing + get() = Trace.isEnabled() override fun beginSection(label: String) { - SafeTrace.beginSection(label) + Trace.beginSection(label) } override fun endSection() { - SafeTrace.endSection() + Trace.endSection() } override fun beginAsyncSection( name: String, cookie: Int ) { - SafeTrace.beginAsyncSection(name, cookie) + Trace.beginAsyncSection(name, cookie) } override fun endAsyncSection( name: String, cookie: Int ) { - SafeTrace.endAsyncSection(name, cookie) + Trace.endAsyncSection(name, cookie) } override fun logSection(info: String) { - SafeTrace.logSection(info) + trace(info) {} } } From d5cc2680293b5868c91208589d737d1202012bc4 Mon Sep 17 00:00:00 2001 From: tcmulcahy <2104594+tcmulcahy@users.noreply.github.com> Date: Fri, 7 Nov 2025 17:40:53 +0000 Subject: [PATCH 3/3] Apply changes from dependencyGuardBaseline --refresh-dependencies Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../dependencies/releaseRuntimeClasspath.txt | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/workflow-tracing-papa/dependencies/releaseRuntimeClasspath.txt b/workflow-tracing-papa/dependencies/releaseRuntimeClasspath.txt index f82db811c..a9e00dcba 100644 --- a/workflow-tracing-papa/dependencies/releaseRuntimeClasspath.txt +++ b/workflow-tracing-papa/dependencies/releaseRuntimeClasspath.txt @@ -1,21 +1,11 @@ -androidx.annotation:annotation-experimental:1.1.0 androidx.annotation:annotation-jvm:1.9.1 androidx.annotation:annotation:1.9.1 -androidx.arch.core:core-common:2.0.0 androidx.collection:collection-jvm:1.5.0 androidx.collection:collection:1.5.0 -androidx.core:core:1.6.0 -androidx.lifecycle:lifecycle-common:2.0.0 -androidx.lifecycle:lifecycle-runtime:2.0.0 -androidx.tracing:tracing-ktx:1.1.0 -androidx.tracing:tracing:1.1.0 -androidx.versionedparcelable:versionedparcelable:1.1.1 -com.squareup.curtains:curtains:1.2.5 +androidx.tracing:tracing-ktx:1.2.0 +androidx.tracing:tracing:1.2.0 com.squareup.okio:okio-jvm:3.3.0 com.squareup.okio:okio:3.3.0 -com.squareup.papa:papa-main-trace:0.30 -com.squareup.papa:papa-safetrace:0.30 -com.squareup.papa:papa:0.30 org.jetbrains.kotlin:kotlin-bom:2.1.21 org.jetbrains.kotlin:kotlin-stdlib-common:2.1.21 org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.1.21