Skip to content

Commit

Permalink
[Feature] Support Tracing for GlobalFilter and GatewayFilter in Gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqianwei committed Dec 16, 2024
1 parent d8192e5 commit 776d206
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class GatewayFilterInterceptor implements InstanceMethodsAroundIntercepto
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
STACK_DEEP.get().getAndIncrement();
if (isEntry()) {
ServerWebExchange exchange = (ServerWebExchange) allArguments[0];

Expand Down Expand Up @@ -67,10 +66,8 @@ public static EnhancedInstance getInstance(Object o) {
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
STACK_DEEP.get().getAndDecrement();
if (ContextManager.isActive()) {
if (isExit()) {
STACK_DEEP.remove();
if (isExit()) {
if (ContextManager.isActive()) {
ContextManager.stopSpan();
}
}
Expand All @@ -84,10 +81,14 @@ public void handleMethodException(EnhancedInstance objInst, Method method, Objec
}

private boolean isEntry() {
return STACK_DEEP.get().intValue() == 1;
return STACK_DEEP.get().getAndIncrement() == 0;
}

private boolean isExit() {
return STACK_DEEP.get().intValue() <= 0;
boolean isExit = STACK_DEEP.get().decrementAndGet() == 0;
if (isExit) {
STACK_DEEP.remove();
}
return isExit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class GatewayFilterInterceptor implements InstanceMethodsAroundIntercepto
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
STACK_DEEP.get().getAndIncrement();
if (isEntry()) {
ServerWebExchange exchange = (ServerWebExchange) allArguments[0];

Expand Down Expand Up @@ -67,10 +66,8 @@ public static EnhancedInstance getInstance(Object o) {
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
STACK_DEEP.get().getAndDecrement();
if (ContextManager.isActive()) {
if (isExit()) {
STACK_DEEP.remove();
if (isExit()) {
if (ContextManager.isActive()) {
ContextManager.stopSpan();
}
}
Expand All @@ -84,10 +81,14 @@ public void handleMethodException(EnhancedInstance objInst, Method method, Objec
}

private boolean isEntry() {
return STACK_DEEP.get().intValue() == 1;
return STACK_DEEP.get().getAndIncrement() == 0;
}

private boolean isExit() {
return STACK_DEEP.get().intValue() <= 0;
boolean isExit = STACK_DEEP.get().decrementAndGet() == 0;
if (isExit) {
STACK_DEEP.remove();
}
return isExit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class GatewayFilterInterceptor implements InstanceMethodsAroundIntercepto
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
STACK_DEEP.get().getAndIncrement();
if (isEntry()) {
ServerWebExchange exchange = (ServerWebExchange) allArguments[0];

Expand Down Expand Up @@ -67,10 +66,8 @@ public static EnhancedInstance getInstance(Object o) {
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
STACK_DEEP.get().getAndDecrement();
if (ContextManager.isActive()) {
if (isExit()) {
STACK_DEEP.remove();
if (isExit()) {
if (ContextManager.isActive()) {
ContextManager.stopSpan();
}
}
Expand All @@ -84,10 +81,14 @@ public void handleMethodException(EnhancedInstance objInst, Method method, Objec
}

private boolean isEntry() {
return STACK_DEEP.get().intValue() == 1;
return STACK_DEEP.get().getAndIncrement() == 0;
}

private boolean isExit() {
return STACK_DEEP.get().intValue() <= 0;
boolean isExit = STACK_DEEP.get().decrementAndGet() == 0;
if (isExit) {
STACK_DEEP.remove();
}
return isExit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class GatewayFilterInterceptor implements InstanceMethodsAroundIntercepto
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
STACK_DEEP.get().getAndIncrement();
if (isEntry()) {
ServerWebExchange exchange = (ServerWebExchange) allArguments[0];

Expand Down Expand Up @@ -67,10 +66,8 @@ public static EnhancedInstance getInstance(Object o) {
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
STACK_DEEP.get().getAndDecrement();
if (ContextManager.isActive()) {
if (isExit()) {
STACK_DEEP.remove();
if (isExit()) {
if (ContextManager.isActive()) {
ContextManager.stopSpan();
}
}
Expand All @@ -84,10 +81,14 @@ public void handleMethodException(EnhancedInstance objInst, Method method, Objec
}

private boolean isEntry() {
return STACK_DEEP.get().intValue() == 1;
return STACK_DEEP.get().getAndIncrement() == 0;
}

private boolean isExit() {
return STACK_DEEP.get().intValue() <= 0;
boolean isExit = STACK_DEEP.get().decrementAndGet() == 0;
if (isExit) {
STACK_DEEP.remove();
}
return isExit;
}
}

0 comments on commit 776d206

Please sign in to comment.