diff --git a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java index 507c1f0a..ef312bc0 100755 --- a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java +++ b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java @@ -17,6 +17,7 @@ package com.alibaba.csp.sentinel.adapter.dubbo; import com.alibaba.csp.sentinel.Entry; import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.ResourceTypeConstants; import com.alibaba.csp.sentinel.SphU; import com.alibaba.csp.sentinel.Tracer; import com.alibaba.csp.sentinel.adapter.dubbo.config.DubboConfig; @@ -54,8 +55,9 @@ public class SentinelDubboConsumerFilter implements Filter { Entry methodEntry = null; try { String resourceName = DubboUtils.getResourceName(invoker, invocation, DubboConfig.getDubboConsumerPrefix()); - interfaceEntry = SphU.entry(invoker.getInterface().getName(), EntryType.OUT); - methodEntry = SphU.entry(resourceName, EntryType.OUT); + interfaceEntry = SphU.entry(invoker.getInterface().getName(), + ResourceTypeConstants.COMMON_RPC, EntryType.OUT); + methodEntry = SphU.entry(resourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT); Result result = invoker.invoke(invocation); if (result.hasException()) { diff --git a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilter.java b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilter.java index 5d2226eb..d5a2745e 100755 --- a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilter.java +++ b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilter.java @@ -17,6 +17,7 @@ package com.alibaba.csp.sentinel.adapter.dubbo; import com.alibaba.csp.sentinel.Entry; import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.ResourceTypeConstants; import com.alibaba.csp.sentinel.SphU; import com.alibaba.csp.sentinel.Tracer; import com.alibaba.csp.sentinel.adapter.dubbo.config.DubboConfig; @@ -63,8 +64,9 @@ public class SentinelDubboProviderFilter implements Filter { // Only need to create entrance context at provider side, as context will take effect // at entrance of invocation chain only (for inbound traffic). ContextUtil.enter(resourceName, application); - interfaceEntry = SphU.entry(interfaceName, EntryType.IN); - methodEntry = SphU.entry(resourceName, EntryType.IN, 1, invocation.getArguments()); + interfaceEntry = SphU.entry(interfaceName, ResourceTypeConstants.COMMON_RPC, EntryType.IN); + methodEntry = SphU.entry(resourceName, ResourceTypeConstants.COMMON_RPC, + EntryType.IN, invocation.getArguments()); Result result = invoker.invoke(invocation); if (result.hasException()) { diff --git a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java index e4b30b95..55b87a59 100644 --- a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java +++ b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java @@ -103,7 +103,7 @@ public class SentinelDubboConsumerFilterTest extends BaseTest { DefaultNode entranceNode = context.getEntranceNode(); ResourceWrapper entranceResource = entranceNode.getId(); assertEquals(Constants.CONTEXT_DEFAULT_NAME, entranceResource.getName()); - assertSame(EntryType.IN, entranceResource.getType()); + assertSame(EntryType.IN, entranceResource.getEntryType()); // As SphU.entry(interfaceName, EntryType.OUT); Set childList = entranceNode.getChildList(); @@ -111,7 +111,7 @@ public class SentinelDubboConsumerFilterTest extends BaseTest { DefaultNode interfaceNode = (DefaultNode) childList.iterator().next(); ResourceWrapper interfaceResource = interfaceNode.getId(); assertEquals(DemoService.class.getName(), interfaceResource.getName()); - assertSame(EntryType.OUT, interfaceResource.getType()); + assertSame(EntryType.OUT, interfaceResource.getEntryType()); // As SphU.entry(resourceName, EntryType.OUT); childList = interfaceNode.getChildList(); @@ -119,7 +119,7 @@ public class SentinelDubboConsumerFilterTest extends BaseTest { DefaultNode methodNode = (DefaultNode) childList.iterator().next(); ResourceWrapper methodResource = methodNode.getId(); assertEquals(resourceName, methodResource.getName()); - assertSame(EntryType.OUT, methodResource.getType()); + assertSame(EntryType.OUT, methodResource.getEntryType()); // Verify curEntry Entry curEntry = context.getCurEntry(); diff --git a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java index 8b0ab899..d8a6f00d 100644 --- a/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java +++ b/sentinel-adapter/sentinel-apache-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java @@ -104,7 +104,7 @@ public class SentinelDubboProviderFilterTest extends BaseTest { DefaultNode entranceNode = context.getEntranceNode(); ResourceWrapper entranceResource = entranceNode.getId(); assertEquals(resourceName, entranceResource.getName()); - assertSame(EntryType.IN, entranceResource.getType()); + assertSame(EntryType.IN, entranceResource.getEntryType()); // As SphU.entry(interfaceName, EntryType.IN); Set childList = entranceNode.getChildList(); @@ -112,7 +112,7 @@ public class SentinelDubboProviderFilterTest extends BaseTest { DefaultNode interfaceNode = (DefaultNode) childList.iterator().next(); ResourceWrapper interfaceResource = interfaceNode.getId(); assertEquals(DemoService.class.getName(), interfaceResource.getName()); - assertSame(EntryType.IN, interfaceResource.getType()); + assertSame(EntryType.IN, interfaceResource.getEntryType()); // As SphU.entry(resourceName, EntryType.IN, 1, invocation.getArguments()); childList = interfaceNode.getChildList(); @@ -120,7 +120,7 @@ public class SentinelDubboProviderFilterTest extends BaseTest { DefaultNode methodNode = (DefaultNode) childList.iterator().next(); ResourceWrapper methodResource = methodNode.getId(); assertEquals(resourceName, methodResource.getName()); - assertSame(EntryType.IN, methodResource.getType()); + assertSame(EntryType.IN, methodResource.getEntryType()); // Verify curEntry Entry curEntry = context.getCurEntry(); diff --git a/sentinel-adapter/sentinel-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java b/sentinel-adapter/sentinel-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java index 47ab5417..e4d822f0 100755 --- a/sentinel-adapter/sentinel-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java +++ b/sentinel-adapter/sentinel-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java @@ -17,6 +17,7 @@ package com.alibaba.csp.sentinel.adapter.dubbo; import com.alibaba.csp.sentinel.Entry; import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.ResourceTypeConstants; import com.alibaba.csp.sentinel.SphU; import com.alibaba.csp.sentinel.Tracer; import com.alibaba.csp.sentinel.adapter.dubbo.config.DubboConfig; @@ -54,19 +55,23 @@ public class SentinelDubboConsumerFilter extends AbstractDubboFilter implements Entry methodEntry = null; try { String resourceName = getResourceName(invoker, invocation, DubboConfig.getDubboConsumerPrefix()); - interfaceEntry = SphU.entry(invoker.getInterface().getName(), EntryType.OUT); - methodEntry = SphU.entry(resourceName, EntryType.OUT); + interfaceEntry = SphU.entry(invoker.getInterface().getName(), ResourceTypeConstants.COMMON_RPC, + EntryType.OUT); + methodEntry = SphU.entry(resourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT); Result result = invoker.invoke(invocation); if (result.hasException()) { + Throwable e = result.getException(); // Record common exception. - Tracer.trace(result.getException()); + Tracer.traceEntry(e, interfaceEntry); + Tracer.traceEntry(e, methodEntry); } return result; } catch (BlockException e) { return DubboFallbackRegistry.getConsumerFallback().handle(invoker, invocation, e); } catch (RpcException e) { - Tracer.trace(e); + Tracer.traceEntry(e, interfaceEntry); + Tracer.traceEntry(e, methodEntry); throw e; } finally { if (methodEntry != null) { diff --git a/sentinel-adapter/sentinel-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilter.java b/sentinel-adapter/sentinel-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilter.java index 87d2fd72..1d78ab8a 100755 --- a/sentinel-adapter/sentinel-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilter.java +++ b/sentinel-adapter/sentinel-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilter.java @@ -17,6 +17,7 @@ package com.alibaba.csp.sentinel.adapter.dubbo; import com.alibaba.csp.sentinel.Entry; import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.ResourceTypeConstants; import com.alibaba.csp.sentinel.SphU; import com.alibaba.csp.sentinel.Tracer; import com.alibaba.csp.sentinel.adapter.dubbo.config.DubboConfig; @@ -60,18 +61,23 @@ public class SentinelDubboProviderFilter extends AbstractDubboFilter implements String resourceName = getResourceName(invoker, invocation, DubboConfig.getDubboProviderPrefix()); String interfaceName = invoker.getInterface().getName(); ContextUtil.enter(resourceName, application); - interfaceEntry = SphU.entry(interfaceName, EntryType.IN); - methodEntry = SphU.entry(resourceName, EntryType.IN, 1, invocation.getArguments()); + interfaceEntry = SphU.entry(interfaceName, ResourceTypeConstants.COMMON_RPC, EntryType.IN); + methodEntry = SphU.entry(resourceName, ResourceTypeConstants.COMMON_RPC, + EntryType.IN, invocation.getArguments()); Result result = invoker.invoke(invocation); if (result.hasException()) { - Tracer.trace(result.getException()); + Throwable e = result.getException(); + // Record common exception. + Tracer.traceEntry(e, interfaceEntry); + Tracer.traceEntry(e, methodEntry); } return result; } catch (BlockException e) { return DubboFallbackRegistry.getProviderFallback().handle(invoker, invocation, e); } catch (RpcException e) { - Tracer.trace(e); + Tracer.traceEntry(e, interfaceEntry); + Tracer.traceEntry(e, methodEntry); throw e; } finally { if (methodEntry != null) { diff --git a/sentinel-adapter/sentinel-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java b/sentinel-adapter/sentinel-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java index a71b0d00..58de29d6 100644 --- a/sentinel-adapter/sentinel-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java +++ b/sentinel-adapter/sentinel-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilterTest.java @@ -92,7 +92,7 @@ public class SentinelDubboConsumerFilterTest extends BaseTest { DefaultNode entranceNode = context.getEntranceNode(); ResourceWrapper entranceResource = entranceNode.getId(); assertEquals(Constants.CONTEXT_DEFAULT_NAME, entranceResource.getName()); - assertSame(EntryType.IN, entranceResource.getType()); + assertSame(EntryType.IN, entranceResource.getEntryType()); // As SphU.entry(interfaceName, EntryType.OUT); Set childList = entranceNode.getChildList(); @@ -100,7 +100,7 @@ public class SentinelDubboConsumerFilterTest extends BaseTest { DefaultNode interfaceNode = (DefaultNode) childList.iterator().next(); ResourceWrapper interfaceResource = interfaceNode.getId(); assertEquals(DemoService.class.getName(), interfaceResource.getName()); - assertSame(EntryType.OUT, interfaceResource.getType()); + assertSame(EntryType.OUT, interfaceResource.getEntryType()); // As SphU.entry(resourceName, EntryType.OUT); childList = interfaceNode.getChildList(); @@ -108,7 +108,7 @@ public class SentinelDubboConsumerFilterTest extends BaseTest { DefaultNode methodNode = (DefaultNode) childList.iterator().next(); ResourceWrapper methodResource = methodNode.getId(); assertEquals(resourceName, methodResource.getName()); - assertSame(EntryType.OUT, methodResource.getType()); + assertSame(EntryType.OUT, methodResource.getEntryType()); // Verify curEntry Entry curEntry = context.getCurEntry(); diff --git a/sentinel-adapter/sentinel-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java b/sentinel-adapter/sentinel-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java index 809a5c71..8f1f850f 100644 --- a/sentinel-adapter/sentinel-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java +++ b/sentinel-adapter/sentinel-dubbo-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboProviderFilterTest.java @@ -92,7 +92,7 @@ public class SentinelDubboProviderFilterTest extends BaseTest { DefaultNode entranceNode = context.getEntranceNode(); ResourceWrapper entranceResource = entranceNode.getId(); assertEquals(resourceName, entranceResource.getName()); - assertSame(EntryType.IN, entranceResource.getType()); + assertSame(EntryType.IN, entranceResource.getEntryType()); // As SphU.entry(interfaceName, EntryType.IN); Set childList = entranceNode.getChildList(); @@ -100,7 +100,7 @@ public class SentinelDubboProviderFilterTest extends BaseTest { DefaultNode interfaceNode = (DefaultNode) childList.iterator().next(); ResourceWrapper interfaceResource = interfaceNode.getId(); assertEquals(DemoService.class.getName(), interfaceResource.getName()); - assertSame(EntryType.IN, interfaceResource.getType()); + assertSame(EntryType.IN, interfaceResource.getEntryType()); // As SphU.entry(resourceName, EntryType.IN, 1, invocation.getArguments()); childList = interfaceNode.getChildList(); @@ -108,7 +108,7 @@ public class SentinelDubboProviderFilterTest extends BaseTest { DefaultNode methodNode = (DefaultNode) childList.iterator().next(); ResourceWrapper methodResource = methodNode.getId(); assertEquals(resourceName, methodResource.getName()); - assertSame(EntryType.IN, methodResource.getType()); + assertSame(EntryType.IN, methodResource.getEntryType()); // Verify curEntry Entry curEntry = context.getCurEntry(); diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/filters/SentinelZuulPreFilter.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/filters/SentinelZuulPreFilter.java index 39f85ff0..6887e1ab 100644 --- a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/filters/SentinelZuulPreFilter.java +++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/filters/SentinelZuulPreFilter.java @@ -23,6 +23,7 @@ import java.util.Set; import com.alibaba.csp.sentinel.AsyncEntry; import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.ResourceTypeConstants; import com.alibaba.csp.sentinel.SphU; import com.alibaba.csp.sentinel.adapter.gateway.common.param.GatewayParamParser; import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule; @@ -96,7 +97,8 @@ public class SentinelZuulPreFilter extends ZuulFilter { return r.getResourceMode() == resType; } }); - AsyncEntry entry = SphU.asyncEntry(resourceName, EntryType.IN, 1, params); + AsyncEntry entry = SphU.asyncEntry(resourceName, ResourceTypeConstants.COMMON_API_GATEWAY, + EntryType.IN, params); asyncEntries.push(entry); } diff --git a/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/SentinelResourceAspect.java b/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/SentinelResourceAspect.java index cf6fca38..77c6772f 100644 --- a/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/SentinelResourceAspect.java +++ b/sentinel-extension/sentinel-annotation-aspectj/src/main/java/com/alibaba/csp/sentinel/annotation/aspectj/SentinelResourceAspect.java @@ -50,9 +50,10 @@ public class SentinelResourceAspect extends AbstractSentinelAspectSupport { } String resourceName = getResourceName(annotation.value(), originMethod); EntryType entryType = annotation.entryType(); + int resourceType = annotation.resourceType(); Entry entry = null; try { - entry = SphU.entry(resourceName, entryType, 1, pjp.getArgs()); + entry = SphU.entry(resourceName, resourceType, entryType, pjp.getArgs()); Object result = pjp.proceed(); return result; } catch (BlockException ex) {