diff --git a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/AsyncContextSpanEventEndPointInterceptor.java b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/AsyncContextSpanEventEndPointInterceptor.java index e4a9efd82d19..08f2f6231bde 100644 --- a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/AsyncContextSpanEventEndPointInterceptor.java +++ b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/AsyncContextSpanEventEndPointInterceptor.java @@ -23,9 +23,9 @@ import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; -import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; import java.util.Objects; @@ -66,7 +66,7 @@ public void before(Object target, Object[] args) { logger.debug("Asynchronous invocation. asyncTraceId={}, trace={}", asyncContext, trace); } // entry scope. - entryAsyncTraceScope(trace); + ScopeUtils.entryAsyncTraceScope(trace); try { // trace event for default & async. @@ -107,7 +107,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } // leave scope. - if (!leaveAsyncTraceScope(trace)) { + if (!ScopeUtils.leaveAsyncTraceScope(trace)) { if (logger.isWarnEnabled()) { logger.warn("Failed to leave scope of async trace {}.", trace); } @@ -125,7 +125,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } } finally { trace.traceBlockEnd(); - if (isAsyncTraceDestination(trace)) { + if (ScopeUtils.isAsyncTraceEndScope(trace)) { if (isDebug) { logger.debug("Arrived at async trace destination. asyncTraceId={}", asyncContext); } @@ -164,33 +164,6 @@ private void deleteAsyncTrace(final Trace trace) { trace.close(); } - private void entryAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - scope.tryEnter(); - } - } - - private boolean leaveAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - } else { - return false; - } - } - return true; - } - - private boolean isAsyncTraceDestination(final Trace trace) { - if (!trace.isAsync()) { - return false; - } - - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - return scope != null && !scope.isActive(); - } private void finishAsyncState(final AsyncContext asyncContext) { if (AsyncContextUtils.asyncStateFinish(asyncContext)) { diff --git a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/AsyncContextSpanEventSimpleAroundInterceptor.java b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/AsyncContextSpanEventSimpleAroundInterceptor.java index 2a782821a66d..6be2c855b8e1 100644 --- a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/AsyncContextSpanEventSimpleAroundInterceptor.java +++ b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/AsyncContextSpanEventSimpleAroundInterceptor.java @@ -21,9 +21,9 @@ import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; -import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; import java.util.Objects; @@ -60,7 +60,7 @@ public void before(Object target, Object[] args) { } // entry scope. - entryAsyncTraceScope(trace); + ScopeUtils.entryAsyncTraceScope(trace); try { // trace event for default & async. @@ -95,7 +95,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } // leave scope. - if (!leaveAsyncTraceScope(trace)) { + if (!ScopeUtils.leaveAsyncTraceScope(trace)) { if (logger.isWarnEnabled()) { logger.warn("Failed to leave scope of async trace {}.", trace); } @@ -113,7 +113,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } } finally { trace.traceBlockEnd(); - if (isAsyncTraceDestination(trace)) { + if (ScopeUtils.isAsyncTraceEndScope(trace)) { deleteAsyncContext(trace, asyncContext); } } @@ -153,32 +153,4 @@ private void deleteAsyncContext(final Trace trace, AsyncContext asyncContext) { asyncContext.close(); } - private void entryAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - scope.tryEnter(); - } - } - - private boolean leaveAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - } else { - return false; - } - } - return true; - } - - private boolean isAsyncTraceDestination(final Trace trace) { - if (!trace.isAsync()) { - return false; - } - - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - return scope != null && !scope.isActive(); - } - } \ No newline at end of file diff --git a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/SpanRecursiveAroundInterceptor.java b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/SpanRecursiveAroundInterceptor.java index 81343d3931e2..92fc8e2aea3b 100644 --- a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/SpanRecursiveAroundInterceptor.java +++ b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/SpanRecursiveAroundInterceptor.java @@ -23,6 +23,7 @@ import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; import java.util.Objects; @@ -175,41 +176,32 @@ private boolean initScope(final Trace trace) { } private void entryScope(final Trace trace) { - final TraceScope scope = trace.getScope(this.scopeName); - if (scope != null) { - scope.tryEnter(); + if (ScopeUtils.entryScope(trace, this.scopeName)) { if (isDebug) { - logger.debug("Try enter trace scope={}", scope.getName()); + logger.debug("Try enter trace scope={}", scopeName); } } } private boolean leaveScope(final Trace trace) { - final TraceScope scope = trace.getScope(this.scopeName); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - if (isDebug) { - logger.debug("Leave trace scope={}", scope.getName()); - } - } else { - if (logger.isInfoEnabled()) { - logger.info("Failed to leave scope. trace={}", trace); - } - return false; + if (ScopeUtils.leaveScope(trace, this.scopeName)) { + if (isDebug) { + logger.debug("Leave trace scope={}", scopeName); } + return true; } - return true; + if (logger.isInfoEnabled()) { + logger.info("Failed to leave scope. trace={}", trace); + } + return false; } private boolean hasScope(final Trace trace) { - final TraceScope scope = trace.getScope(this.scopeName); - return scope != null; + return ScopeUtils.hasScope(trace, this.scopeName); } private boolean isEndScope(final Trace trace) { - final TraceScope scope = trace.getScope(this.scopeName); - return scope != null && !scope.isActive(); + return ScopeUtils.isEndScope(trace, this.scopeName); } private void deleteTrace(final Trace trace) { diff --git a/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/util/ScopeUtils.java b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/util/ScopeUtils.java new file mode 100644 index 000000000000..4dd182f56258 --- /dev/null +++ b/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/util/ScopeUtils.java @@ -0,0 +1,63 @@ +package com.navercorp.pinpoint.bootstrap.util; + +import com.navercorp.pinpoint.bootstrap.context.AsyncContext; +import com.navercorp.pinpoint.bootstrap.context.Trace; +import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; + +public final class ScopeUtils { + + public static final String ASYNC_TRACE_SCOPE = AsyncContext.ASYNC_TRACE_SCOPE; + + private ScopeUtils() { + } + + public static boolean entryAsyncTraceScope(final Trace trace) { + return entryScope(trace, ASYNC_TRACE_SCOPE); + } + + public static boolean entryScope(final Trace trace, final String scopeName) { + final TraceScope scope = trace.getScope(scopeName); + if (scope != null) { + scope.tryEnter(); + return true; + } + return false; + } + + public static boolean leaveAsyncTraceScope(final Trace trace) { + return leaveScope(trace, ASYNC_TRACE_SCOPE); + } + + public static boolean leaveScope(final Trace trace, final String scopeName) { + final TraceScope scope = trace.getScope(scopeName); + if (scope != null) { + if (scope.canLeave()) { + scope.leave(); + } else { + return false; + } + } + return true; + } + + public static boolean isAsyncTraceEndScope(final Trace trace) { + return isAsyncTraceEndScope(trace, ASYNC_TRACE_SCOPE); + } + + public static boolean isAsyncTraceEndScope(final Trace trace, final String scopeName) { + if (!trace.isAsync()) { + return false; + } + return isEndScope(trace, scopeName); + } + + public static boolean isEndScope(final Trace trace, final String scopeName) { + final TraceScope scope = trace.getScope(scopeName); + return scope != null && !scope.isActive(); + } + + public static boolean hasScope(final Trace trace, final String scopeName) { + final TraceScope scope = trace.getScope(scopeName); + return scope != null; + } +} diff --git a/plugins/akka-http/src/main/java/com/navercorp/pinpoint/plugin/akka/http/interceptor/AsyncContextSpanEventEndPointInterceptor.java b/plugins/akka-http/src/main/java/com/navercorp/pinpoint/plugin/akka/http/interceptor/AsyncContextSpanEventEndPointInterceptor.java index 3961d012a2ba..9455712be198 100644 --- a/plugins/akka-http/src/main/java/com/navercorp/pinpoint/plugin/akka/http/interceptor/AsyncContextSpanEventEndPointInterceptor.java +++ b/plugins/akka-http/src/main/java/com/navercorp/pinpoint/plugin/akka/http/interceptor/AsyncContextSpanEventEndPointInterceptor.java @@ -23,10 +23,10 @@ import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; -import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; import java.util.Objects; @@ -37,7 +37,6 @@ public abstract class AsyncContextSpanEventEndPointInterceptor implements Around protected final PLogger logger = PLoggerFactory.getLogger(getClass()); protected final boolean isDebug = logger.isDebugEnabled(); - protected static final String ASYNC_TRACE_SCOPE = AsyncContext.ASYNC_TRACE_SCOPE; protected final MethodDescriptor methodDescriptor; protected final TraceContext traceContext; @@ -68,7 +67,7 @@ public void before(Object target, Object[] args) { logger.debug("Asynchronous invocation. asyncTraceId={}, trace={}", asyncContext, trace); } // entry scope. - entryAsyncTraceScope(trace); + ScopeUtils.entryAsyncTraceScope(trace); try { // trace event for default & async. @@ -107,7 +106,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } // leave scope. - if (!leaveAsyncTraceScope(trace)) { + if (!ScopeUtils.leaveAsyncTraceScope(trace)) { if (logger.isWarnEnabled()) { logger.warn("Failed to leave scope of async trace {}.", trace); } @@ -125,8 +124,8 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } } finally { trace.traceBlockEnd(); - if (isAsyncTraceDestination(trace)) { - if(isDebug) { + if (ScopeUtils.isAsyncTraceEndScope(trace)) { + if (isDebug) { logger.debug("Arrived at async trace destination. asyncTraceId={}", asyncContext); } deleteAsyncTrace(trace); @@ -164,33 +163,6 @@ private void deleteAsyncTrace(final Trace trace) { trace.close(); } - private void entryAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - scope.tryEnter(); - } - } - - private boolean leaveAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - } else { - return false; - } - } - return true; - } - - private boolean isAsyncTraceDestination(final Trace trace) { - if (!trace.isAsync()) { - return false; - } - - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - return scope != null && !scope.isActive(); - } private void finishAsyncState(final AsyncContext asyncContext) { if (AsyncContextUtils.asyncStateFinish(asyncContext)) { diff --git a/plugins/grpc/src/main/java/com/navercorp/pinpoint/plugin/grpc/interceptor/server/GrpcAsyncContextSpanEventEndPointInterceptor.java b/plugins/grpc/src/main/java/com/navercorp/pinpoint/plugin/grpc/interceptor/server/GrpcAsyncContextSpanEventEndPointInterceptor.java index 90917024ec69..ebce17939079 100644 --- a/plugins/grpc/src/main/java/com/navercorp/pinpoint/plugin/grpc/interceptor/server/GrpcAsyncContextSpanEventEndPointInterceptor.java +++ b/plugins/grpc/src/main/java/com/navercorp/pinpoint/plugin/grpc/interceptor/server/GrpcAsyncContextSpanEventEndPointInterceptor.java @@ -21,8 +21,8 @@ import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; -import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.bootstrap.interceptor.AsyncContextSpanEventSimpleAroundInterceptor; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; import java.util.Objects; @@ -62,7 +62,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } // leave scope. - if (!leaveAsyncTraceScope(trace)) { + if (!ScopeUtils.leaveAsyncTraceScope(trace)) { if (logger.isWarnEnabled()) { logger.warn("Failed to leave scope of async trace {}.", trace); } @@ -80,7 +80,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } } finally { trace.traceBlockEnd(); - if (isAsyncTraceDestination(trace)) { + if (ScopeUtils.isAsyncTraceEndScope(trace)) { if (isDebug) { logger.debug("Arrived at async trace destination. asyncTraceId={}", asyncContext); } @@ -98,26 +98,6 @@ private void deleteAsyncTrace(final Trace trace) { trace.close(); } - private boolean leaveAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - } else { - return false; - } - } - return true; - } - - private boolean isAsyncTraceDestination(final Trace trace) { - if (!trace.isAsync()) { - return false; - } - - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - return scope != null && !scope.isActive(); - } protected void finishAsyncState(final AsyncContext asyncContext) { } diff --git a/plugins/jdk-http/src/main/java/com/navercorp/pinpoint/plugin/jdk/http/interceptor/AbstractHttpURLConnectionInterceptor.java b/plugins/jdk-http/src/main/java/com/navercorp/pinpoint/plugin/jdk/http/interceptor/AbstractHttpURLConnectionInterceptor.java index 53e622858418..c1e4ab91a4e8 100644 --- a/plugins/jdk-http/src/main/java/com/navercorp/pinpoint/plugin/jdk/http/interceptor/AbstractHttpURLConnectionInterceptor.java +++ b/plugins/jdk-http/src/main/java/com/navercorp/pinpoint/plugin/jdk/http/interceptor/AbstractHttpURLConnectionInterceptor.java @@ -16,17 +16,32 @@ package com.navercorp.pinpoint.plugin.jdk.http.interceptor; -import com.navercorp.pinpoint.bootstrap.context.*; +import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor; +import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; +import com.navercorp.pinpoint.bootstrap.context.Trace; +import com.navercorp.pinpoint.bootstrap.context.TraceContext; +import com.navercorp.pinpoint.bootstrap.context.TraceId; import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor; import com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScope; import com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; -import com.navercorp.pinpoint.bootstrap.plugin.request.*; +import com.navercorp.pinpoint.bootstrap.plugin.request.ClientHeaderAdaptor; +import com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestAdaptor; +import com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestRecorder; +import com.navercorp.pinpoint.bootstrap.plugin.request.DefaultRequestTraceWriter; +import com.navercorp.pinpoint.bootstrap.plugin.request.RequestTraceWriter; import com.navercorp.pinpoint.bootstrap.plugin.response.ResponseHeaderRecorderFactory; import com.navercorp.pinpoint.bootstrap.plugin.response.ServerResponseHeaderRecorder; -import com.navercorp.pinpoint.plugin.jdk.http.*; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; +import com.navercorp.pinpoint.plugin.jdk.http.ConnectingGetter; +import com.navercorp.pinpoint.plugin.jdk.http.HttpURLConnectionClientHeaderAdaptor; +import com.navercorp.pinpoint.plugin.jdk.http.JdkHttpClientRequestAdaptor; +import com.navercorp.pinpoint.plugin.jdk.http.JdkHttpClientResponseAdaptor; +import com.navercorp.pinpoint.plugin.jdk.http.JdkHttpConstants; +import com.navercorp.pinpoint.plugin.jdk.http.JdkHttpPlugin; +import com.navercorp.pinpoint.plugin.jdk.http.JdkHttpPluginConfig; import java.net.HttpURLConnection; import java.net.URL; @@ -189,8 +204,7 @@ private boolean isInterceptingHttps() { } private boolean isRecordingResponse(Trace trace) { - final TraceScope scope = trace.getScope(TRACE_SCOPE_NAME_RESPONSE); - return scope != null && scope.isActive(); + return ScopeUtils.isEndScope(trace, TRACE_SCOPE_NAME_RESPONSE); } private boolean startRecordingResponse(Trace trace) { @@ -212,13 +226,8 @@ private boolean startRecordingResponse(Trace trace) { } private void clearRecordingResponseStatus(Trace trace) { - final TraceScope scope = trace.getScope(TRACE_SCOPE_NAME_RESPONSE); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - } else { - logger.warn("Try to learRecordingResponseStatus failed, canLeave scope returned false"); - } + if (!ScopeUtils.leaveScope(trace, TRACE_SCOPE_NAME_RESPONSE)) { + logger.warn("Try to learRecordingResponseStatus failed, canLeave scope returned false"); } } diff --git a/plugins/netty/src/main/java/com/navercorp/pinpoint/plugin/netty/interceptor/http/HttpEncoderInterceptor.java b/plugins/netty/src/main/java/com/navercorp/pinpoint/plugin/netty/interceptor/http/HttpEncoderInterceptor.java index 75340f87a342..34226292d055 100644 --- a/plugins/netty/src/main/java/com/navercorp/pinpoint/plugin/netty/interceptor/http/HttpEncoderInterceptor.java +++ b/plugins/netty/src/main/java/com/navercorp/pinpoint/plugin/netty/interceptor/http/HttpEncoderInterceptor.java @@ -24,7 +24,6 @@ import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; import com.navercorp.pinpoint.bootstrap.context.TraceId; -import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; @@ -35,13 +34,13 @@ import com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapperAdaptor; import com.navercorp.pinpoint.bootstrap.plugin.request.DefaultRequestTraceWriter; import com.navercorp.pinpoint.bootstrap.plugin.request.RequestTraceWriter; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; import com.navercorp.pinpoint.common.util.ArrayUtils; import com.navercorp.pinpoint.plugin.netty.NettyClientRequestWrapper; import com.navercorp.pinpoint.plugin.netty.NettyConfig; import com.navercorp.pinpoint.plugin.netty.NettyConstants; import com.navercorp.pinpoint.plugin.netty.NettyUtils; import com.navercorp.pinpoint.plugin.netty.field.accessor.AsyncStartFlagFieldAccessor; - import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMessage; @@ -55,7 +54,6 @@ public class HttpEncoderInterceptor implements AroundInterceptor { protected final PLogger logger = PLoggerFactory.getLogger(getClass()); protected final boolean isDebug = logger.isDebugEnabled(); - protected static final String ASYNC_TRACE_SCOPE = AsyncContext.ASYNC_TRACE_SCOPE; private final TraceContext traceContext; protected final MethodDescriptor methodDescriptor; @@ -119,7 +117,7 @@ private void beforeAsync(Object target, Object[] args) { } // entry scope. - entryAsyncTraceScope(trace); + ScopeUtils.entryAsyncTraceScope(trace); try { // trace event for default & async. @@ -200,7 +198,7 @@ private void afterAsync(Object target, Object[] args, Object result, Throwable t } // leave scope. - if (!leaveAsyncTraceScope(trace)) { + if (!ScopeUtils.leaveAsyncTraceScope(trace)) { if (logger.isWarnEnabled()) { logger.warn("Failed to leave scope of async trace {}.", trace); } @@ -218,7 +216,7 @@ private void afterAsync(Object target, Object[] args, Object result, Throwable t } } finally { trace.traceBlockEnd(); - if (isAsyncTraceDestination(trace)) { + if (ScopeUtils.isAsyncTraceEndScope(trace)) { deleteAsyncContext(trace, asyncContext); } } @@ -257,33 +255,6 @@ private void deleteAsyncContext(final Trace trace, AsyncContext asyncContext) { asyncContext.close(); } - private void entryAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - scope.tryEnter(); - } - } - - private boolean leaveAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - } else { - return false; - } - } - return true; - } - - private boolean isAsyncTraceDestination(final Trace trace) { - if (!trace.isAsync()) { - return false; - } - - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - return scope != null && !scope.isActive(); - } private boolean validate(Object[] args) { if (ArrayUtils.getLength(args) != 3) { diff --git a/plugins/rabbitmq/src/main/java/com/navercorp/pinpoint/plugin/rabbitmq/client/interceptor/ConsumerHandleDeliveryInterceptor.java b/plugins/rabbitmq/src/main/java/com/navercorp/pinpoint/plugin/rabbitmq/client/interceptor/ConsumerHandleDeliveryInterceptor.java index b65549c830bb..5ae9b095545e 100644 --- a/plugins/rabbitmq/src/main/java/com/navercorp/pinpoint/plugin/rabbitmq/client/interceptor/ConsumerHandleDeliveryInterceptor.java +++ b/plugins/rabbitmq/src/main/java/com/navercorp/pinpoint/plugin/rabbitmq/client/interceptor/ConsumerHandleDeliveryInterceptor.java @@ -2,11 +2,15 @@ import com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor; import com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessorUtils; -import com.navercorp.pinpoint.bootstrap.context.*; -import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; +import com.navercorp.pinpoint.bootstrap.context.AsyncContext; +import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor; +import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; +import com.navercorp.pinpoint.bootstrap.context.Trace; +import com.navercorp.pinpoint.bootstrap.context.TraceContext; import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; import com.navercorp.pinpoint.common.util.ArrayUtils; import com.navercorp.pinpoint.plugin.rabbitmq.client.RabbitMQClientConstants; import com.rabbitmq.client.Consumer; @@ -23,7 +27,6 @@ public class ConsumerHandleDeliveryInterceptor implements AroundInterceptor { private final PLogger logger = PLoggerFactory.getLogger(getClass()); private final boolean isDebug = logger.isDebugEnabled(); - private static final String ASYNC_TRACE_SCOPE = AsyncContext.ASYNC_TRACE_SCOPE; private final MethodDescriptor methodDescriptor; @@ -52,7 +55,7 @@ public void before(Object target, Object[] args) { } // entry scope. - entryAsyncTraceScope(trace); + ScopeUtils.entryAsyncTraceScope(trace); try { // trace event for default & async @@ -86,7 +89,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } // leave scope - if (!leaveAsyncTraceScope(trace)) { + if (!ScopeUtils.leaveAsyncTraceScope(trace)) { if (logger.isWarnEnabled()) { logger.warn("Failed to leave scope of async trace {}.", trace); } @@ -106,7 +109,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } } finally { trace.traceBlockEnd(); - if (isAsyncTraceDestination(trace)) { + if (ScopeUtils.isAsyncTraceEndScope(trace)) { deleteAsyncContext(trace, asyncContext); } } @@ -153,30 +156,4 @@ private void deleteAsyncContext(Trace trace, AsyncContext asyncContext) { asyncContext.close(); } - private void entryAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - scope.tryEnter(); - } - } - - private boolean leaveAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - } else { - return false; - } - } - return true; - } - - private boolean isAsyncTraceDestination(final Trace trace) { - if (!trace.isAsync()) { - return false; - } - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - return scope != null && !scope.isActive(); - } } diff --git a/plugins/rocketmq/src/main/java/com/navercorp/pinpoint/plugin/rocketmq/interceptor/ProducerSendInterceptor.java b/plugins/rocketmq/src/main/java/com/navercorp/pinpoint/plugin/rocketmq/interceptor/ProducerSendInterceptor.java index 4f34a59adc65..a7d690395e71 100644 --- a/plugins/rocketmq/src/main/java/com/navercorp/pinpoint/plugin/rocketmq/interceptor/ProducerSendInterceptor.java +++ b/plugins/rocketmq/src/main/java/com/navercorp/pinpoint/plugin/rocketmq/interceptor/ProducerSendInterceptor.java @@ -16,16 +16,6 @@ package com.navercorp.pinpoint.plugin.rocketmq.interceptor; -import static com.navercorp.pinpoint.bootstrap.sampler.SamplingFlagUtils.SAMPLING_RATE_FALSE; -import static org.apache.rocketmq.common.message.MessageDecoder.NAME_VALUE_SEPARATOR; -import static org.apache.rocketmq.common.message.MessageDecoder.PROPERTY_SEPARATOR; - -import java.util.HashMap; -import java.util.Map; - -import com.navercorp.pinpoint.common.util.ArrayArgumentUtils; -import org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader; - import com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor; import com.navercorp.pinpoint.bootstrap.context.AsyncContext; import com.navercorp.pinpoint.bootstrap.context.Header; @@ -38,8 +28,18 @@ import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; +import com.navercorp.pinpoint.common.util.ArrayArgumentUtils; import com.navercorp.pinpoint.plugin.rocketmq.RocketMQConstants; import com.navercorp.pinpoint.plugin.rocketmq.field.accessor.EndPointFieldAccessor; +import org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader; + +import java.util.HashMap; +import java.util.Map; + +import static com.navercorp.pinpoint.bootstrap.sampler.SamplingFlagUtils.SAMPLING_RATE_FALSE; +import static org.apache.rocketmq.common.message.MessageDecoder.NAME_VALUE_SEPARATOR; +import static org.apache.rocketmq.common.message.MessageDecoder.PROPERTY_SEPARATOR; /** * @author messi-gao @@ -130,7 +130,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab return; } - if (!leaveScope(trace)) { + if (!ScopeUtils.leaveScope(trace, SCOPE_NAME)) { // Defense code deleteTrace(trace); return; @@ -156,7 +156,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } } finally { trace.traceBlockEnd(); - if (isAsyncTraceDestination(trace)) { + if (ScopeUtils.isAsyncTraceEndScope(trace, SCOPE_NAME)) { deleteTrace(trace); } } @@ -221,7 +221,7 @@ private boolean isSkipTrace() { } if (hasScope(trace)) { // Entry Scope - entryScope(trace); + ScopeUtils.entryScope(trace, SCOPE_NAME); if (isDebug) { logger.debug("Skip recursive invoked"); } @@ -248,50 +248,20 @@ private boolean initScope(final Trace trace) { } private void entryScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - if (scope != null) { - scope.tryEnter(); + if (ScopeUtils.entryScope(trace, SCOPE_NAME)) { if (isDebug) { - logger.debug("Try enter trace scope={}", scope.getName()); + logger.debug("Try enter trace scope={}", SCOPE_NAME); } } } - private boolean leaveScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - if (isDebug) { - logger.debug("Leave trace scope={}", scope.getName()); - } - } else { - if (logger.isInfoEnabled()) { - logger.info("Failed to leave scope. trace={}", trace); - } - return false; - } - } - return true; - } private boolean hasScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - return scope != null; + return ScopeUtils.hasScope(trace, SCOPE_NAME); } private boolean isEndScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - return scope != null && !scope.isActive(); - } - - private boolean isAsyncTraceDestination(final Trace trace) { - if (!trace.isAsync()) { - return false; - } - - final TraceScope scope = trace.getScope(SCOPE_NAME); - return scope != null && !scope.isActive(); + return ScopeUtils.isEndScope(trace, SCOPE_NAME); } private void deleteTrace(final Trace trace) { diff --git a/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/interceptor/tprotocol/server/TProtocolReadMessageEndInterceptor.java b/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/interceptor/tprotocol/server/TProtocolReadMessageEndInterceptor.java index 8e077aa4ffa3..504236f90f16 100644 --- a/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/interceptor/tprotocol/server/TProtocolReadMessageEndInterceptor.java +++ b/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/interceptor/tprotocol/server/TProtocolReadMessageEndInterceptor.java @@ -16,24 +16,20 @@ package com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server; -import java.net.Socket; - import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor; -import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; -import com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScope; -import org.apache.thrift.protocol.TProtocol; -import org.apache.thrift.transport.TTransport; - import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; import com.navercorp.pinpoint.bootstrap.context.SpanId; import com.navercorp.pinpoint.bootstrap.context.SpanRecorder; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor; +import com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScope; import com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext; import com.navercorp.pinpoint.plugin.thrift.ThriftConstants; @@ -42,6 +38,10 @@ import com.navercorp.pinpoint.plugin.thrift.descriptor.ThriftServerEntryMethodDescriptor; import com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor; import com.navercorp.pinpoint.plugin.thrift.field.accessor.SocketFieldAccessor; +import org.apache.thrift.protocol.TProtocol; +import org.apache.thrift.transport.TTransport; + +import java.net.Socket; /** * This interceptor intercepts the point in which the client message is read, and creates a new trace object to indicate the starting point of a new span. @@ -379,37 +379,28 @@ private boolean initScope(final Trace trace) { } private void entryScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - if (scope != null) { - scope.tryEnter(); + if (ScopeUtils.entryScope(trace, SCOPE_NAME)) { if (isDebug) { - logger.debug("Try enter trace scope={}", scope.getName()); + logger.debug("Try enter trace scope={}", SCOPE_NAME); } } } private boolean leaveScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - if (isDebug) { - logger.debug("Leave trace scope={}", scope.getName()); - } - } else { - return false; + if (ScopeUtils.leaveScope(trace, SCOPE_NAME)) { + if (isDebug) { + logger.debug("Leave trace scope={}", SCOPE_NAME); } + return true; } - return true; + return false; } private boolean hasScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - return scope != null; + return ScopeUtils.hasScope(trace, SCOPE_NAME); } private boolean isEndScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - return scope != null && !scope.isActive(); + return ScopeUtils.isEndScope(trace, SCOPE_NAME); } } diff --git a/plugins/user/src/main/java/com/navercorp/pinpoint/plugin/user/interceptor/MQExternalClientHandlerInterceptor.java b/plugins/user/src/main/java/com/navercorp/pinpoint/plugin/user/interceptor/MQExternalClientHandlerInterceptor.java index 9d5aa8b1cfe4..87dc98ed17cb 100644 --- a/plugins/user/src/main/java/com/navercorp/pinpoint/plugin/user/interceptor/MQExternalClientHandlerInterceptor.java +++ b/plugins/user/src/main/java/com/navercorp/pinpoint/plugin/user/interceptor/MQExternalClientHandlerInterceptor.java @@ -23,10 +23,10 @@ import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; -import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.common.util.ArrayUtils; @@ -38,7 +38,6 @@ public class MQExternalClientHandlerInterceptor implements AroundInterceptor { protected final PLogger logger = PLoggerFactory.getLogger(getClass()); protected final boolean isDebug = logger.isDebugEnabled(); - protected static final String ASYNC_TRACE_SCOPE = AsyncContext.ASYNC_TRACE_SCOPE; protected final MethodDescriptor methodDescriptor; @@ -64,7 +63,7 @@ public void before(Object target, Object[] args) { } // entry scope. - entryAsyncTraceScope(trace); + ScopeUtils.entryAsyncTraceScope(trace); try { // trace event for default & async. @@ -95,7 +94,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } // leave scope. - if (!leaveAsyncTraceScope(trace)) { + if (!ScopeUtils.leaveAsyncTraceScope(trace)) { if (logger.isWarnEnabled()) { logger.warn("Failed to leave scope of async trace {}.", trace); } @@ -115,7 +114,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } } finally { trace.traceBlockEnd(); - if (isAsyncTraceDestination(trace)) { + if (ScopeUtils.isAsyncTraceEndScope(trace)) { deleteAsyncContext(trace, asyncContext); } } @@ -157,31 +156,4 @@ private void deleteAsyncContext(final Trace trace, AsyncContext asyncContext) { asyncContext.close(); } - private void entryAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - scope.tryEnter(); - } - } - - private boolean leaveAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - } else { - return false; - } - } - return true; - } - - private boolean isAsyncTraceDestination(final Trace trace) { - if (!trace.isAsync()) { - return false; - } - - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - return scope != null && !scope.isActive(); - } } diff --git a/plugins/user/src/main/java/com/navercorp/pinpoint/plugin/user/interceptor/UserIncludeMethodInterceptor.java b/plugins/user/src/main/java/com/navercorp/pinpoint/plugin/user/interceptor/UserIncludeMethodInterceptor.java index 161a51b1cc16..2db15f774893 100644 --- a/plugins/user/src/main/java/com/navercorp/pinpoint/plugin/user/interceptor/UserIncludeMethodInterceptor.java +++ b/plugins/user/src/main/java/com/navercorp/pinpoint/plugin/user/interceptor/UserIncludeMethodInterceptor.java @@ -16,11 +16,16 @@ package com.navercorp.pinpoint.plugin.user.interceptor; -import com.navercorp.pinpoint.bootstrap.context.*; +import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor; +import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; +import com.navercorp.pinpoint.bootstrap.context.SpanRecorder; +import com.navercorp.pinpoint.bootstrap.context.Trace; +import com.navercorp.pinpoint.bootstrap.context.TraceContext; import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.common.util.StringUtils; import com.navercorp.pinpoint.plugin.user.UserIncludeMethodDescriptor; @@ -176,37 +181,25 @@ private void deleteUserIncludeTrace(final Trace trace) { } private void entryUserIncludeTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - if (scope != null) { - scope.tryEnter(); + if (ScopeUtils.entryScope(trace, SCOPE_NAME)) { if (isDebug) { - logger.debug("Try enter trace scope={}", scope.getName()); + logger.debug("Try enter trace scope={}", SCOPE_NAME); } } } private boolean leaveUserIncludeTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - if (isDebug) { - logger.debug("Leave trace scope={}", scope.getName()); - } - } else { - return false; + if (ScopeUtils.leaveScope(trace, SCOPE_NAME)) { + if (isDebug) { + logger.debug("Leave trace scope={}", SCOPE_NAME); } + return true; } - return true; + return false; } - private boolean isUserIncludeTrace(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - return scope != null; - } private boolean isUserIncludeTraceDestination(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - return scope != null && !scope.isActive(); + return ScopeUtils.isEndScope(trace, SCOPE_NAME); } } \ No newline at end of file diff --git a/plugins/vertx/src/main/java/com/navercorp/pinpoint/plugin/vertx/interceptor/AsyncContextSpanEventEndPointInterceptor.java b/plugins/vertx/src/main/java/com/navercorp/pinpoint/plugin/vertx/interceptor/AsyncContextSpanEventEndPointInterceptor.java index 4acf40f54e8b..fd50fa25d168 100644 --- a/plugins/vertx/src/main/java/com/navercorp/pinpoint/plugin/vertx/interceptor/AsyncContextSpanEventEndPointInterceptor.java +++ b/plugins/vertx/src/main/java/com/navercorp/pinpoint/plugin/vertx/interceptor/AsyncContextSpanEventEndPointInterceptor.java @@ -23,10 +23,10 @@ import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; import com.navercorp.pinpoint.bootstrap.context.Trace; import com.navercorp.pinpoint.bootstrap.context.TraceContext; -import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor; import com.navercorp.pinpoint.bootstrap.logging.PLogger; import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; import java.util.Objects; @@ -69,7 +69,7 @@ public void before(Object target, Object[] args) { logger.debug("Asynchronous invocation. asyncTraceId={}, trace={}", asyncContext, trace); } // entry scope. - entryAsyncTraceScope(trace); + ScopeUtils.entryAsyncTraceScope(trace); try { // trace event for default & async. @@ -108,7 +108,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } // leave scope. - if (!leaveAsyncTraceScope(trace)) { + if (!ScopeUtils.leaveAsyncTraceScope(trace)) { if (logger.isWarnEnabled()) { logger.warn("Failed to leave scope of async trace {}.", trace); } @@ -131,8 +131,8 @@ public void after(Object target, Object[] args, Object result, Throwable throwab } } finally { trace.traceBlockEnd(); - if (isAsyncTraceDestination(trace)) { - if(isDebug) { + if (ScopeUtils.isAsyncTraceEndScope(trace)) { + if (isDebug) { logger.debug("Arrived at async trace destination. asyncTraceId={}", asyncContext); } deleteAsyncTrace(trace); @@ -173,34 +173,6 @@ private void deleteAsyncTrace(final Trace trace) { trace.close(); } - private void entryAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - scope.tryEnter(); - } - } - - private boolean leaveAsyncTraceScope(final Trace trace) { - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - } else { - return false; - } - } - return true; - } - - private boolean isAsyncTraceDestination(final Trace trace) { - if (!trace.isAsync()) { - return false; - } - - final TraceScope scope = trace.getScope(ASYNC_TRACE_SCOPE); - return scope != null && !scope.isActive(); - } - private void finishAsyncState(final AsyncContext asyncContext) { if (AsyncContextUtils.asyncStateFinish(asyncContext)) { if (isDebug) { diff --git a/plugins/vertx/src/main/java/com/navercorp/pinpoint/plugin/vertx/interceptor/ServerConnectionHandleRequestInterceptor.java b/plugins/vertx/src/main/java/com/navercorp/pinpoint/plugin/vertx/interceptor/ServerConnectionHandleRequestInterceptor.java index 94df09995662..55c9d5ba5e92 100644 --- a/plugins/vertx/src/main/java/com/navercorp/pinpoint/plugin/vertx/interceptor/ServerConnectionHandleRequestInterceptor.java +++ b/plugins/vertx/src/main/java/com/navercorp/pinpoint/plugin/vertx/interceptor/ServerConnectionHandleRequestInterceptor.java @@ -35,6 +35,7 @@ import com.navercorp.pinpoint.bootstrap.plugin.request.ServerRequestRecorder; import com.navercorp.pinpoint.bootstrap.plugin.request.util.ParameterRecorder; import com.navercorp.pinpoint.bootstrap.plugin.request.util.RemoteAddressResolverFactory; +import com.navercorp.pinpoint.bootstrap.util.ScopeUtils; import com.navercorp.pinpoint.common.util.ArrayUtils; import com.navercorp.pinpoint.plugin.vertx.ParameterRecorderFactory; import com.navercorp.pinpoint.plugin.vertx.VertxConstants; @@ -288,38 +289,29 @@ private boolean initScope(final Trace trace) { } private void entryScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - if (scope != null) { - scope.tryEnter(); + if (ScopeUtils.entryScope(trace, SCOPE_NAME)) { if (isDebug) { - logger.debug("Try enter trace scope={}", scope.getName()); + logger.debug("Try enter trace scope={}", SCOPE_NAME); } } } private boolean leaveScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - if (scope != null) { - if (scope.canLeave()) { - scope.leave(); - if (isDebug) { - logger.debug("Leave trace scope={}", scope.getName()); - } - } else { - return false; + if (ScopeUtils.leaveScope(trace, SCOPE_NAME)) { + if (isDebug) { + logger.debug("Leave trace scope={}", SCOPE_NAME); } + return true; } - return true; + return false; } private boolean hasScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - return scope != null; + return ScopeUtils.hasScope(trace, SCOPE_NAME); } private boolean isEndScope(final Trace trace) { - final TraceScope scope = trace.getScope(SCOPE_NAME); - return scope != null && !scope.isActive(); + return ScopeUtils.isEndScope(trace, SCOPE_NAME); }