Skip to content

Commit 70010d8

Browse files
committed
Add clientName/clientVersion
1 parent 986719b commit 70010d8

File tree

7 files changed

+28
-14
lines changed

7 files changed

+28
-14
lines changed

apollo-execution-reporting/api/apollo-execution-reporting.api

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
public final class com/apollographql/execution/reporting/ApolloOperationTracing {
22
public fun <init> ()V
33
public final fun beforeField (Lcom/apollographql/execution/ResolveInfo;)Lcom/apollographql/execution/FieldCallback;
4-
public final fun toProtoTrace ()Lcom/apollographql/execution/reporting/Trace;
4+
public final fun toProtoTrace (Ljava/lang/String;Ljava/lang/String;)Lcom/apollographql/execution/reporting/Trace;
55
}
66

77
public final class com/apollographql/execution/reporting/ApolloReportingInstrumentation : com/apollographql/execution/Instrumentation {
@@ -17,9 +17,12 @@ public final class com/apollographql/execution/reporting/ApolloReportingInstrume
1717
public final class com/apollographql/execution/reporting/ApolloReportingOperationContext : com/apollographql/apollo/api/ExecutionContext$Element {
1818
public static final field Key Lcom/apollographql/execution/reporting/ApolloReportingOperationContext$Key;
1919
public fun <init> ()V
20-
public final fun getApolloOperationTracing ()Lcom/apollographql/execution/reporting/ApolloOperationTracing;
20+
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
21+
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
22+
public final fun beforeField (Lcom/apollographql/execution/ResolveInfo;)Lcom/apollographql/execution/FieldCallback;
2123
public synthetic fun getKey ()Lcom/apollographql/apollo/api/ExecutionContext$Key;
2224
public fun getKey ()Lcom/apollographql/execution/reporting/ApolloReportingOperationContext$Key;
25+
public final fun toProtoTrace ()Lcom/apollographql/execution/reporting/Trace;
2326
}
2427

2528
public final class com/apollographql/execution/reporting/ApolloReportingOperationContext$Key : com/apollographql/apollo/api/ExecutionContext$Key {

apollo-execution-reporting/api/apollo-execution-reporting.klib.api

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
final class com.apollographql.execution.reporting/ApolloOperationTracing { // com.apollographql.execution.reporting/ApolloOperationTracing|null[0]
1010
constructor <init>() // com.apollographql.execution.reporting/ApolloOperationTracing.<init>|<init>(){}[0]
1111
final fun beforeField(com.apollographql.execution/ResolveInfo): com.apollographql.execution/FieldCallback? // com.apollographql.execution.reporting/ApolloOperationTracing.beforeField|beforeField(com.apollographql.execution.ResolveInfo){}[0]
12-
final fun toProtoTrace(): com.apollographql.execution.reporting/Trace // com.apollographql.execution.reporting/ApolloOperationTracing.toProtoTrace|toProtoTrace(){}[0]
12+
final fun toProtoTrace(kotlin/String?, kotlin/String?): com.apollographql.execution.reporting/Trace // com.apollographql.execution.reporting/ApolloOperationTracing.toProtoTrace|toProtoTrace(kotlin.String?;kotlin.String?){}[0]
1313
}
1414
final class com.apollographql.execution.reporting/ApolloReportingInstrumentation : com.apollographql.execution/Instrumentation { // com.apollographql.execution.reporting/ApolloReportingInstrumentation|null[0]
1515
constructor <init>(kotlin/String? = ...) // com.apollographql.execution.reporting/ApolloReportingInstrumentation.<init>|<init>(kotlin.String?){}[0]
@@ -21,10 +21,10 @@ final class com.apollographql.execution.reporting/ApolloReportingInstrumentation
2121
final fun <get-client>(): io.ktor.client/HttpClient // com.apollographql.execution.reporting/ApolloReportingInstrumentation.client.<get-client>|<get-client>(){}[0]
2222
}
2323
final class com.apollographql.execution.reporting/ApolloReportingOperationContext : com.apollographql.apollo.api/ExecutionContext.Element { // com.apollographql.execution.reporting/ApolloReportingOperationContext|null[0]
24-
constructor <init>() // com.apollographql.execution.reporting/ApolloReportingOperationContext.<init>|<init>(){}[0]
24+
constructor <init>(kotlin/String? = ..., kotlin/String? = ...) // com.apollographql.execution.reporting/ApolloReportingOperationContext.<init>|<init>(kotlin.String?;kotlin.String?){}[0]
25+
final fun beforeField(com.apollographql.execution/ResolveInfo): com.apollographql.execution/FieldCallback? // com.apollographql.execution.reporting/ApolloReportingOperationContext.beforeField|beforeField(com.apollographql.execution.ResolveInfo){}[0]
26+
final fun toProtoTrace(): com.apollographql.execution.reporting/Trace // com.apollographql.execution.reporting/ApolloReportingOperationContext.toProtoTrace|toProtoTrace(){}[0]
2527
final object Key : com.apollographql.apollo.api/ExecutionContext.Key<com.apollographql.execution.reporting/ApolloReportingOperationContext> // com.apollographql.execution.reporting/ApolloReportingOperationContext.Key|null[0]
26-
final val apolloOperationTracing // com.apollographql.execution.reporting/ApolloReportingOperationContext.apolloOperationTracing|{}apolloOperationTracing[0]
27-
final fun <get-apolloOperationTracing>(): com.apollographql.execution.reporting/ApolloOperationTracing // com.apollographql.execution.reporting/ApolloReportingOperationContext.apolloOperationTracing.<get-apolloOperationTracing>|<get-apolloOperationTracing>(){}[0]
2828
final val key // com.apollographql.execution.reporting/ApolloReportingOperationContext.key|{}key[0]
2929
final fun <get-key>(): com.apollographql.execution.reporting/ApolloReportingOperationContext.Key // com.apollographql.execution.reporting/ApolloReportingOperationContext.key.<get-key>|<get-key>(){}[0]
3030
}

apollo-execution-reporting/src/commonMain/kotlin/com/apollographql/execution/reporting/ApolloOperationTracing.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ class ApolloOperationTracing {
3737
return newNode(parentPath)
3838
}
3939

40-
fun toProtoTrace(): Trace {
40+
fun toProtoTrace(clientName: String?, clientVersion: String?): Trace {
4141
val endInstant = Clock.System.now()
4242
return Trace(
4343
start_time = ofEpochSecond(startInstant.epochSeconds, startInstant.nanosecondsOfSecond.toLong()),
4444
end_time = ofEpochSecond(endInstant.epochSeconds, endInstant.nanosecondsOfSecond.toLong()),
4545
duration_ns = (markNow() - operationStartMark).inWholeNanoseconds,
46-
root = rootNode.toProtoNode()
46+
root = rootNode.toProtoNode(),
47+
client_name = clientName ?: "",
48+
client_version = clientVersion ?: ""
4749
)
4850
}
4951

apollo-execution-reporting/src/commonMain/kotlin/com/apollographql/execution/reporting/ApolloReportingInstrumentation.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ApolloReportingInstrumentation(val apolloKey: String? = null) : Instrument
6464
val operationData = getOperationData(operationInfo)
6565
if (operationData != null) {
6666
val trace =
67-
operationInfo.executionContext[ApolloReportingOperationContext]!!.apolloOperationTracing.toProtoTrace()
67+
operationInfo.executionContext[ApolloReportingOperationContext]!!.toProtoTrace()
6868

6969
val operation = operations.getOrPut(operationData.statsReportKey) { operationData }
7070
operation.traces.add(trace)
@@ -84,7 +84,7 @@ class ApolloReportingInstrumentation(val apolloKey: String? = null) : Instrument
8484
require(atc != null) {
8585
"ApolloTracingInstrumentation requires an ApolloTracingContext"
8686
}
87-
return atc.apolloOperationTracing.beforeField(resolveInfo)
87+
return atc.beforeField(resolveInfo)
8888
}
8989
}
9090

apollo-execution-reporting/src/commonMain/kotlin/com/apollographql/execution/reporting/ApolloReportingOperationContext.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
package com.apollographql.execution.reporting
44

55
import com.apollographql.apollo.api.ExecutionContext
6+
import com.apollographql.execution.FieldCallback
7+
import com.apollographql.execution.ResolveInfo
68
import kotlin.io.encoding.ExperimentalEncodingApi
79

8-
class ApolloReportingOperationContext() : ExecutionContext.Element {
9-
val apolloOperationTracing = ApolloOperationTracing()
10+
class ApolloReportingOperationContext(
11+
private val clientName: String? = null,
12+
private val clientVersion: String? = null,
13+
) : ExecutionContext.Element {
14+
private val apolloOperationTracing = ApolloOperationTracing()
15+
16+
fun beforeField(info: ResolveInfo): FieldCallback? = apolloOperationTracing.beforeField(info)
17+
18+
fun toProtoTrace(): Trace = apolloOperationTracing.toProtoTrace(clientName, clientVersion)
1019

1120
override val key = Key
1221

apollo-execution-reporting/src/commonTest/kotlin/TracingTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class TracingTest {
5252
schema().execute("{ widgets { foo, baz: bar }, listOfLists { foo }, listOfScalars }".toGraphQLRequest(), context)
5353
}
5454

55-
val trace = context.apolloOperationTracing.toProtoTrace()
55+
val trace = context.toProtoTrace()
5656

5757
assertTrue(trace.start_time!!.getEpochSecond() > 0, "Start time has seconds")
5858
assertTrue(trace.start_time.getNano() > 0, "Start time has nanoseconds")

apollo-execution-subgraph/src/commonMain/kotlin/com/apollographql/execution/subgraph/Ftv1Instrumentation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Ftv1Instrumentation : Instrumentation() {
2727
response
2828
} else {
2929
response.newBuilder()
30-
.extensions(mapOf("ftv1" to Base64.encode(ftv1Context.apolloOperationTracing.toProtoTrace().encode())))
30+
.extensions(mapOf("ftv1" to Base64.encode(ftv1Context.apolloOperationTracing.toProtoTrace(null, null).encode())))
3131
.build()
3232
}
3333
}

0 commit comments

Comments
 (0)