I am stucked to find any proper example which can demonstrate me to find out traces and store it in MySQL database locally. I have used zipkin server to visualize my distrubuted tracing of microservices. If any one worked with Spring Cloud Sleuth with gradle in latest version please handover the perfect Example which can help me.
Here' my code:
build.gradle
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "Hoxton.SR4")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
implementation 'org.springframework.cloud:spring-cloud-sleuth-zipkin'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.16'
// https://mvnrepository.com/artifact/io.zipkin.zipkin2/zipkin-storage-mysql-v1
implementation group: 'io.zipkin.zipkin2', name: 'zipkin-storage-mysql-v1', version: '2.23.2'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '2.5.0'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
application.properties
server.port=8083
spring.application.name=service1
#logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG
spring.sleuth.sampler.percentage=1.0
spring.zipkin.enabled=true
spring.zipkin.base-url=http://localhost:9411/
spring.sleuth.enabled=true
spring.zipkin.storage.type=mysql
spring.datasource.url=jdbc:mysql://localhost:3306/zipkin
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.schema=classpath:mysql.sql
spring.datasource.initialization-mode=always
spring.jpa.show-sql=true
spring.sleuth.web.enabled=true
spring.zipkin.sender.type=web
Controller.class
@RestController
@Slf4j
@RequiredArgsConstructor
public class SpaceShipRestController {
private final RestTemplate restTemplate;
@GetMapping("/service1")
public String service1() {
log.info("service1 start");
String service2 = restTemplate.getForObject("http://localhost:8090/service2", String.class);
String service3 = restTemplate.getForObject("http://localhost:9090/service3", String.class);
log.info("call" + service2 + "and" + service3);
return "calling service2";
}
}
Apllication.class
@SpringBootApplication
@EnableAutoConfiguration
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
@Bean
@Primary
public MySQLStorage mySQLStorage(DataSource datasource) {
return MySQLStorage.newBuilder().datasource(datasource).executor(Runnable::run).build();
}
}
I have Used zipkin-server-2.23.2-exec jar to lauch server on port localhost:9411 as default port using this command on cmd. java -jar zipkin-server-2.23.2-exec
My zipkin is up and working fine i am just stucked to store the traces in my MySQL DB the tables are getting created properly. But the record are empty. I don't no why i think i am missing any configuration. I followed this article as they shown to store traces in DB. Can anyone suggest me where i am missing to evalute.