graphql-java-kickstart / graphql-spring-boot

GraphQL and GraphiQL Spring Framework Boot Starters - Forked from oembedler/graphql-spring-boot due to inactivity.
https://www.graphql-java-kickstart.com/spring-boot/
MIT License
1.5k stars 325 forks source link

Cannot disable tracing response with graphql-spring-boot-starter version 15 #976

Open steam0 opened 1 year ago

steam0 commented 1 year ago

Describe the bug

I am in the progress of upgrading to version 15 of the following dependency

<dependency>
    <groupId>com.graphql-java-kickstart</groupId>
    <artifactId>graphql-spring-boot-starter</artifactId>
    <version>${graphql-java-kickstart.version}</version>
</dependency>

When I do that I get an extensions object in my response like the one below:

{
    "extensions": {
        "tracing": {
            "version": 1,
            "startTime": "2023-11-13T11:31:29.328819Z",
            "endTime": "2023-11-13T11:31:29.435707Z",
            "duration": 107035750,
            "parsing": {
                "startOffset": 2249667,
                "duration": 2161084
            },
            "validation": {
                "startOffset": 7496208,
                "duration": 5197250
            },
            "execution": {
                "resolvers": [
                   (...)
                ] 
            }
        }
    }

I would like to disable this part of the response as it is simply too much data for my clients to load every time. I am reading in the documentation here: https://github.com/graphql-java-kickstart/graphql-spring-boot#tracing-and-metrics

Apollo style tracing along with two levels of metrics based on them are currently configurable. Full tracing is based on the GraphQL java implementation, and can be enabled in the application.yml or application.properties file: the default value is false, with "metrics-only" being available. Metrics-only does not add the tracing extension to the response.

However even if I set the value to metrics-only the extensions object is included.

graphql:
  servlet:
    mapping: /api/graphql
    enabled: true
    exception-handlers-enabled: true
    actuator-metrics: true
    tracing-enabled: metrics-only

The only way to disable the "extensions" part of the reponse object is by disabling graphql.servlet.actuator-metrics: false all together which is not desirable as we wish to produce actuator metrics.

Expected behavior

When setting the config paramter graphql.servlet.tracing-enabled: metrics-only the response from the servlet should not include the "extensions" object.

If applicable, add screenshots to help explain your problem. MacOS Sonoma Java17 Intellij Spring Boot 3.1.4

bsara commented 11 months ago

this is fixed by this: https://github.com/graphql-java-kickstart/graphql-spring-boot/commit/4c5a3e075bfc93b9f239b80cc7d834c9983f4c94

It hasn't been released yet though.

In the mean time, you can add these spring beans as a workaround:


@Bean
@ConditionalOnExpression(
  "'${graphql.servlet.tracing-enabled:false}' == 'metrics-only' "
  + "|| '${graphql.servlet.tracing-enabled:false}' == 'true'"
)
public TracingInstrumentation tracingInstrumentation() {
  return new TracingInstrumentation();
}

@Bean
@ConditionalOnProperty(value = "graphql.servlet.actuator-metrics", havingValue = "true")
public MetricsInstrumentation metricsInstrumentation(
  MeterRegistry meterRegistry,
  @Value("${graphql.servlet.tracing-enabled}") String isTracingEnabled
) {
  return new MetricsInstrumentation(meterRegistry, Boolean.TRUE.toString().equalsIgnoreCase(isTracingEnabled)) {
    @Override
    public @NotNull CompletableFuture<ExecutionResult> instrumentExecutionResult(ExecutionResult executionResult, InstrumentationExecutionParameters parameters, InstrumentationState rawState) {
      return super.instrumentExecutionResult(executionResult, parameters);
    }
  };
}
steam0 commented 11 months ago

Thank you @bsara.

When do you think the new release will ship?

bsara commented 11 months ago

I don't control that, so I have no idea. Sorry.

oliemansm commented 11 months ago

I've released v15.1.0 today