Skip to content

Add operation name to operationWrapper of querystring in GraphQLRequestSerializer #590

@idegroot

Description

@idegroot

I would like to trace the timing of resolving the distinct query operations in my graphql project. The metrics are added to the Spring Actuator when the operationName is present in the query, otherwise the operationName is set to "unknown" (see also [https://github.com/graphql-java-kickstart/graphql-java-servlet/issues/264] and [https://spectrum.chat/graphql-java/general/reading-operationname-from-query-text~30cc09d5-0a55-4406-88da-7e8d0b91141a]).

In GraphQLRequestSerializer only the operationType is added to the serialized form. It would be very helpful if also the operationName would be added.

So the serialized query request should be changed from:
"query { MyOperationName: MyOperationName(...) {....} }"

to:
"query MyOperationName { MyOperationName: MyOperationName(...) {....} }"

The reporting will then change from

# TYPE graphql_timer_query_seconds_max gauge
graphql_timer_query_seconds_max{application="my-service",operation="execution",operationName="unknown",} 0.834386921
graphql_timer_query_seconds_max{application="my-service",operation="validation",operationName="unknown",} 0.011841088
graphql_timer_query_seconds_max{application="my-service",operation="parsing",operationName="unknown",} 0.005506738

to

# TYPE graphql_timer_query_seconds_max gauge
graphql_timer_query_seconds_max{application="my-service",operation="execution",operationName="MyOperationName1",} 0.536624579
graphql_timer_query_seconds_max{application="my-service",operation="execution",operationName="MyOperationName2",} 0.265046921
graphql_timer_query_seconds_max{application="my-service",operation="parsing",operationName="MyOperationName2",} 7.57737E-4
graphql_timer_query_seconds_max{application="my-service",operation="parsing",operationName="MyOperationName1",} 0.003428935
graphql_timer_query_seconds_max{application="my-service",operation="validation",operationName="MyOperationName1",} 0.011300205
graphql_timer_query_seconds_max{application="my-service",operation="validation",operationName="MyOperationName2",} 0.001935768

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions