I'm using below micrometer dependencies along with spring boot graphql starter.
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-observation</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
When I use below graphqlclient to fetch data from one of my microservices I can see that traceId is being propagated for both services but unfortunately differently.
@Bean
public HttpGraphQlClient dataServiceHttpGraphQlClient(@Value("${url}") String dataServiceUrl) {
return HttpGraphQlClient.builder()
.url(url)
.header(HttpHeaders.CONTENT_TYPE, "application/json")
.header(HttpHeaders.ACCEPT, "application/json")
.build();
}
This's how I execute it:
public <T> Mono<List<T>> executeQuery(final String queryName,
final String path,
final Class<T> responseClass,
final Map<String, Object> variables) {
log.debug("Executing {} query: {}", path, queryName);
GraphQlClient.RequestSpec document = graphQlClient.documentName(queryName);
if (!CollectionUtils.isEmpty(variables)) document.variables(variables);
return document.execute()
.mapNotNull(response -> response.field(path).toEntityList(responseClass))
.onErrorResume(error -> Mono.error(new RuntimeException("Error " + error.getMessage()))); //TODO custom exception
}
When I check the headers in my requested service, I can see that no tracing header is added.
Any help would be appreciated.
I've figured this out. There're two topics here first you must bind WebClient.Builder
via Autowiring it since Spring handles the tracing itself.
Second there's a bug in the spring graphql https://github.com/spring-projects/spring-graphql/issues/675 So using 3.0.7-SNAPSHOT
for spring dependencies fixed it.
@Bean
public HttpGraphQlClient dataServiceHttpGraphQlClient(@Autowired WebClient.Builder webClientBuilder,
@Value("${url}") String url) {
return HttpGraphQlClient.builder(webClientBuilder)
.url(url)
.build();
}
UPDATE 3.0.7 is now released, you don't need to use SNAPSHOT anymore.