Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SO1S-321 backend logging 추가 #35

Merged
merged 8 commits into from
Sep 14, 2022
Merged

Conversation

shinilseop
Copy link
Contributor

SO1S-321 backend logging 추가

Tasks

  • filter단에서 logging 구현
  • Spring Sleuth, Zipkin을 통한 trace_id, span_id 로깅 및 트래픽 전송

Discussion

image

  • 인증이 허락되지 않은 경우는 filter에서 반환해버리기기 때문에 그런경우에는 filter보다 내부에서 처리하게 되면 로그가 남지 않는 문제가 있어 가장 최상단인 filter에서 로그를 남겨 들어오거나 나가는 모든 로그를 기록할 수 있도록 구현했습니다.
  • 다만 filter에서 InputStream을 사용해서 데이터를 사용해버리면 Controller 에서 데이터를 읽을 수가 없기 때문에 InputStream이 남아있을 수 있도록 Wrapper클래스를 상속받아 getInputStream시 cached된 데이터를 Copy 해서 사용하는 별도의 클래스를 만들어서 반환하도록 구현했습니다.
  • 이후 별도의 서비스 로직에서 남기는 로깅은 리팩토링때 같이 진행하겠습니다.

image

  • 현재 sleuth가 traceId와 spanId를 남겨주고 있으며 이러한 데이터를 연결해놓은 zipkin 주소로 보내고 있습니다.
// 로그인 예시

// REQUEST LOG
{"timestamp":"2022-09-14T12:43:37.413+09","level":"INFO","thread":"http-nio-8080-exec-2","mdc":{"traceId":"698b15a611e68d8d","spanId":"698b15a611e68d8d"},"logger":"io.so1s.backend.global.filter.LoggingFilter","message":"[REQUEST] Method=[POST], url=[/api/v1/signin], Header=[{authorization=Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzbzFzLmlvIiwiYXV0aCI6IlVzZXJSb2xlLkFETUlOKGlkPTIpLFVzZXJSb2xlLlVTRVIoaWQ9MykiLCJleHAiOjE2NjI1NTE0MTB9.AYuTijynNmREGwu33lVNd_vB2QIvWMB4eWshmfsxSQnFqPzsqD0Nw83dltcQ-miRSA0mcqoqVvr1fzHlEXB2sQ, content-length=57, postman-token=ac224f01-b18b-407e-8831-241fe310c347, host=localhost:8080, content-type=application/json, connection=keep-alive, accept-encoding=gzip, deflate, br, user-agent=PostmanRuntime/7.29.2, accept=*/*}], Body=[{\n    \"username\":\"so1s.io\",\n    \"password\":\"admin12345\"\n}]","context":"default"}

// RESPONSE LOG
{"timestamp":"2022-09-14T12:43:37.760+09","level":"INFO","thread":"http-nio-8080-exec-2","mdc":{"traceId":"698b15a611e68d8d","spanId":"698b15a611e68d8d"},"logger":"io.so1s.backend.global.filter.LoggingFilter","message":"[RESPONSE] Status=[200], Header=[{Authorization=Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzbzFzLmlvIiwiYXV0aCI6IlVzZXJSb2xlLkFETUlOKGlkPTIpLFVzZXJSb2xlLlVTRVIoaWQ9MykiLCJleHAiOjE2NjMyMTM0MTd9.bImoBzo7ehbG7fqL9AaMgCQlBaRadzL-7OM8EfclxNkRk4NlO86WzgP0XgiLCKpIi_WVh-pY6EtB6IGuaVNs6Q, Vary=Origin}], Body=[{\"token\":\"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzbzFzLmlvIiwiYXV0aCI6IlVzZXJSb2xlLkFETUlOKGlkPTIpLFVzZXJSb2xlLlVTRVIoaWQ9MykiLCJleHAiOjE2NjMyMTM0MTd9.bImoBzo7ehbG7fqL9AaMgCQlBaRadzL-7OM8EfclxNkRk4NlO86WzgP0XgiLCKpIi_WVh-pY6EtB6IGuaVNs6Q\"}]","context":"default"}

Jira

  • SO1S-321

@sonarqube-so1s
Copy link

Passed

Analysis Details

17 Issues

  • Bug 0 Bugs
  • Vulnerability 0 Vulnerabilities
  • Code Smell 17 Code Smells

Coverage and Duplications

  • Coverage 78.69% Coverage (81.30% Estimated after merge)
  • Duplications 0.00% Duplicated Code (1.70% Estimated after merge)

Project ID: So1S_backend_AYHrZkBbJVI_JANDYCcZ

View in SonarQube

Copy link
Member

@NEM-NE NEM-NE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~

build.gradle Show resolved Hide resolved
@shinilseop shinilseop merged commit 9a64c05 into main Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants