Merge pull request #3860 from khatwaniNikhil/BAEL-1633
Changes for BAEL-1633
This commit is contained in:
commit
f0c3155833
|
@ -3,17 +3,34 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>2.0.0.RELEASE</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>spring-sleuth</artifactId>
|
<artifactId>spring-sleuth</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
|
||||||
<artifactId>parent-boot-5</artifactId>
|
<repositories>
|
||||||
<groupId>com.baeldung</groupId>
|
<repository>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<id>spring-milestones</id>
|
||||||
<relativePath>../parent-boot-5</relativePath>
|
<name>Spring Milestones</name>
|
||||||
</parent>
|
<url>https://repo.spring.io/libs-milestone</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -27,15 +44,15 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-dependencies</artifactId>
|
<artifactId>spring-cloud-sleuth</artifactId>
|
||||||
<version>Camden.SR3</version>
|
<version>2.0.0.M7</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -3,11 +3,13 @@ package com.baeldung.spring.session;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cloud.sleuth.Span;
|
|
||||||
import org.springframework.cloud.sleuth.Tracer;
|
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import brave.Span;
|
||||||
|
import brave.Tracer;
|
||||||
|
import brave.Tracer.SpanInScope;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SleuthService {
|
public class SleuthService {
|
||||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
@ -26,12 +28,12 @@ public class SleuthService {
|
||||||
public void doSomeWorkNewSpan() throws InterruptedException {
|
public void doSomeWorkNewSpan() throws InterruptedException {
|
||||||
logger.info("I'm in the original span");
|
logger.info("I'm in the original span");
|
||||||
|
|
||||||
Span newSpan = tracer.createSpan("newSpan");
|
Span newSpan = tracer.newTrace().name("newSpan").start();
|
||||||
try {
|
try (SpanInScope ws = tracer.withSpanInScope(newSpan.start())) {
|
||||||
Thread.sleep(1000L);
|
Thread.sleep(1000L);
|
||||||
logger.info("I'm in the new span doing some cool work that needs its own span");
|
logger.info("I'm in the new span doing some cool work that needs its own span");
|
||||||
} finally {
|
} finally {
|
||||||
tracer.close(newSpan);
|
newSpan.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("I'm in the original span");
|
logger.info("I'm in the original span");
|
||||||
|
|
Loading…
Reference in New Issue