Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Persisting ZipKin SpanStore: MySQL and Cassandra

DZone's Guide to

Persisting ZipKin SpanStore: MySQL and Cassandra

The ZipKin distributed tracing system is great for testing latency issues, but by default, it doesn't persist the traces. Fortunately, you can fix that with Cassandra and MySQL.

· Database Zone
Free Resource

Traditional relational databases weren’t designed for today’s customers. Learn about the world’s first NoSQL Engagement Database purpose-built for the new era of customer experience.

ZipKin is a distributed tracing system that collects the traces from sleuth-enabled microservices and helps gather the timing data needed to troubleshoot latency issues in microservices.

The ZipKin provides a UI that displays the "waterfall" style graph of service calls — showing call durations as horizontal bars, the UI helps users visualize latency when requests travel across several microservices.

ZipKin, by default, does not persist traces, which are stored in-memory and thus lost on server startup. But ideally, if we plan to use ZipKin, we would like to persist the traces in some persistent store. So, to do that, ZipKin has given a provision to persist SpanStore in MySQL and Cassandra.

You can check the list of available storage options provided by ZipKin on GitHub

Below are some examples for persisting ZipKin SpansStore both in Cassandra 3 and MySQL.

Persisting ZipKin SpanStore to Cassandra 3

For Cassandra 3, add the dependencies below for Cassandra in your pom.xml

<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-storage-cassandra3</artifactId>
<version>1.17.1</version>
<exclusions>
<exclusion>
<artifactId>cassandra-driver-core</artifactId>
<groupId>com.datastax.cassandra</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.1.0</version>
</dependency>


Also in your application.yml/application.properties files, specify the database configuration information of you Cassandra database. Here, you need to specify the ZipKin storage type as "cassandra3".

server:
  port: 9411

spring:
  application:
    name: zipkin-server
  datasource:
    schema: classpath:/cassandra3-schema.cql
    url: jdbc:cassandra://127.0.0.1:9042
    keyspace: zipkin3
    contactPoints: localhost
    initialize: true
    continue-on-error: true
  sleuth:
    enabled: false

zipkin:
  storage:
      type: cassandra3


And that's it. That is the minimum configuration needed in to persist ZipKin SpanStore to Cassandra 3.

Persisting ZipKin SpanStore to MySQL 

For MySQL, add the dependencies below for MySQL in your pom.xml

<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-storage-mysql</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>


Now in your application.yml/application.properties files, specify the database configuration information of your MySQL database. Here, you need to specify the ZipKin storage type as "mysql".

server:
  port: 9411

spring:
  application:
    name: zipkin-server
  datasource:
    schema: classpath:/mysql.sql
    url: jdbc:mysql://localhost:3306/zipkin?autoReconnect=true&useSSL=false
    username: root
    driver-class-name: com.mysql.jdbc.Driver
    initialize: true
    continue-on-error: true
  sleuth:
    enabled: false

zipkin:
  storage:
      type: mysql


I have posted the code example for both MySQL and Cassandra 3 on GitHub.

Learn how the world’s first NoSQL Engagement Database delivers unparalleled performance at any scale for customer experience innovation that never ends.

Topics:
zipkin ,cassandra ,mysql ,database ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}