-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerAspect.java
More file actions
27 lines (24 loc) · 810 Bytes
/
TimerAspect.java
File metadata and controls
27 lines (24 loc) · 810 Bytes
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
package org.javaspringcourse.metric.timer;
import io.micrometer.core.instrument.MeterRegistry;
import lombok.RequiredArgsConstructor;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Aspect
@Component
@RequiredArgsConstructor
public class TimerAspect {
private final MeterRegistry meterRegistry;
@Around("@annotation(timer)")
public Object timer(ProceedingJoinPoint jp, TimerMetric timer) {
return meterRegistry.timer("shop.api-request.timer." + timer.name()).record(() ->
{
try {
return jp.proceed();
} catch (Throwable e) {
throw new RuntimeException(e);
}
});
}
}