Skip to content

Commit

Permalink
Add clientName/clientVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed Nov 4, 2024
1 parent 986719b commit 70010d8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
7 changes: 5 additions & 2 deletions apollo-execution-reporting/api/apollo-execution-reporting.api
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public final class com/apollographql/execution/reporting/ApolloOperationTracing {
public fun <init> ()V
public final fun beforeField (Lcom/apollographql/execution/ResolveInfo;)Lcom/apollographql/execution/FieldCallback;
public final fun toProtoTrace ()Lcom/apollographql/execution/reporting/Trace;
public final fun toProtoTrace (Ljava/lang/String;Ljava/lang/String;)Lcom/apollographql/execution/reporting/Trace;
}

public final class com/apollographql/execution/reporting/ApolloReportingInstrumentation : com/apollographql/execution/Instrumentation {
Expand All @@ -17,9 +17,12 @@ public final class com/apollographql/execution/reporting/ApolloReportingInstrume
public final class com/apollographql/execution/reporting/ApolloReportingOperationContext : com/apollographql/apollo/api/ExecutionContext$Element {
public static final field Key Lcom/apollographql/execution/reporting/ApolloReportingOperationContext$Key;
public fun <init> ()V
public final fun getApolloOperationTracing ()Lcom/apollographql/execution/reporting/ApolloOperationTracing;
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun beforeField (Lcom/apollographql/execution/ResolveInfo;)Lcom/apollographql/execution/FieldCallback;
public synthetic fun getKey ()Lcom/apollographql/apollo/api/ExecutionContext$Key;
public fun getKey ()Lcom/apollographql/execution/reporting/ApolloReportingOperationContext$Key;
public final fun toProtoTrace ()Lcom/apollographql/execution/reporting/Trace;
}

public final class com/apollographql/execution/reporting/ApolloReportingOperationContext$Key : com/apollographql/apollo/api/ExecutionContext$Key {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
final class com.apollographql.execution.reporting/ApolloOperationTracing { // com.apollographql.execution.reporting/ApolloOperationTracing|null[0]
constructor <init>() // com.apollographql.execution.reporting/ApolloOperationTracing.<init>|<init>(){}[0]
final fun beforeField(com.apollographql.execution/ResolveInfo): com.apollographql.execution/FieldCallback? // com.apollographql.execution.reporting/ApolloOperationTracing.beforeField|beforeField(com.apollographql.execution.ResolveInfo){}[0]
final fun toProtoTrace(): com.apollographql.execution.reporting/Trace // com.apollographql.execution.reporting/ApolloOperationTracing.toProtoTrace|toProtoTrace(){}[0]
final fun toProtoTrace(kotlin/String?, kotlin/String?): com.apollographql.execution.reporting/Trace // com.apollographql.execution.reporting/ApolloOperationTracing.toProtoTrace|toProtoTrace(kotlin.String?;kotlin.String?){}[0]
}
final class com.apollographql.execution.reporting/ApolloReportingInstrumentation : com.apollographql.execution/Instrumentation { // com.apollographql.execution.reporting/ApolloReportingInstrumentation|null[0]
constructor <init>(kotlin/String? = ...) // com.apollographql.execution.reporting/ApolloReportingInstrumentation.<init>|<init>(kotlin.String?){}[0]
Expand All @@ -21,10 +21,10 @@ final class com.apollographql.execution.reporting/ApolloReportingInstrumentation
final fun <get-client>(): io.ktor.client/HttpClient // com.apollographql.execution.reporting/ApolloReportingInstrumentation.client.<get-client>|<get-client>(){}[0]
}
final class com.apollographql.execution.reporting/ApolloReportingOperationContext : com.apollographql.apollo.api/ExecutionContext.Element { // com.apollographql.execution.reporting/ApolloReportingOperationContext|null[0]
constructor <init>() // com.apollographql.execution.reporting/ApolloReportingOperationContext.<init>|<init>(){}[0]
constructor <init>(kotlin/String? = ..., kotlin/String? = ...) // com.apollographql.execution.reporting/ApolloReportingOperationContext.<init>|<init>(kotlin.String?;kotlin.String?){}[0]
final fun beforeField(com.apollographql.execution/ResolveInfo): com.apollographql.execution/FieldCallback? // com.apollographql.execution.reporting/ApolloReportingOperationContext.beforeField|beforeField(com.apollographql.execution.ResolveInfo){}[0]
final fun toProtoTrace(): com.apollographql.execution.reporting/Trace // com.apollographql.execution.reporting/ApolloReportingOperationContext.toProtoTrace|toProtoTrace(){}[0]
final object Key : com.apollographql.apollo.api/ExecutionContext.Key<com.apollographql.execution.reporting/ApolloReportingOperationContext> // com.apollographql.execution.reporting/ApolloReportingOperationContext.Key|null[0]
final val apolloOperationTracing // com.apollographql.execution.reporting/ApolloReportingOperationContext.apolloOperationTracing|{}apolloOperationTracing[0]
final fun <get-apolloOperationTracing>(): com.apollographql.execution.reporting/ApolloOperationTracing // com.apollographql.execution.reporting/ApolloReportingOperationContext.apolloOperationTracing.<get-apolloOperationTracing>|<get-apolloOperationTracing>(){}[0]
final val key // com.apollographql.execution.reporting/ApolloReportingOperationContext.key|{}key[0]
final fun <get-key>(): com.apollographql.execution.reporting/ApolloReportingOperationContext.Key // com.apollographql.execution.reporting/ApolloReportingOperationContext.key.<get-key>|<get-key>(){}[0]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ class ApolloOperationTracing {
return newNode(parentPath)
}

fun toProtoTrace(): Trace {
fun toProtoTrace(clientName: String?, clientVersion: String?): Trace {
val endInstant = Clock.System.now()
return Trace(
start_time = ofEpochSecond(startInstant.epochSeconds, startInstant.nanosecondsOfSecond.toLong()),
end_time = ofEpochSecond(endInstant.epochSeconds, endInstant.nanosecondsOfSecond.toLong()),
duration_ns = (markNow() - operationStartMark).inWholeNanoseconds,
root = rootNode.toProtoNode()
root = rootNode.toProtoNode(),
client_name = clientName ?: "",
client_version = clientVersion ?: ""
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ApolloReportingInstrumentation(val apolloKey: String? = null) : Instrument
val operationData = getOperationData(operationInfo)
if (operationData != null) {
val trace =
operationInfo.executionContext[ApolloReportingOperationContext]!!.apolloOperationTracing.toProtoTrace()
operationInfo.executionContext[ApolloReportingOperationContext]!!.toProtoTrace()

val operation = operations.getOrPut(operationData.statsReportKey) { operationData }
operation.traces.add(trace)
Expand All @@ -84,7 +84,7 @@ class ApolloReportingInstrumentation(val apolloKey: String? = null) : Instrument
require(atc != null) {
"ApolloTracingInstrumentation requires an ApolloTracingContext"
}
return atc.apolloOperationTracing.beforeField(resolveInfo)
return atc.beforeField(resolveInfo)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
package com.apollographql.execution.reporting

import com.apollographql.apollo.api.ExecutionContext
import com.apollographql.execution.FieldCallback
import com.apollographql.execution.ResolveInfo
import kotlin.io.encoding.ExperimentalEncodingApi

class ApolloReportingOperationContext() : ExecutionContext.Element {
val apolloOperationTracing = ApolloOperationTracing()
class ApolloReportingOperationContext(
private val clientName: String? = null,
private val clientVersion: String? = null,
) : ExecutionContext.Element {
private val apolloOperationTracing = ApolloOperationTracing()

fun beforeField(info: ResolveInfo): FieldCallback? = apolloOperationTracing.beforeField(info)

fun toProtoTrace(): Trace = apolloOperationTracing.toProtoTrace(clientName, clientVersion)

override val key = Key

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TracingTest {
schema().execute("{ widgets { foo, baz: bar }, listOfLists { foo }, listOfScalars }".toGraphQLRequest(), context)
}

val trace = context.apolloOperationTracing.toProtoTrace()
val trace = context.toProtoTrace()

assertTrue(trace.start_time!!.getEpochSecond() > 0, "Start time has seconds")
assertTrue(trace.start_time.getNano() > 0, "Start time has nanoseconds")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Ftv1Instrumentation : Instrumentation() {
response
} else {
response.newBuilder()
.extensions(mapOf("ftv1" to Base64.encode(ftv1Context.apolloOperationTracing.toProtoTrace().encode())))
.extensions(mapOf("ftv1" to Base64.encode(ftv1Context.apolloOperationTracing.toProtoTrace(null, null).encode())))
.build()
}
}
Expand Down

0 comments on commit 70010d8

Please sign in to comment.