Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 튜플
- trie
- Tistory
- pycon
- 가사 검색
- 티스토리
- bulk update
- 호텔 방 배정
- 프로그래머스
- 트라이 #trie #알고리즘
- 불량 사용자
- 징검다리 건너기
- 보행자 천국
- jdbc
- 트라이
- 카카오 인턴
- 알고리즘
- 크레인 인형뽑기 게임
- Python
- 티스토리 open api
- Open API
- CleanCode
- Spring Boot
Archives
- Today
- Total
택시짱의 개발 노트
Spring Cloud OpenFeign의 Logging 방법 본문
개요
- MSA 환경에서 다른 server로 요청 보내야할때 spring cloud openfeign을 이용하여 정보를 얻고 있는데 종종 의도한 동작을 하지 않을때가 있다. 예를들면 open feign에 설정한 timeout 을 초과 했을때, 또는 인증 문제, 등등
open feign에 logging을 남기기 전에는 내가 작성한 코드가 문제인지 open feign에서 문제 인지 단정하기 어려웠다.. 그래서 open feign에 logging을 달기 시작했다.
1. FeignConfiguration 작성
import feign.Logger
import org.springframework.cloud.openfeign.EnableFeignClients
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
@Configuration
@EnableFeignClients
class FeignConfiguration{
@Bean
fun feignLoggerLevel(): Logger.Level {
return feign.Logger.Level.FULL
}
}
2. Log를 남길 FeignClient Annotaion에 Configuration 등록
- 만약에 한개의 FeignConfiguration를 전역으로 사용한다면 추가하지 않아도 됩니다. )
package com.taxijjang.notification.application.port.out
import com.fasterxml.jackson.databind.ObjectMapper
import com.quriously.epictower.notification.application.configure.FeignConfiguration
import org.springframework.cloud.openfeign.FeignClient
@FeignClient(name = "ncloud", url = "https://sens.apigw.ntruss.com", configuration = [FeignConfiguration::class])
interface NCloudSmsFeignClient {
@PostMapping(
"/sms/v2/services/{serviceId}/messages",
consumes = ["application/json; charset=utf-8"],
produces = ["application/json; charset=utf-8"]
)
fun sendMessage(
@RequestHeader headers: HttpHeaders,
@PathVariable("serviceId") serviceId: String,
@RequestBody body: String,
): String
}
3. application.yml 파일에 Log를 남길 FeignClient 경로 지정
- 저는 local 환경에서만 log를 보려고 on-profie: local 일때 설정 했습니다.
spring:
config:
activate:
on-profile: local
logging:
level:
package com.taxijjang.notification.application.port.out.NCloudSmsFeignClient: DEBUG
4. 결과
- request, response를 명확하게 확인이 가능
[NCloudSmsFeignClient#sendMessage] ---> POST https://sens.apigw.ntruss.com/sms/v2/services/ncp%3Asms%3Akr%3A260252380873%3Aqube/messages HTTP/1.1
2023-06-30 19:55:15.698 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] Accept: application/json; charset=utf-8
2023-06-30 19:55:15.698 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] Content-Length: 199
2023-06-30 19:55:15.698 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] Content-Type: application/json; charset=utf-8
2023-06-30 19:55:15.698 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] x-ncp-apigw-signature-v2: {삭제처리}
2023-06-30 19:55:15.698 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] x-ncp-apigw-timestamp: 1688122515681
2023-06-30 19:55:15.698 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] x-ncp-iam-access-key: {삭제처리}
2023-06-30 19:55:15.698 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage]
2023-06-30 19:55:15.698 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] {"type":"SMS","contentType":"COMM","countryCode":"82","from":"{삭제처리}","content":"인증번호는 123456 입니다.","messages":[{"content":"인증번호는 123456 입니다.","to":"{삭제처리}"}]}
2023-06-30 19:55:15.698 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] ---> END HTTP (199-byte body)
2023-06-30 19:55:15.806 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] <--- HTTP/1.1 401 Unauthorized (107ms)
2023-06-30 19:55:15.806 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] connection: keep-alive
2023-06-30 19:55:15.806 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] content-length: 111
2023-06-30 19:55:15.806 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] content-type: application/json; charset=utf-8
2023-06-30 19:55:15.806 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] date: Fri, 30 Jun 2023 10:55:15 GMT
2023-06-30 19:55:15.806 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] server: nginx
2023-06-30 19:55:15.806 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] x-ncp-apigw-response-origin: APIGW
2023-06-30 19:55:15.806 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] x-ncp-trace-id: 32dj4cos3cp1o34dhp75hmcp1i
2023-06-30 19:55:15.806 DEBUG 29853 --- [nio-8081-exec-1] c.q.e.n.a.port.out.NCloudSmsFeignClient : [NCloudSmsFeignClient#sendMessage] <--- END HTTP (0-byte body)
반응형
'spring' 카테고리의 다른 글
Spring Boot Jdbc Bulk Update 삽질기 (Feat. VALUES Parsing Problem) (1) | 2024.02.15 |
---|---|
Kotlin Spring Boot 중첩 클래스에 @Valid 사용 - feat) 이모지 체크(Emoji Valid) (0) | 2023.11.28 |
AWS EC2 freetier instance에 spring boot 배포시 멈춤 현상 (0) | 2022.12.04 |
spring cloud open feign이란?? (작성중) (0) | 2022.10.23 |
Spring Boot - RestAPI (0) | 2022.07.31 |
Comments