Closed pulsar-gupta closed 1 year ago
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
@pulsar509 Are you using a RestTemplate
on the client side that has been created by a Spring Boot auto-configured RestTemplateBuilder
, or a custom RestTemplate
created in your code? If it is the latter, this StackOverflow answer might help you. If your setup doesn't match that StackOverflow question,
please provide a complete minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it and attaching it to this issue.
Thanks for your response Scott. currently, I am facing this issue with resttemplate and Feign both. Attached the code which uses rest template.
here is how I have initialized rest @Bean public RestTemplate getRestTemplate() { return new RestTemplate(); }
the stackoverflow solution is not working for me it is showing me compile time error as "Could not autowire. No beans of 'RestTemplateBuilderConfigurer' type found. "
@pulsar509 I checked the project you attached, injecting RestTemplateBuilderConfigurer
works as expected.
To have all the customizers applied on the RestTemplate
, you should not create instances of RestTemplate with new
, but rather use RestTemplateBuilder
:
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}
My problem is resolved with the above solution, thanks !
But I am still facing same issue while using Feign Client. Do not know what is going wrong.
Duplicates #33912
how to configure rest client with the same configuration to maintain same trace id across applications
I have 2 spring boot 3 apps ; first spring boot app is calling second app, both the apps are generating trace id but it is not same. I am using rest template to call api's.
2023-03-30 18:05:44,146 INFO 27964 --- [http-nio-8080-exec-1] INFO [model-microservice, c8fbc38554bcbd8254196a78c8f787fa, 53aba1b9c1f23476] com.sascia.modelmicroservice.controller.Controller.one(83) : Send API called
2023-03-30 18:05:44,050 INFO 22544 --- [http-nio-8081-exec-1] INFO [microservice, aa8e748aa9d0ea493ace7f5c3a8571af, 5cff6acc1680a6ab] com.sascia.modelmicroservice.controller.Controller.getTwo(92) : called 2 2023-03-30 18:05:44,160 INFO 22544 --- [http-nio-8081-exec-1] INFO [microservice, aa8e748aa9d0ea493ace7f5c3a8571af, 5cff6acc1680a6ab] com.sascia.modelmicroservice.controller.Controller.getTwo(104) : Reply = 0ne