Spring Boot GraphQL Tutorial #24 - Instrumentation (Request Logging)

Опубликовано: 09 Октябрь 2024
на канале: Philip Starritt
5,194
52

GraphQL Instrumentation allows you to inject code that can observe the execution of a query and also change the runtime behaviour. Let's take advantage of this to log the graphql request's query, variables, any exceptions thrown and execution time.


To do this we create a spring bean of type graphql.execution.instrumentation.Instrumentation.
To remove boilerplace no-op code, we override no-op SimpleInstrumentation implementation and just override the beginExecution method.


We then return a SimpleInstrumentationContext with an whenCompleted callable containing our duration logic and log message.

It is possible that multiple Instrumentation objects are in one graphql server.


In the next video, I demo the TracingInstrumentation that will capture the execution time of the fields and place the results into the graphql response.

See you in the next video!

Cheers!
Philip


GraphQL Instrumentation: https://www.graphql-java.com/document...


Spring Boot GraphQL Java: https://github.com/graphql-java-kicks...


Good article on graphql paypal instrumentation:   / graphql-instrumenting-your-api-and-unlocki...  


Image on thumbnail: https://wallhaven.cc/w/ymepyg