generated from pricelees/issue-pr-template
feat: AOP를 이용한 서비스 로직에서의 트레이싱 Observation 추가
This commit is contained in:
parent
31f15aa80c
commit
ca295f4374
@ -0,0 +1,25 @@
|
|||||||
|
package com.sangdol.common.web.asepct
|
||||||
|
|
||||||
|
import io.micrometer.observation.Observation
|
||||||
|
import io.micrometer.observation.ObservationRegistry
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint
|
||||||
|
import org.aspectj.lang.annotation.Around
|
||||||
|
import org.aspectj.lang.annotation.Aspect
|
||||||
|
import org.aspectj.lang.annotation.Pointcut
|
||||||
|
|
||||||
|
@Aspect
|
||||||
|
class ServiceObservationAspect(
|
||||||
|
private val observationRegistry: ObservationRegistry
|
||||||
|
) {
|
||||||
|
|
||||||
|
@Pointcut("execution(* com.sangdol..business..*Service*.*(..))")
|
||||||
|
fun allServices() {}
|
||||||
|
|
||||||
|
@Around("allServices()")
|
||||||
|
fun runWithObserve(joinPoint: ProceedingJoinPoint): Any? {
|
||||||
|
val methodName: String = joinPoint.signature.toShortString()
|
||||||
|
|
||||||
|
return Observation.createNotStarted(methodName, observationRegistry)
|
||||||
|
.observe<Any?> { joinPoint.proceed() }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
package com.sangdol.common.web.config
|
||||||
|
|
||||||
|
import com.sangdol.common.web.asepct.ServiceObservationAspect
|
||||||
|
import io.micrometer.observation.ObservationPredicate
|
||||||
|
import io.micrometer.observation.ObservationRegistry
|
||||||
|
import io.micrometer.observation.aop.ObservedAspect
|
||||||
|
import jakarta.servlet.http.HttpServletRequest
|
||||||
|
import org.springframework.beans.factory.annotation.Value
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.http.server.observation.ServerRequestObservationContext
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
class ObservationConfig(
|
||||||
|
@Value("\${management.endpoints.web.base-path}") private val actuatorPath: String
|
||||||
|
) {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun observedAspect(observationRegistry: ObservationRegistry): ObservedAspect {
|
||||||
|
return ObservedAspect(observationRegistry)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun serviceObservationAspect(observationRegistry: ObservationRegistry): ServiceObservationAspect {
|
||||||
|
return ServiceObservationAspect(observationRegistry)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun excludeActuatorPredicate(): ObservationPredicate {
|
||||||
|
return ObservationPredicate { _, context ->
|
||||||
|
if (context !is ServerRequestObservationContext) {
|
||||||
|
return@ObservationPredicate true
|
||||||
|
}
|
||||||
|
|
||||||
|
val servletRequest: HttpServletRequest = context.carrier
|
||||||
|
val requestUri = servletRequest.requestURI
|
||||||
|
|
||||||
|
!requestUri.contains(actuatorPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user