Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dependencies {

// Monitoring
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-cloudwatch2'
implementation 'io.micrometer:micrometer-registry-prometheus'

// Tracing
implementation 'io.micrometer:micrometer-tracing-bridge-otel'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@
@Order(Ordered.HIGHEST_PRECEDENCE)
public class LocalLoggingAspect {

@Around("""
execution(* com.daedan.festabook..*.*(..)) &&
(
within(@org.springframework.web.bind.annotation.RestController *) ||
within(@org.springframework.stereotype.Service *) ||
within(@com.daedan.festabook.global.logging.Loggable *) ||
execution(* org.springframework.data.jpa.repository.JpaRepository+.*(..))
)
"""
)
@Around("com.daedan.festabook.global.logging.LoggingPointcuts.applicationLayers()")
public Object allLayersLogging(ProceedingJoinPoint joinPoint) throws Throwable {
StopWatch stopWatch = new StopWatch();
String className = joinPoint.getSignature().getDeclaringType().getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

import com.daedan.festabook.global.logging.dto.MethodEventLog;
import com.daedan.festabook.global.logging.dto.MethodLog;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
Expand All @@ -23,21 +20,10 @@
@Component
@Profile("prod | dev")
@RequiredArgsConstructor
@Order(Ordered.HIGHEST_PRECEDENCE)
@Order(Ordered.HIGHEST_PRECEDENCE + 1)
public class LoggingAspect {

private final Tracer tracer;

@Around("""
execution(* com.daedan.festabook..*.*(..)) &&
(
within(@org.springframework.web.bind.annotation.RestController *) ||
within(@org.springframework.stereotype.Service *) ||
within(@com.daedan.festabook.global.logging.Loggable *) ||
execution(* org.springframework.data.jpa.repository.JpaRepository+.*(..))
)
"""
)
@Around("com.daedan.festabook.global.logging.LoggingPointcuts.applicationLayers()")
public Object allLayersLogging(ProceedingJoinPoint joinPoint) throws Throwable {
StopWatch stopWatch = new StopWatch();
String className = joinPoint.getSignature().getDeclaringType().getSimpleName();
Expand All @@ -46,23 +32,15 @@ public Object allLayersLogging(ProceedingJoinPoint joinPoint) throws Throwable {
MethodEventLog methodEvent = MethodEventLog.from(className, methodName);
log.info("", kv("event", methodEvent));

String spanName = className + "::" + methodName;
Span span = tracer.spanBuilder(spanName).startSpan();

Object result = null;
stopWatch.start();
try (Scope scope = span.makeCurrent()) {
result = joinPoint.proceed();
try {
return joinPoint.proceed();
} finally {
stopWatch.stop();
long executionTime = stopWatch.getTotalTimeMillis();

MethodLog methodLog = MethodLog.from(className, methodName, executionTime);
log.info("", kv("event", methodLog));

span.end();
}

return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.daedan.festabook.global.logging;

import org.aspectj.lang.annotation.Pointcut;

public final class LoggingPointcuts {

private LoggingPointcuts() {
}

@Pointcut("""
execution(* com.daedan.festabook..*.*(..)) &&
(
within(@org.springframework.web.bind.annotation.RestController *) ||
within(@org.springframework.stereotype.Service *) ||
within(@com.daedan.festabook.global.logging.Loggable *) ||
execution(* org.springframework.data.jpa.repository.JpaRepository+.*(..))
)
""")
public void applicationLayers() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.daedan.festabook.global.logging;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;
import lombok.RequiredArgsConstructor;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Profile("prod | dev")
@RequiredArgsConstructor
@Order(Ordered.HIGHEST_PRECEDENCE)
public class TracingAspect {

private final Tracer tracer;

@Value("${env}")
private String env;
Copy link
Contributor

Choose a reason for hiding this comment

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

생성자로 주입받아서 final 붙이는건 어때요?

Copy link
Member Author

Choose a reason for hiding this comment

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

좋아요~ 바로 반영했습니다!


@Around("com.daedan.festabook.global.logging.LoggingPointcuts.applicationLayers()")
public Object trace(ProceedingJoinPoint joinPoint) throws Throwable {
Copy link
Contributor

Choose a reason for hiding this comment

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

그 log에서 사용하는 traceId랑 trace에서 사용하는 traceId가 기존에 동일했는데 분리했을 때도 같은지 확인해봐야 할 것 같아요!

Copy link
Member Author

Choose a reason for hiding this comment

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

구두로 설명 드렸습니다! 같네요.

String className = joinPoint.getSignature().getDeclaringType().getSimpleName();
String methodName = joinPoint.getSignature().getName();

String spanName = className + "::" + methodName;
Span span = tracer.spanBuilder(spanName).startSpan();
span.setAttribute("env", env);

try (Scope scope = span.makeCurrent()) {
return joinPoint.proceed();
} finally {
span.end();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class SecurityConfig {
"/lineups",
"/time-tags",
"/actuator/health",
"/actuator/prometheus",
"/test/**"
};

Expand Down
26 changes: 26 additions & 0 deletions src/main/resources/application-monitoring.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
server:
tomcat:
mbeanregistry:
enabled: true

management:
server:
port: 9000
endpoints:
web:
exposure:
include: prometheus, health
metrics:
tags:
application: ${spring.application.name}
prometheus:
metrics:
export:
enabled: true
tracing:
sampling:
probability: 1.0
otlp:
tracing:
endpoint: "http://localhost:4317"
transport: grpc
6 changes: 1 addition & 5 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ server:
context-path: /api
shutdown: graceful
forward-headers-strategy: native
tomcat:
mbeanregistry:
enabled: true

spring:
datasource:
Expand All @@ -21,7 +18,7 @@ spring:
hibernate:
ddl-auto: none
profiles:
include: secret
include: secret, monitoring
lifecycle:
# WAS 종료 대기 시간 15초로 설정
timeout-per-shutdown-phase: 15s
Expand All @@ -31,7 +28,6 @@ spring:
max-file-size: 10MB
max-request-size: 11MB


storage:
image:
max-size: 10485760 # 10 * 1024 * 1024, 10MB
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- DEV, PROD: JSON 형식으로 로그 파일 기록 -->
<springProfile name="prod | dev">
<property name="LOG_FILE_PATH" value="/home/ubuntu/2025-festabook/spring-logs"/>
<property name="LOG_FILE_PATH" value="/var/log"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

잘 기억이 나지 않아서, 이거 변경한 이유만 간단하게 남겨주세요! 인지하고 있을게요

Copy link
Member Author

Choose a reason for hiding this comment

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

후유 의견으로, 기존 경로는 환경 의존성이 강해서, 서버 자체 환경에서도 표준적으로 수집이가능한 /var/log로 통일했었던 기억이 있습니다.


<appender name="JSON_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_FILE_PATH}/application.json</file>
Expand Down
Loading