Skip to content

Commit a4ef10e

Browse files
committed
Add monograph usage reporting
1 parent fe5d727 commit a4ef10e

File tree

41 files changed

+1961
-1622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1961
-1622
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Version 0.1.0
44
_2024-10-23_
55

6-
* Add `apollo-execution-federation` with minimal `@key` support
6+
* Add `apollo-execution-subgraph` with minimal `@key` support
77
* Add support for suspending resolvers and parallel execution (#18)
88
* Update Ktor to version 3
99

Writerside/doc.tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@
2424
<toc-element toc-title="Apollo Federation">
2525
<toc-element topic="federation.md"/>
2626
</toc-element>
27+
<toc-element toc-title="Apollo Usage Reporting">
28+
<toc-element topic="usage-reporting.md"/>
29+
</toc-element>
2730
</instance-profile>

Writerside/topics/federation.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
Apollo Kotlin Execution supports [Apollo Federation](https://www.apollographql.com/federation).
44

5-
To use federation, add the `apollo-execution-federation` artifact to your project:
5+
To use federation, add the `apollo-execution-subgraph` artifact to your project:
66

77
```kotlin
88
dependencies {
99
// Add the federation dependency
10-
implementation("com.apollographql.execution:apollo-execution-federation:%latest_version%")
10+
implementation("com.apollographql.execution:apollo-execution-subgraph:%latest_version%")
1111
}
1212
```
1313

14-
The `apollo-execution-federation` artifact contains the `@GraphQLKey` annotation allowing you to define [entities](https://www.apollographql.com/docs/graphos/schema-design/federated-schemas/entities/intro).
14+
The `apollo-execution-subgraph` artifact contains the `@GraphQLKey` annotation allowing you to define [entities](https://www.apollographql.com/docs/graphos/schema-design/federated-schemas/entities/intro).
1515

1616
## Defining entities
1717

@@ -105,7 +105,10 @@ Apollo Kotlin Execution supports [federated tracing](https://www.apollographql.c
105105

106106
Ftv1 records timing information for each field and reports that information to the router through the `"ftv1"` extension.
107107

108-
This is done through the `Ftv1Instrumentation` and its matching `Ftv1Context`:
108+
> If you have a monograph, see [usage reporting](usage-reporting.md) instead for how to send tracing information to the Apollo usage reporting endpoint.
109+
{style=note}
110+
111+
To enable federated tracing, configure your `ExecutableSchema` with a `Ftv1Instrumentation` and matching `Ftv1Context`:
109112

110113
```kotlin
111114
// Install the Ftv1Instrumentation in the executable schema

Writerside/topics/getting-started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Apollo Kotlin Execution:
1111
* Doesn't use reflection. Use it on the JVM and enjoy ultra-fast start times. Or use it with Kotlin native. Apollo Kotlin Execution is KMP-ready!
1212
* Supports custom scalars, subscriptions, persisted queries and everything in the current [GraphQL draft](https://spec.graphql.org/draft/).
1313
* Integrates with [Ktor](ktor.md), [http4k](http4k.md) and [Spring](spring.md).
14+
* Supports [Apollo Federation](federation.md).
1415

1516
Under the hood, Apollo Kotlin Execution uses [KSP](https://kotlinlang.org/docs/ksp-overview.html) to generate GraphQL resolvers and types from your Kotlin code.
1617

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Apollo Usage Reporting
2+
3+
Apollo Kotlin Execution supports sending [operation and field reports](https://www.apollographql.com/docs/graphos/platform/insights/sending-operation-metrics) to GraphOS.
4+
5+
> If you have a federated graph, see [ftv1](federation.md#tracing-ftv1) instead for how to send tracing information to the router.
6+
{style=note}
7+
8+
## Sending usage reports
9+
10+
Operation and field reports are sent using a protobuf protocol to `https://usage-reporting.api.apollographql.com/api/ingress/traces`.
11+
12+
Apollo Kotlin collects, encodes and sends those reports using the `apollo-execution-reporting` artifact:
13+
14+
```kotlin
15+
dependencies {
16+
// Add the Apollo monograph artifact
17+
implementation("com.apollographql.execution:apollo-execution-reporting:%latest_version%")
18+
}
19+
```
20+
21+
To enable reports, configure your `ExecutableSchema` with a `ApolloReportsInstrumentation` and matching `ApolloReportsContext`:
22+
23+
```kotlin
24+
// Get your API key from the environment or secret manager
25+
val apolloKey = System.getenv("APOLLO_KEY")
26+
27+
// Install the ApolloReportsInstrumentation in the executable schema
28+
val schema = ServiceExecutableSchemaBuilder()
29+
.addInstrumentation(ApolloReportsInstrumentation(apolloKey))
30+
.build()
31+
32+
// Create a new ApolloReportsContext() for each operation and use it through execution
33+
val reportsContext = ApolloReportsContext()
34+
val response = schema.execute(request, reportsContext)
35+
36+
// The reports are sent in the background
37+
```

apollo-execution-federation/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

apollo-execution-federation/api/apollo-execution-federation.api

Lines changed: 0 additions & 27 deletions
This file was deleted.

apollo-execution-federation/api/apollo-execution-federation.klib.api

Lines changed: 0 additions & 29 deletions
This file was deleted.

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

Lines changed: 0 additions & 40 deletions
This file was deleted.

apollo-execution-processor/src/main/kotlin/com/apollographql/execution/processor/codegen/ExecutableSchemaBuilderBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ internal class ExecutableSchemaBuilderBuilder(
106106
add(".addCoercing(%S, %M)\n", sirEnumDefinition.name, context.coercings.get(sirEnumDefinition.name))
107107
}
108108
if (entityResolver != null) {
109-
add(".addCoercing(%S, %M)\n", "_Any", MemberName("com.apollographql.execution.federation", "_AnyCoercing"))
109+
add(".addCoercing(%S, %M)\n", "_Any", MemberName("com.apollographql.execution.subgraph", "_AnyCoercing"))
110110
}
111111
listOf("query", "mutation", "subscription").forEach { operationType ->
112112
val sirObjectDefinition = sirDefinitions.rootType(operationType)

0 commit comments

Comments
 (0)