Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add federated tracing instrumentation #25

Merged
merged 17 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ An example of [graphql-spring-boot](https://www.graphql-java-kickstart.com/sprin

## Getting started

### Dependency management
### Dependency management with Gradle

Make sure JCenter is among your repositories:

Expand Down Expand Up @@ -56,3 +56,34 @@ you will also need to provide:

A minimal but complete example is available in
[InventorySchemaProvider](spring-example/src/main/java/com/apollographql/federation/springexample/InventorySchemaProvider.java).

### Federated tracing

To make your server generate performance traces and return them along with
responses to the Apollo Gateway (which then can send them to Apollo Graph
Manager), install the `FederatedTracingInstrumentation` into your `GraphQL`
object:

```java
GraphQL graphql = GraphQL.newGraphQL(graphQLSchema)
.instrumentation(new FederatedTracingInstrumentation())
.build()
```

It is generally desired to only create traces for requests that actually come
from Apollo Gateway, as they aren't helpful if you're connecting directly to
your backend service for testing. In order for `FederatedTracingInstrumentation`
to know if the request is coming from Gateway, you need to give it access to the
HTTP request's headers, by making the `context` part of your `ExecutionInput`
implement the `HTTPRequestHeaders` interface. For example:

```java
HTTPRequestHeaders context = new HTTPRequestHeaders() {
@Override
public @Nullable String getHTTPRequestHeader(String caseInsensitiveHeaderName) {
return myIncomingHTTPRequest.getHeader(caseInsensitiveHeaderName);
}
}
graphql.execute(ExecutionInput.newExecutionInput(queryString).context(context));

```
29 changes: 29 additions & 0 deletions graphql-java-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,21 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>

<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.0</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -54,6 +66,23 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>

<plugin>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a Maven expert. Maybe @pcarrier 's eyes on at least the Maven part of the PR could help?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neithr am I, but this seems to match https://www.xolstice.org/protobuf-maven-plugin/usage.html so LGTM.

<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.9.0:exe:${os.detected.classifier}</protocArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading