-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
136 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,13 +27,19 @@ | |
import com.alipay.common.tracer.core.span.LogData; | ||
import com.alipay.common.tracer.core.span.SofaTracerSpan; | ||
import com.alipay.common.tracer.core.utils.StringUtils; | ||
import com.alipay.sofa.tracer.plugins.dubbo.constants.AttachmentKeyConstants; | ||
import com.alipay.sofa.tracer.plugins.dubbo.tracer.DubboConsumerSofaTracer; | ||
import com.alipay.sofa.tracer.plugins.dubbo.tracer.DubboProviderSofaTracer; | ||
import io.opentracing.tag.Tags; | ||
import org.apache.dubbo.common.Constants; | ||
import org.apache.dubbo.common.constants.CommonConstants; | ||
import org.apache.dubbo.common.extension.Activate; | ||
import org.apache.dubbo.remoting.TimeoutException; | ||
import org.apache.dubbo.rpc.*; | ||
import org.apache.dubbo.rpc.Filter; | ||
import org.apache.dubbo.rpc.Invocation; | ||
import org.apache.dubbo.rpc.Invoker; | ||
import org.apache.dubbo.rpc.Result; | ||
import org.apache.dubbo.rpc.RpcContext; | ||
import org.apache.dubbo.rpc.RpcException; | ||
import org.apache.dubbo.rpc.support.RpcUtils; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
@@ -44,7 +50,7 @@ | |
* @author: guolei.sgl ([email protected]) 2019/2/26 2:02 PM | ||
* @since: 2.3.4 | ||
**/ | ||
@Activate(group = { Constants.PROVIDER, Constants.CONSUMER }, value = "dubboSofaTracerFilter", order = 1) | ||
@Activate(group = { CommonConstants.PROVIDER, CommonConstants.CONSUMER }, value = "dubboSofaTracerFilter", order = 1) | ||
public class DubboSofaTracerFilter implements Filter { | ||
|
||
private String appName = StringUtils.EMPTY_STRING; | ||
|
@@ -76,7 +82,7 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept | |
String spanKind = spanKind(rpcContext); | ||
Result result; | ||
if (spanKind.equals(Tags.SPAN_KIND_SERVER)) { | ||
result = doServerFilter(rpcContext, invoker, invocation); | ||
result = doServerFilter(invoker, invocation); | ||
} else { | ||
result = doClientFilter(rpcContext, invoker, invocation); | ||
} | ||
|
@@ -87,7 +93,7 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept | |
public Result onResponse(Result result, Invoker<?> invoker, Invocation invocation) { | ||
String spanKey = getTracerSpanMapKey(invoker); | ||
try { | ||
// 只有异步才进行回调打印 | ||
// only the asynchronous callback to print | ||
boolean isAsync = RpcUtils.isAsync(invoker.getUrl(), invocation); | ||
if (!isAsync) { | ||
return result; | ||
|
@@ -223,12 +229,11 @@ private Result doClientFilter(RpcContext rpcContext, Invoker<?> invoker, Invocat | |
|
||
/** | ||
* rpc client handler | ||
* @param rpcContext | ||
* @param invoker | ||
* @param invocation | ||
* @return | ||
*/ | ||
private Result doServerFilter(RpcContext rpcContext, Invoker<?> invoker, Invocation invocation) { | ||
private Result doServerFilter(Invoker<?> invoker, Invocation invocation) { | ||
if (dubboProviderSofaTracer == null) { | ||
this.dubboProviderSofaTracer = DubboProviderSofaTracer | ||
.getDubboProviderSofaTracerSingleton(); | ||
|
@@ -309,29 +314,38 @@ private void appendElapsedTimeTags(Invocation invocation, SofaTracerSpan sofaTra | |
if (sofaTracerSpan == null) { | ||
return; | ||
} | ||
String reqSize = invocation.getAttachment(Constants.INPUT_KEY); | ||
String respSize = result.getAttachment(Constants.OUTPUT_KEY); | ||
String reqSize; | ||
String respSize; | ||
String elapsed; | ||
String deElapsed; | ||
if (isClient) { | ||
elapsed = invocation.getAttachment(CommonSpanTags.CLIENT_SERIALIZE_TIME); | ||
deElapsed = invocation.getAttachment(CommonSpanTags.CLIENT_DESERIALIZE_TIME); | ||
//客户端请求序列化耗时 | ||
sofaTracerSpan | ||
.setTag(CommonSpanTags.CLIENT_SERIALIZE_TIME, parseAttachment(elapsed, 0)); | ||
//客户端接受响应反序列化耗时 | ||
sofaTracerSpan.setTag(CommonSpanTags.CLIENT_DESERIALIZE_TIME, | ||
reqSize = invocation.getAttachment(AttachmentKeyConstants.CLIENT_SERIALIZE_SIZE); | ||
elapsed = invocation.getAttachment(AttachmentKeyConstants.CLIENT_SERIALIZE_TIME); | ||
respSize = result.getAttachment(AttachmentKeyConstants.CLIENT_DESERIALIZE_SIZE); | ||
deElapsed = result.getAttachment(AttachmentKeyConstants.CLIENT_DESERIALIZE_TIME); | ||
sofaTracerSpan.setTag(AttachmentKeyConstants.CLIENT_SERIALIZE_TIME, | ||
parseAttachment(elapsed, 0)); | ||
sofaTracerSpan.setTag(AttachmentKeyConstants.CLIENT_DESERIALIZE_TIME, | ||
parseAttachment(deElapsed, 0)); | ||
sofaTracerSpan.setTag(AttachmentKeyConstants.CLIENT_SERIALIZE_SIZE, | ||
parseAttachment(reqSize, 0)); | ||
sofaTracerSpan.setTag(AttachmentKeyConstants.CLIENT_DESERIALIZE_SIZE, | ||
parseAttachment(respSize, 0)); | ||
} else { | ||
elapsed = invocation.getAttachment(CommonSpanTags.SERVER_SERIALIZE_TIME); | ||
deElapsed = invocation.getAttachment(CommonSpanTags.SERVER_DESERIALIZE_TIME); | ||
sofaTracerSpan | ||
.setTag(CommonSpanTags.SERVER_SERIALIZE_TIME, parseAttachment(elapsed, 0)); | ||
sofaTracerSpan.setTag(CommonSpanTags.SERVER_DESERIALIZE_TIME, | ||
reqSize = invocation.getAttachment(AttachmentKeyConstants.SERVER_DESERIALIZE_SIZE); | ||
deElapsed = invocation.getAttachment(AttachmentKeyConstants.SERVER_DESERIALIZE_TIME); | ||
respSize = result.getAttachment(AttachmentKeyConstants.SERVER_SERIALIZE_SIZE); | ||
elapsed = result.getAttachment(AttachmentKeyConstants.SERVER_SERIALIZE_TIME); | ||
sofaTracerSpan.setTag(AttachmentKeyConstants.SERVER_DESERIALIZE_SIZE, | ||
parseAttachment(reqSize, 0)); | ||
sofaTracerSpan.setTag(AttachmentKeyConstants.SERVER_DESERIALIZE_TIME, | ||
parseAttachment(deElapsed, 0)); | ||
sofaTracerSpan.setTag(AttachmentKeyConstants.SERVER_SERIALIZE_SIZE, | ||
parseAttachment(respSize, 0)); | ||
sofaTracerSpan.setTag(AttachmentKeyConstants.SERVER_SERIALIZE_TIME, | ||
parseAttachment(elapsed, 0)); | ||
} | ||
sofaTracerSpan.setTag(CommonSpanTags.REQ_SIZE, parseAttachment(reqSize, 0)); | ||
sofaTracerSpan.setTag(CommonSpanTags.RESP_SIZE, parseAttachment(respSize, 0)); | ||
|
||
} | ||
|
||
private int parseAttachment(String value, int defaultVal) { | ||
|
@@ -361,7 +375,7 @@ private void appendRpcServerSpanTags(Invoker<?> invoker, SofaTracerSpan sofaTrac | |
tagsStr.put(CommonSpanTags.SERVICE, service == null ? BLANK : service); | ||
String methodName = rpcContext.getMethodName(); | ||
tagsStr.put(CommonSpanTags.METHOD, methodName == null ? BLANK : methodName); | ||
String app = rpcContext.getUrl().getParameter(Constants.APPLICATION_KEY); | ||
String app = rpcContext.getUrl().getParameter(CommonConstants.APPLICATION_KEY); | ||
tagsStr.put(CommonSpanTags.REMOTE_HOST, rpcContext.getRemoteHost()); | ||
tagsStr.put(CommonSpanTags.LOCAL_APP, app == null ? BLANK : app); | ||
tagsStr.put(CommonSpanTags.CURRENT_THREAD_NAME, Thread.currentThread().getName()); | ||
|
@@ -385,7 +399,7 @@ private void appendRpcClientSpanTags(Invoker<?> invoker, SofaTracerSpan sofaTrac | |
String methodName = rpcContext.getMethodName(); | ||
tagsStr.put(CommonSpanTags.METHOD, methodName == null ? BLANK : methodName); | ||
tagsStr.put(CommonSpanTags.CURRENT_THREAD_NAME, Thread.currentThread().getName()); | ||
String app = rpcContext.getUrl().getParameter(Constants.APPLICATION_KEY); | ||
String app = rpcContext.getUrl().getParameter(CommonConstants.APPLICATION_KEY); | ||
tagsStr.put(CommonSpanTags.LOCAL_APP, app == null ? BLANK : app); | ||
tagsStr.put(CommonSpanTags.REMOTE_HOST, rpcContext.getRemoteHost()); | ||
tagsStr.put(CommonSpanTags.REMOTE_PORT, String.valueOf(rpcContext.getRemotePort())); | ||
|
39 changes: 39 additions & 0 deletions
39
.../src/main/java/com/alipay/sofa/tracer/plugins/dubbo/constants/AttachmentKeyConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.alipay.sofa.tracer.plugins.dubbo.constants; | ||
|
||
/** | ||
* @author: guolei.sgl ([email protected]) 2019/8/1 5:16 PM | ||
* @since: | ||
**/ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @author: guolei.sgl ([email protected]) 2019/7/26 5:25 PM | ||
* @since: | ||
**/ | ||
public class AttachmentKeyConstants { | ||
|
||
public static final String SERVER_DESERIALIZE_SIZE = "server.deserialize.size"; | ||
public static final String SERVER_SERIALIZE_SIZE = "server.serialize.size"; | ||
public static final String CLIENT_DESERIALIZE_SIZE = "client.deserialize.size"; | ||
public static final String CLIENT_SERIALIZE_SIZE = "client.serialize.size"; | ||
|
||
public static final String SERVER_DESERIALIZE_TIME = "server.deserialize.time"; | ||
public static final String SERVER_SERIALIZE_TIME = "server.serialize.time"; | ||
public static final String CLIENT_DESERIALIZE_TIME = "client.deserialize.time"; | ||
public static final String CLIENT_SERIALIZE_TIME = "client.serialize.time"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.