Spring GraphQL - DataFetcher observations-missing keys

82 views Asked by At

I am trying to monitor a Spring Boot GraphQL application using Spring Boot 3 Observability features. I managed to do well the monitoring for succesfull requests and now I am trying to collect some info about GraphQl errors as well.

My application has spring-boot-actuator as dependency, has the ObservedAspect configured and I am using the @Observed annotation. That is all, no custom handlers, filters or anything else that could hide/override the auto functions of Spring DataFetchers. No custom handling of GraphQL errors, the default behaviour is kept.

According to Spring documentation, by default they are creating the following low cardinality keys(https://docs.spring.io/spring-graphql/reference/observability.html):

enter image description here

And indeed, for a succesfull request I managed to see them:

enter image description here

But in case of a ValidationError, or any other error, for the exact same operation called, when I expected to have those error fields populated, those keys are missing completely.

I tried to debug the application, the error is well collected and set in ObservationContext:

enter image description here

But somewhere along the way, is lost or intentionally not displayed?

I have no idea about what is happening and why isn't shown in the end. If I am doing something wrong or if I understood something wrong, please let me know.

Also, what is the best way to monitor GraphQL errors in a Spring Boot Application using the latest observability features?

1

There are 1 answers

0
Brian Clozel On

An issue was created about this in the Spring for GraphQL project and I'll summarize here the result.

This is currently the expected behavior for Spring for GraphQL applications. The "graphql.request" observations are about the entire request processing (many queries and data fetching operations), while the "graphql.datafetcher" observations are about single data fetching operations.

When a GraphQL request is processed, the engine first starts by parsing and validating the incoming document. If the document is invalid, the response rejects it with error details - no data fetcher has been called in this case so there aren't any datafetcher observation.

It is true that the current graphql.request" observation only mentions that it failed (see the "graphql.outcome" keyvalue) but doesn't say why.

In Spring for GraphQL, we're now considering improving the "graphql.request" observation by adding errors as observation events. This would mean:

  • "graphql.request.ValidationError", "graphql.request.InvalidSyntax" counters in the metrics world
  • a span annotation on the "graphql.request" trace for each error type with more details.

This should be considered for Spring for GraphQL 1.3.0, feel free to comment there to give feedback until then.