graphql.nadel.instrumentation.parameters.NadelInstrumentationTimingParameters.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nadel Show documentation
Show all versions of nadel Show documentation
Nadel is a Java library that combines multiple GrahpQL services together into one API.
package graphql.nadel.instrumentation.parameters
import graphql.execution.instrumentation.InstrumentationState
import graphql.nadel.engine.transform.NadelTransform
import graphql.nadel.instrumentation.parameters.NadelInstrumentationTimingParameters.ChildStep
import graphql.nadel.instrumentation.parameters.NadelInstrumentationTimingParameters.Step
import java.time.Duration
import java.time.Instant
data class NadelInstrumentationTimingParameters(
val step: Step,
/**
* Can be null for batched timings which don't really have a start time.
*/
val startedAt: Instant?,
val duration: Duration,
/**
* If an exception occurred during the timing of the step, then it is passed in here.
*/
val exception: Throwable?,
private val context: Any?,
private val instrumentationState: InstrumentationState?,
) {
fun getContext(): T? {
@Suppress("UNCHECKED_CAST") // trust the caller
return context as T
}
fun getInstrumentationState(): T? {
@Suppress("UNCHECKED_CAST") // trust the caller
return instrumentationState as T?
}
sealed interface Step {
val parent: Step?
val name: String
fun getFullName(): String {
val parents = mutableListOf()
var cursor: Step? = this
while (cursor != null) {
parents.add(cursor)
cursor = cursor.parent
}
return parents
.asReversed()
.joinToString(separator = ".") { it.name }
}
/**
* Determines whether `this` is a child of another [parent] step.
*/
fun isChildOf(parent: Step): Boolean {
var cursor: Step? = this
while (cursor != null && cursor != parent) {
cursor = cursor.parent
}
return cursor == parent
}
}
enum class RootStep : Step {
ExecutableOperationParsing,
ExecutionPlanning,
QueryTransforming,
ResultTransforming,
ServiceExecution,
;
override val parent: Step? = null
}
data class ChildStep internal constructor(
override val parent: Step,
override val name: String,
) : Step {
constructor(
parent: Step,
transform: NadelTransform<*>,
) : this(
parent = parent,
name = transform.name,
)
companion object {
val DocumentCompilation = RootStep.ServiceExecution.child("DocumentCompilation")
}
}
}
internal fun Step.child(name: String): ChildStep {
return ChildStep(parent = this, name = name)
}