Skip to content

Commit 719cd4a

Browse files
authored
Merge pull request #1428 from square/tomm/remove-safe-trace-is-traceable
Make PapaSafeTrace isTraceable configurable
2 parents 7db6d67 + 991c5bd commit 719cd4a

File tree

6 files changed

+39
-25
lines changed

6 files changed

+39
-25
lines changed

workflow-tracing-papa/api/workflow-tracing-papa.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
public final class com/squareup/workflow1/tracing/papa/PapaSafeTrace : com/squareup/workflow1/tracing/SafeTraceInterface {
22
public fun <init> ()V
3+
public fun <init> (Z)V
4+
public synthetic fun <init> (ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
35
public fun beginAsyncSection (Ljava/lang/String;I)V
46
public fun beginSection (Ljava/lang/String;)V
57
public fun endAsyncSection (Ljava/lang/String;I)V

workflow-tracing-papa/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ android {
1111

1212
dependencies {
1313
api(libs.androidx.collection)
14+
api(libs.androidx.tracing.ktx)
1415
api(libs.kotlin.jdk8)
1516
api(libs.kotlinx.coroutines.core)
16-
api(libs.squareup.papa)
1717

1818
api(project(":workflow-core"))
1919
api(project(":workflow-runtime"))

workflow-tracing-papa/dependencies/releaseRuntimeClasspath.txt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
androidx.annotation:annotation-experimental:1.1.0
21
androidx.annotation:annotation-jvm:1.9.1
32
androidx.annotation:annotation:1.9.1
4-
androidx.arch.core:core-common:2.0.0
53
androidx.collection:collection-jvm:1.5.0
64
androidx.collection:collection:1.5.0
7-
androidx.core:core:1.6.0
8-
androidx.lifecycle:lifecycle-common:2.0.0
9-
androidx.lifecycle:lifecycle-runtime:2.0.0
10-
androidx.tracing:tracing-ktx:1.1.0
11-
androidx.tracing:tracing:1.1.0
12-
androidx.versionedparcelable:versionedparcelable:1.1.1
13-
com.squareup.curtains:curtains:1.2.5
5+
androidx.tracing:tracing-ktx:1.2.0
6+
androidx.tracing:tracing:1.2.0
147
com.squareup.okio:okio-jvm:3.3.0
158
com.squareup.okio:okio:3.3.0
16-
com.squareup.papa:papa-main-trace:0.30
17-
com.squareup.papa:papa-safetrace:0.30
18-
com.squareup.papa:papa:0.30
199
org.jetbrains.kotlin:kotlin-bom:2.1.21
2010
org.jetbrains.kotlin:kotlin-stdlib-common:2.1.21
2111
org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.1.21
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
package com.squareup.workflow1.tracing.papa
22

3+
import androidx.tracing.Trace
4+
import androidx.tracing.trace
35
import com.squareup.workflow1.tracing.SafeTraceInterface
4-
import papa.SafeTrace
56

67
/**
7-
* Production implementation of [SafeTraceInterface] that delegates to the actual [SafeTrace].
8+
* Production implementation of [SafeTraceInterface] that uses androidx.tracing.Trace.
9+
*
10+
* @param isTraceable Whether tracing is enabled. Clients should configure this directly.
11+
* Defaults to false for backwards compatibility.
812
*/
9-
class PapaSafeTrace : SafeTraceInterface {
10-
override val isTraceable: Boolean
11-
get() = SafeTrace.isTraceable
13+
class PapaSafeTrace(
14+
override val isTraceable: Boolean = false
15+
) : SafeTraceInterface {
1216

1317
override val isCurrentlyTracing: Boolean
14-
get() = SafeTrace.isCurrentlyTracing
18+
get() = Trace.isEnabled()
1519

1620
override fun beginSection(label: String) {
17-
SafeTrace.beginSection(label)
21+
Trace.beginSection(label)
1822
}
1923

2024
override fun endSection() {
21-
SafeTrace.endSection()
25+
Trace.endSection()
2226
}
2327

2428
override fun beginAsyncSection(
2529
name: String,
2630
cookie: Int
2731
) {
28-
SafeTrace.beginAsyncSection(name, cookie)
32+
Trace.beginAsyncSection(name, cookie)
2933
}
3034

3135
override fun endAsyncSection(
3236
name: String,
3337
cookie: Int
3438
) {
35-
SafeTrace.endAsyncSection(name, cookie)
39+
Trace.endAsyncSection(name, cookie)
3640
}
3741

3842
override fun logSection(info: String) {
39-
SafeTrace.logSection(info)
43+
trace(info) {}
4044
}
4145
}

workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/WorkflowPapaTracer.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ import kotlin.reflect.KType
3030
* [WorkflowRuntimeTracer] plugin to add [SafeTraceInterface] traces.
3131
* By default this uses [PapaSafeTrace] which will use [androidx.tracing.Trace] calls that
3232
* will be received by the system and included in Perfetto traces.
33+
*
34+
* @param safeTrace The [SafeTraceInterface] implementation to use for tracing.
3335
*/
3436
class WorkflowPapaTracer(
35-
private val safeTrace: SafeTraceInterface = PapaSafeTrace()
37+
private val safeTrace: SafeTraceInterface = PapaSafeTrace(isTraceable = false)
3638
) : WorkflowRuntimeTracer() {
3739

3840
private data class NameAndCookie(

workflow-tracing-papa/src/test/java/com/squareup/workflow1/tracing/papa/WorkflowPapaTracerTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ internal class WorkflowPapaTracerTest {
102102
assertNotNull(papaTracer)
103103
}
104104

105+
@Test
106+
fun `PapaSafeTrace can be configured with isTraceable`() {
107+
val traceableTrace = PapaSafeTrace(isTraceable = true)
108+
assertEquals(true, traceableTrace.isTraceable)
109+
110+
val nonTraceableTrace = PapaSafeTrace(isTraceable = false)
111+
assertEquals(false, nonTraceableTrace.isTraceable)
112+
}
113+
114+
@Test
115+
fun `WorkflowPapaTracer can be configured with custom SafeTrace`() {
116+
val customTrace = FakeSafeTrace(isTraceable = true)
117+
val tracer = WorkflowPapaTracer(safeTrace = customTrace)
118+
assertNotNull(tracer)
119+
}
120+
105121
@Test
106122
fun `onPropsChanged delegates to proceed function`() {
107123
val testWorkflow = TestWorkflow()

0 commit comments

Comments
 (0)