Skip to content

Commit d04f045

Browse files
committed
Remove Papa/Safe prefixes from names
We are no longer using papa safe trace, so this commit renames SafeTraceInterface to TraceInterface, PapaSafeTrace to WorkflowTrace, WorkflowPapaTracer to WorkflowTracer, and FakeSafeTrace to FakeTrace to better reflect their purpose without legacy naming conventions. Maintains backward compatibility by keeping deprecated versions of the old class names that delegate to the new implementations. All test files updated to use the new naming convention. workflow-tracing-papa is misleading, but it's the name of a jar published to maven, so I've preserved it.
1 parent 719cd4a commit d04f045

File tree

8 files changed

+169
-80
lines changed

8 files changed

+169
-80
lines changed

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public final class com/squareup/workflow1/tracing/papa/PapaSafeTrace : com/squareup/workflow1/tracing/SafeTraceInterface {
1+
public final class com/squareup/workflow1/tracing/papa/PapaSafeTrace : com/squareup/workflow1/tracing/TraceInterface {
22
public fun <init> ()V
33
public fun <init> (Z)V
44
public synthetic fun <init> (ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
@@ -11,11 +11,30 @@ public final class com/squareup/workflow1/tracing/papa/PapaSafeTrace : com/squar
1111
public fun logSection (Ljava/lang/String;)V
1212
}
1313

14-
public final class com/squareup/workflow1/tracing/papa/WorkflowPapaTracer : com/squareup/workflow1/tracing/WorkflowRuntimeTracer {
15-
public static final field Companion Lcom/squareup/workflow1/tracing/papa/WorkflowPapaTracer$Companion;
14+
public final class com/squareup/workflow1/tracing/papa/WorkflowPapaTracer : com/squareup/workflow1/tracing/papa/WorkflowTracer {
1615
public fun <init> ()V
17-
public fun <init> (Lcom/squareup/workflow1/tracing/SafeTraceInterface;)V
18-
public synthetic fun <init> (Lcom/squareup/workflow1/tracing/SafeTraceInterface;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
16+
public fun <init> (Lcom/squareup/workflow1/tracing/TraceInterface;)V
17+
public synthetic fun <init> (Lcom/squareup/workflow1/tracing/TraceInterface;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
18+
}
19+
20+
public final class com/squareup/workflow1/tracing/papa/WorkflowTrace : com/squareup/workflow1/tracing/TraceInterface {
21+
public fun <init> ()V
22+
public fun <init> (Z)V
23+
public synthetic fun <init> (ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
24+
public fun beginAsyncSection (Ljava/lang/String;I)V
25+
public fun beginSection (Ljava/lang/String;)V
26+
public fun endAsyncSection (Ljava/lang/String;I)V
27+
public fun endSection ()V
28+
public fun isCurrentlyTracing ()Z
29+
public fun isTraceable ()Z
30+
public fun logSection (Ljava/lang/String;)V
31+
}
32+
33+
public class com/squareup/workflow1/tracing/papa/WorkflowTracer : com/squareup/workflow1/tracing/WorkflowRuntimeTracer {
34+
public static final field Companion Lcom/squareup/workflow1/tracing/papa/WorkflowTracer$Companion;
35+
public fun <init> ()V
36+
public fun <init> (Lcom/squareup/workflow1/tracing/TraceInterface;)V
37+
public synthetic fun <init> (Lcom/squareup/workflow1/tracing/TraceInterface;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
1938
public fun onInitialState (Ljava/lang/Object;Lcom/squareup/workflow1/Snapshot;Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object;
2039
public fun onPropsChanged (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object;
2140
public fun onRender (Ljava/lang/Object;Ljava/lang/Object;Lcom/squareup/workflow1/BaseRenderContext;Lkotlin/jvm/functions/Function3;Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/Object;
@@ -27,6 +46,6 @@ public final class com/squareup/workflow1/tracing/papa/WorkflowPapaTracer : com/
2746
public fun onWorkflowSessionStopped (J)V
2847
}
2948

30-
public final class com/squareup/workflow1/tracing/papa/WorkflowPapaTracer$Companion {
49+
public final class com/squareup/workflow1/tracing/papa/WorkflowTracer$Companion {
3150
}
3251

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ package com.squareup.workflow1.tracing.papa
22

33
import androidx.tracing.Trace
44
import androidx.tracing.trace
5-
import com.squareup.workflow1.tracing.SafeTraceInterface
5+
import com.squareup.workflow1.tracing.TraceInterface
66

77
/**
8-
* Production implementation of [SafeTraceInterface] that uses androidx.tracing.Trace.
8+
* Production implementation of [TraceInterface] that uses androidx.tracing.Trace.
99
*
1010
* @param isTraceable Whether tracing is enabled. Clients should configure this directly.
1111
* Defaults to false for backwards compatibility.
1212
*/
13-
class PapaSafeTrace(
13+
class WorkflowTrace(
1414
override val isTraceable: Boolean = false
15-
) : SafeTraceInterface {
15+
) : TraceInterface {
1616

1717
override val isCurrentlyTracing: Boolean
1818
get() = Trace.isEnabled()
@@ -43,3 +43,27 @@ class PapaSafeTrace(
4343
trace(info) {}
4444
}
4545
}
46+
47+
@Deprecated(
48+
message = "Renamed to WorkflowTrace",
49+
replaceWith = ReplaceWith(
50+
expression = "WorkflowTrace",
51+
imports = arrayOf("com.squareup.workflow1.tracing.papa.WorkflowTrace")
52+
)
53+
)
54+
class PapaSafeTrace(
55+
override val isTraceable: Boolean = false
56+
) : TraceInterface {
57+
private val delegate = WorkflowTrace(isTraceable)
58+
59+
override val isCurrentlyTracing: Boolean
60+
get() = delegate.isCurrentlyTracing
61+
62+
override fun beginSection(label: String) = delegate.beginSection(label)
63+
override fun endSection() = delegate.endSection()
64+
override fun beginAsyncSection(name: String, cookie: Int) =
65+
delegate.beginAsyncSection(name, cookie)
66+
override fun endAsyncSection(name: String, cookie: Int) =
67+
delegate.endAsyncSection(name, cookie)
68+
override fun logSection(info: String) = delegate.logSection(info)
69+
}

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import com.squareup.workflow1.WorkflowInterceptor.RuntimeUpdate
1515
import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession
1616
import com.squareup.workflow1.applyTo
1717
import com.squareup.workflow1.tracing.ConfigSnapshot
18-
import com.squareup.workflow1.tracing.SafeTraceInterface
18+
import com.squareup.workflow1.tracing.TraceInterface
1919
import com.squareup.workflow1.tracing.WorkflowRuntimeMonitor.ActionType
2020
import com.squareup.workflow1.tracing.WorkflowRuntimeMonitor.ActionType.CascadeAction
2121
import com.squareup.workflow1.tracing.WorkflowRuntimeMonitor.ActionType.QueuedAction
@@ -27,14 +27,14 @@ import kotlinx.coroutines.CoroutineScope
2727
import kotlin.reflect.KType
2828

2929
/**
30-
* [WorkflowRuntimeTracer] plugin to add [SafeTraceInterface] traces.
31-
* By default this uses [PapaSafeTrace] which will use [androidx.tracing.Trace] calls that
30+
* [WorkflowRuntimeTracer] plugin to add [TraceInterface] traces.
31+
* By default this uses [WorkflowTrace] which will use [androidx.tracing.Trace] calls that
3232
* will be received by the system and included in Perfetto traces.
3333
*
34-
* @param safeTrace The [SafeTraceInterface] implementation to use for tracing.
34+
* @param safeTrace The [TraceInterface] implementation to use for tracing.
3535
*/
36-
class WorkflowPapaTracer(
37-
private val safeTrace: SafeTraceInterface = PapaSafeTrace(isTraceable = false)
36+
open class WorkflowTracer(
37+
private val safeTrace: TraceInterface = WorkflowTrace(isTraceable = false)
3838
) : WorkflowRuntimeTracer() {
3939

4040
private data class NameAndCookie(
@@ -249,7 +249,7 @@ class WorkflowPapaTracer(
249249
proceed(
250250
renderProps,
251251
renderState,
252-
PapaRenderContextInterceptor(
252+
TracingRenderContextInterceptor(
253253
isRoot = session.isRootWorkflow,
254254
workflowName = workflowName
255255
)
@@ -271,9 +271,9 @@ class WorkflowPapaTracer(
271271
/** END SECTION: [WorkflowInterceptor] override methods. **/
272272

273273
/**
274-
* [RenderContextInterceptor] that adds Perfetto tracing through Papa.
274+
* [RenderContextInterceptor] that adds Perfetto tracing.
275275
*/
276-
private inner class PapaRenderContextInterceptor<P, S, O>(
276+
private inner class TracingRenderContextInterceptor<P, S, O>(
277277
private val isRoot: Boolean,
278278
private val workflowName: String
279279
) : RenderContextInterceptor<P, S, O> {
@@ -474,3 +474,14 @@ class WorkflowPapaTracer(
474474
private var effectIndex = 0
475475
}
476476
}
477+
478+
@Deprecated(
479+
message = "Renamed to WorkflowTracer",
480+
replaceWith = ReplaceWith(
481+
expression = "WorkflowTracer",
482+
imports = arrayOf("com.squareup.workflow1.tracing.papa.WorkflowTracer")
483+
)
484+
)
485+
class WorkflowPapaTracer(
486+
safeTrace: TraceInterface = WorkflowTrace(isTraceable = false)
487+
) : WorkflowTracer(safeTrace)

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.squareup.workflow1.tracing.papa
22

3-
import com.squareup.workflow1.tracing.SafeTraceInterface
3+
import com.squareup.workflow1.tracing.TraceInterface
44

55
/**
6-
* Fake implementation of [SafeTraceInterface] for testing purposes.
6+
* Fake implementation of [TraceInterface] for testing purposes.
77
* Records all trace calls for verification in tests.
88
*/
9-
class FakeSafeTrace(
9+
class FakeTrace(
1010
override val isTraceable: Boolean = true,
1111
override val isCurrentlyTracing: Boolean = true
12-
) : SafeTraceInterface {
12+
) : TraceInterface {
1313

1414
data class TraceCall(
1515
val type: String,
@@ -51,3 +51,29 @@ class FakeSafeTrace(
5151
_traceCalls.add(TraceCall("logSection", label = info))
5252
}
5353
}
54+
55+
@Deprecated(
56+
message = "Renamed to FakeTrace",
57+
replaceWith = ReplaceWith(
58+
expression = "FakeTrace",
59+
imports = arrayOf("com.squareup.workflow1.tracing.papa.FakeTrace")
60+
)
61+
)
62+
class FakeSafeTrace(
63+
override val isTraceable: Boolean = true,
64+
override val isCurrentlyTracing: Boolean = true
65+
) : TraceInterface {
66+
private val delegate = FakeTrace(isTraceable, isCurrentlyTracing)
67+
68+
val traceCalls: List<FakeTrace.TraceCall> get() = delegate.traceCalls
69+
70+
fun clearTraceCalls() = delegate.clearTraceCalls()
71+
72+
override fun beginSection(label: String) = delegate.beginSection(label)
73+
override fun endSection() = delegate.endSection()
74+
override fun beginAsyncSection(name: String, cookie: Int) =
75+
delegate.beginAsyncSection(name, cookie)
76+
override fun endAsyncSection(name: String, cookie: Int) =
77+
delegate.endAsyncSection(name, cookie)
78+
override fun logSection(info: String) = delegate.logSection(info)
79+
}

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import kotlin.test.assertTrue
2323

2424
internal class WorkflowPapaTracerTest {
2525

26-
private val fakeTrace = FakeSafeTrace()
27-
private val papaTracer = WorkflowPapaTracer(fakeTrace)
26+
private val fakeTrace = FakeTrace()
27+
private val tracer = WorkflowTracer(fakeTrace)
2828

2929
@Test
3030
fun `onWorkflowSessionStarted creates async section for root workflow`() {
@@ -34,12 +34,12 @@ internal class WorkflowPapaTracerTest {
3434

3535
// Attach runtime context to tracer
3636
val testContext = TestRuntimeTraceContext()
37-
papaTracer.attachRuntimeContext(testContext)
37+
tracer.attachRuntimeContext(testContext)
3838

3939
// Add session info to the context as would normally be done by WorkflowRuntimeMonitor
4040
testContext.workflowSessionInfo[rootSession.sessionId] = WorkflowSessionInfo(rootSession)
4141

42-
papaTracer.onWorkflowSessionStarted(testScope, rootSession)
42+
tracer.onWorkflowSessionStarted(testScope, rootSession)
4343

4444
val asyncSectionCalls = fakeTrace.traceCalls.filter { it.type == "beginAsyncSection" }
4545
assertEquals(1, asyncSectionCalls.size)
@@ -54,12 +54,12 @@ internal class WorkflowPapaTracerTest {
5454

5555
// Attach runtime context to tracer
5656
val testContext = TestRuntimeTraceContext()
57-
papaTracer.attachRuntimeContext(testContext)
57+
tracer.attachRuntimeContext(testContext)
5858

5959
// Add session info to the context as would normally be done by WorkflowRuntimeMonitor
6060
testContext.workflowSessionInfo[rootSession.sessionId] = WorkflowSessionInfo(rootSession)
6161

62-
val result = papaTracer.onInitialState(
62+
val result = tracer.onInitialState(
6363
props = "testProps",
6464
snapshot = null,
6565
workflowScope = testScope,
@@ -81,12 +81,12 @@ internal class WorkflowPapaTracerTest {
8181

8282
// Attach runtime context to tracer
8383
val testContext = TestRuntimeTraceContext()
84-
papaTracer.attachRuntimeContext(testContext)
84+
tracer.attachRuntimeContext(testContext)
8585

8686
val expectedSnapshot = TreeSnapshot.forRootOnly(null)
8787
val renderingAndSnapshot = RenderingAndSnapshot("rendering", expectedSnapshot)
8888

89-
val result = papaTracer.onRenderAndSnapshot(
89+
val result = tracer.onRenderAndSnapshot(
9090
renderProps = "props",
9191
proceed = { renderingAndSnapshot },
9292
session = rootSession
@@ -99,22 +99,22 @@ internal class WorkflowPapaTracerTest {
9999

100100
@Test
101101
fun `tracer can be instantiated`() {
102-
assertNotNull(papaTracer)
102+
assertNotNull(tracer)
103103
}
104104

105105
@Test
106-
fun `PapaSafeTrace can be configured with isTraceable`() {
107-
val traceableTrace = PapaSafeTrace(isTraceable = true)
106+
fun `WorkflowTrace can be configured with isTraceable`() {
107+
val traceableTrace = WorkflowTrace(isTraceable = true)
108108
assertEquals(true, traceableTrace.isTraceable)
109109

110-
val nonTraceableTrace = PapaSafeTrace(isTraceable = false)
110+
val nonTraceableTrace = WorkflowTrace(isTraceable = false)
111111
assertEquals(false, nonTraceableTrace.isTraceable)
112112
}
113113

114114
@Test
115-
fun `WorkflowPapaTracer can be configured with custom SafeTrace`() {
116-
val customTrace = FakeSafeTrace(isTraceable = true)
117-
val tracer = WorkflowPapaTracer(safeTrace = customTrace)
115+
fun `WorkflowTracer can be configured with custom TraceInterface`() {
116+
val customTrace = FakeTrace(isTraceable = true)
117+
val tracer = WorkflowTracer(safeTrace = customTrace)
118118
assertNotNull(tracer)
119119
}
120120

@@ -125,12 +125,12 @@ internal class WorkflowPapaTracerTest {
125125

126126
// Attach runtime context to tracer
127127
val testContext = TestRuntimeTraceContext()
128-
papaTracer.attachRuntimeContext(testContext)
128+
tracer.attachRuntimeContext(testContext)
129129

130130
// Add session info to the context as would normally be done by WorkflowRuntimeMonitor
131131
testContext.workflowSessionInfo[mockSession.sessionId] = WorkflowSessionInfo(mockSession)
132132

133-
val result = papaTracer.onPropsChanged(
133+
val result = tracer.onPropsChanged(
134134
old = "old",
135135
new = "new",
136136
state = "current",
@@ -148,12 +148,12 @@ internal class WorkflowPapaTracerTest {
148148

149149
// Attach runtime context to tracer
150150
val testContext = TestRuntimeTraceContext()
151-
papaTracer.attachRuntimeContext(testContext)
151+
tracer.attachRuntimeContext(testContext)
152152

153153
val expectedSnapshot = TreeSnapshot.forRootOnly(null)
154154
val renderingAndSnapshot = RenderingAndSnapshot("rendering", expectedSnapshot)
155155

156-
val result = papaTracer.onRenderAndSnapshot(
156+
val result = tracer.onRenderAndSnapshot(
157157
renderProps = "props",
158158
proceed = { renderingAndSnapshot },
159159
session = mockSession
@@ -169,11 +169,11 @@ internal class WorkflowPapaTracerTest {
169169

170170
// Attach runtime context to tracer
171171
val testContext = TestRuntimeTraceContext()
172-
papaTracer.attachRuntimeContext(testContext)
172+
tracer.attachRuntimeContext(testContext)
173173

174174
val treeSnapshot = TreeSnapshot.forRootOnly(null)
175175

176-
val result = papaTracer.onSnapshotStateWithChildren(
176+
val result = tracer.onSnapshotStateWithChildren(
177177
proceed = { treeSnapshot },
178178
session = mockSession
179179
)
@@ -184,15 +184,15 @@ internal class WorkflowPapaTracerTest {
184184
@Test
185185
fun `onRuntimeUpdateEnhanced handles different runtime updates`() {
186186
val testContext = TestRuntimeTraceContext()
187-
papaTracer.attachRuntimeContext(testContext)
187+
tracer.attachRuntimeContext(testContext)
188188

189189
val configSnapshot = ConfigSnapshot(TestRuntimeConfig())
190190

191191
// Should not throw for RenderPassSkipped
192-
papaTracer.onRuntimeUpdateEnhanced(RenderPassSkipped, false, configSnapshot)
192+
tracer.onRuntimeUpdateEnhanced(RenderPassSkipped, false, configSnapshot)
193193

194194
// Should not throw for RuntimeLoopSettled
195-
papaTracer.onRuntimeUpdateEnhanced(RuntimeSettled, true, configSnapshot)
195+
tracer.onRuntimeUpdateEnhanced(RuntimeSettled, true, configSnapshot)
196196
}
197197

198198
@Test
@@ -202,14 +202,14 @@ internal class WorkflowPapaTracerTest {
202202

203203
// Attach runtime context to tracer
204204
val testContext = TestRuntimeTraceContext()
205-
papaTracer.attachRuntimeContext(testContext)
205+
tracer.attachRuntimeContext(testContext)
206206

207207
// Add session info to the context as would normally be done by WorkflowRuntimeMonitor
208208
testContext.workflowSessionInfo[mockSession.sessionId] = WorkflowSessionInfo(mockSession)
209209

210210
// Should not throw
211-
papaTracer.onWorkflowSessionStarted(TestScope(), mockSession)
212-
papaTracer.onWorkflowSessionStopped(123L)
211+
tracer.onWorkflowSessionStarted(TestScope(), mockSession)
212+
tracer.onWorkflowSessionStopped(123L)
213213
}
214214

215215
@Test
@@ -219,13 +219,13 @@ internal class WorkflowPapaTracerTest {
219219

220220
// Attach runtime context to tracer
221221
val testContext = TestRuntimeTraceContext()
222-
papaTracer.attachRuntimeContext(testContext)
222+
tracer.attachRuntimeContext(testContext)
223223

224224
// Add session info to the context as would normally be done by WorkflowRuntimeMonitor
225225
testContext.workflowSessionInfo[mockSession.sessionId] = WorkflowSessionInfo(mockSession)
226226

227227
// Should not throw
228-
papaTracer.onRootPropsChanged(mockSession)
228+
tracer.onRootPropsChanged(mockSession)
229229
}
230230

231231
private class TestWorkflow : StatefulWorkflow<String, String, String, String>() {

0 commit comments

Comments
 (0)