-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WorkflowTracer Through some Runtime Internals
- Loading branch information
1 parent
32cb7bb
commit b2e9f1e
Showing
22 changed files
with
219 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
workflow-core/src/commonMain/kotlin/com/squareup/workflow1/WorkflowTracer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.squareup.workflow1 | ||
|
||
/** | ||
* This is a very simple tracing interface that can be passed into a workflow runtime in order | ||
* to inject span tracing throughout the workflow core and runtime internals. | ||
*/ | ||
public interface WorkflowTracer { | ||
public fun beginSection(label: String): Unit | ||
public fun endSection(): Unit | ||
} | ||
|
||
/** | ||
* Convenience function to wrap [block] with a trace span as defined by [WorkflowTracer]. | ||
* Only calls [label] if there is an active [WorkflowTracer] use this for any label other than | ||
* a constant. | ||
*/ | ||
public inline fun <T> WorkflowTracer?.trace(label: () -> String, block: () -> T): T { | ||
val optimizedLabel = if (this !== null) { | ||
label() | ||
} else { | ||
"" | ||
} | ||
return trace(optimizedLabel, block) | ||
} | ||
|
||
/** | ||
* Convenience function to wrap [block] with a trace span as defined by [WorkflowTracer]. | ||
*/ | ||
public inline fun <T> WorkflowTracer?.trace(label: String, block: () -> T): T { | ||
this?.beginSection(label) | ||
try { | ||
return block() | ||
} finally { | ||
this?.endSection() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.