Giter Site home page Giter Site logo

itqpleyva / springbootmicroserviceslogtrace Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 91 KB

Spring Cloud Microservices Log Tracing example using Sleuth and Zipkin

Java 100.00%
zipkin sleuth zipkin-sleuth spring-cloud springboot java-8 microservices

springbootmicroserviceslogtrace's Introduction

#SpringMicroservicesLogTracing

Spring Cloud Microservices Log Tracing example using Sleuth and Zipkin

In this example we create Zipkin server to trace all logs from microservices

Dependencies for Zipkin server :

<dependencies>	
	<dependency>	
		<groupId>org.springframework.boot</groupId>	
		<artifactId>spring-boot-starter-web</artifactId>	
					<exclusions>
				<exclusion>
					<groupId>ch.qos.logback</groupId>
					<artifactId>logback-classic</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.apache.logging.log4j</groupId>
					<artifactId>log4j-to-slf4j</artifactId>
				</exclusion>
			</exclusions>	
		</dependency>	
	<dependency>	
		<groupId>org.springframework.boot</groupId>		
		<artifactId>spring-boot-devtools</artifactId>		
		<scope>runtime</scope>	
	</dependency>	
	<dependency>		
		<groupId>org.springframework.boot</groupId>		
		<artifactId>spring-boot-starter-test</artifactId>		
		<scope>test</scope>	
	</dependency>	
	<dependency>	
		<groupId>io.zipkin.java</groupId>	
		<artifactId>zipkin-server</artifactId>	
		<version>2.11.5</version>
	</dependency>	
	<dependency>	
		<groupId>io.zipkin.java</groupId>	
		<artifactId>zipkin-autoconfigure-ui</artifactId>	
		<version>2.11.5</version>	
	</dependency>
</dependencies>

Dependencies for Sleuth microservice:

  <dependencies>   
		<dependency>
		    <groupId>org.springframework.cloud</groupId>
		    <artifactId>spring-cloud-starter-sleuth</artifactId>
		    <version>2.0.2.RELEASE</version>
		</dependency>
      <dependency>
	 <groupId>org.springframework.boot</groupId>
	 <artifactId>spring-boot-starter-web</artifactId>
      </dependency> 
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-zipkin</artifactId>
			<version>2.0.2.RELEASE</version>
		</dependency>
   </dependencies>

Zipkin server main class:

	@SpringBootApplication
	@EnableZipkinServer
	public class Main {

	public static void main(String[] args) {
		
		SpringApplication.run(Main.class, args);

		}

	}

Sleuth microservice main class:

	@SpringBootApplication
	@RestController
	public class Main {

		private static final Logger LOG = Logger.getLogger(Main.class.getName());
		
		public static void main(String[] args) {
			
			SpringApplication.run(Main.class, args);
		}
		  @RequestMapping("/") 
		  public String home() { 
			
			LOG.log(Level.INFO, "Creating new log");
			
			return "Hello from microservice"; 

		  } 
	}

Zipkin server application.properties:

	spring.application.name=zipkinserver
	server.port:9411
	management.metrics.web.server.auto-time-requests=false

Sleuth microservice application.properties:

	spring.application.name=SleuthExample
	spring.zipkin.baseUrl=http://localhost:9411/
	spring.sleuth.sampler.probability = 1.0

Final result:

If we go to: http://localhost:8080/ we can see: "Hello from microservice" message

If we go to: http://localhost:8080/home we can see: "Error type=Not Found, status=404" message

Then we can go to zipkin server(http://localhost:9411/zipkin/) to see bouth logs:

If we select the red log related to the http://localhost:8080/home request, we can see the details of error log:

springbootmicroserviceslogtrace's People

Contributors

itqpleyva avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.