Instrumenting the GraphQL APIs
The GraphQL Java library supports the instrumentation of the GraphQL APIs. This can be used to support metrics, tracing, and logging. The DGS framework also uses it. You just must mark the instrumentation class with the Spring @
Component
annotation.
The instrumentation bean can be implemented using the graphql.execution. instrumentation.Instumentation
interface. Here, you have to write boilerplate code, which may increase the unit test automation code for you. Another way that is much easier is to extend the SimpleInstrumentation
class, which does the simple implementation for you. However, you can override the methods for custom implementation.
Let’s add instrumentation that will record the time taken by the data fetcher and complete GraphQL request processing. This metric may help you to fine-tune the performance and identify the fields that take more time to resolve.
Before adding the tracing, let’s add the custom header in the...