-
Spring Cloud Sleuth - Overview개발 일지/Cloud 2022. 7. 8. 15:06반응형
안녕하세요!
계속해서 스프링 클라우드 관련 아키텍처를 살펴보겠습니다.
그중에서 이번 포스트에서는 트레이스와 관련된 "Spring Cloud Sleuth"를 읽어볼게요.
https://spring.io/projects/spring-cloud-sleuth
Spring Cloud Sleuth는 분산 트레이싱을 위한 스프링 부트(auto-configuration)을 제공합니다.
기능:
Sleuth는 트레이싱을 시작하기 위해 필요한 것들을 구성해 줍니다.
→ 트레이스 데이터(spans)가 집계되는 위치, 유지할 트레이스 수(sampling), 원격 필드 전송여부(baggage), 그리고 트레이스된 라이브러리
여기에 더해 아래 사항을 포함합니다.
- Slf4J MDC에 트레이스 및 span-id를 추가하므로 로그 수집기에서 주어진 트레이스 또는 span로 부터 모든 로그를 추출할 수 있습니다.
- 스프링 애플리케이션(서블릿 필터, REST 템플릿, 스케쥴, 메시지 채널, 가상 클라이언트)에서 송 수신 엔드포인트를 계측합니다.
- "spring-cloud-sleuth-zipkin"을 사용하면, 애플리케이션은 HTTP를 통해 Zipkin 트레이스를 생성하여 전송합니다.
기본적으로 localshot:9411 로 실행되는 Zipkin 수집기 서비스로 집계됩니다.
spring.zipkin.baseUrl을 사용하며 Zipkin 경로를 설정합니다.
스프링 부트 설정:
buildscript { dependencies { classpath "io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE" } } apply plugin: "io.spring.dependency-management" dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${releaseTrainVersion}" } } dependencies { compile 'org.springframework.cloud:spring-cloud-starter-sleuth' }
위와 같이 Spring Cloud Sleuth를 추가하면, 이제 스프링 부트 애플리케이션 어느 곳에서나 트레이스 데이터를 생성할 수 있습니다.
@SpringBootApplication @RestController public class Application { private static Logger log = LoggerFactory.getLogger(DemoController.class); @RequestMapping("/") public String home() { log.info("Handling home"); return "Hello World"; } public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
이 애플리케이션을 실행하고 홈 페이지("/")에 방문해 볼까요?
그러면 트레이스ID와 범위(span) ID가 해당 로그에 표시됩니다.
이 앱이 다른 앱을 호출하면, 헤더에 트레이스 데이터를 보내고 리시버(수신)가 다른 Sleuth 앱인 경우 계속 트레이스 됩니다.
- 핸들러에 요청(request)를 명시적으로 로깅하는 대신, "logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG"로 설정할 수 있습니다.
- Sleuth는 기본적으로 속도가 제한된 sampler를 사용합니다. (초당 최대 1,000개의 트랜잭션을 샘플링합니다.)
- 서비스 명과 트레이스 및 범위(span) ID를 보려면, "spring.application.name=bar"를 설정할 수 있습니다.
자... 여기까지가 spring.io 공홈에 나와 있는 "Spring Cloud Sleuth"의 개요였습니다.
이후 포스트에서는 실제 튜토리얼을 진행한 내용을 기술해 보겠습니다.
반응형'개발 일지 > Cloud' 카테고리의 다른 글
Zipkin 살펴보기 (0) 2022.08.19 Spring Cloud Sleuth - 시작하기 (0) 2022.07.08 Spring Cloud Circuit Breaker (0) 2022.06.30 Centralized Configuation (feat. spring.io) (0) 2022.06.28 Spring Cloud Gateway (feat. spring.io) (0) 2022.06.27