Skip to content

Commit

Permalink
Bugfix/dubbo attachment (#350)
Browse files Browse the repository at this point in the history
* dubbo compatible  all for 2.6.x and 2.7.x
  • Loading branch information
xzchaoo authored Mar 31, 2020
1 parent f3effb5 commit 0d5ec87
Show file tree
Hide file tree
Showing 41 changed files with 2,254 additions and 40 deletions.
35 changes: 20 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>

<artifactId>tracer-all-parent</artifactId>
<version>3.0.11</version>
<version>3.0.12</version>
<packaging>pom</packaging>
<name>tracer-all-parent</name>
<description>Alipay SOFATracer Log Implemented by OpenTracing</description>
Expand All @@ -33,11 +33,11 @@
<module>tracer-test/logback-test</module>
<module>tracer-test/log4j2-test</module>
<module>tracer-test/log4j-test</module>
<module>sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin</module>
</modules>

<properties>
<opentracing.version>0.22.0</opentracing.version>
<sofa.tracer.version>3.0.11</sofa.tracer.version>
<java.compiler.source.version>1.8</java.compiler.source.version>
<java.compiler.target.version>1.8</java.compiler.target.version>
<jmh.version>1.9.3</jmh.version>
Expand Down Expand Up @@ -89,62 +89,67 @@
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-core</artifactId>
<version>${sofa.tracer.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-extensions</artifactId>
<version>${sofa.tracer.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-springmvc-plugin</artifactId>
<version>${sofa.tracer.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-httpclient-plugin</artifactId>
<version>${sofa.tracer.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-okhttp-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-resttmplate-plugin</artifactId>
<version>${sofa.tracer.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-datasource-plugin</artifactId>
<version>${sofa.tracer.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-zipkin-plugin</artifactId>
<version>${sofa.tracer.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-spring-cloud-plugin</artifactId>
<version>${sofa.tracer.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-dubbo-plugin</artifactId>
<version>${sofa.tracer.version}</version>
<artifactId>sofa-tracer-dubbo-common-plugin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-flexible-plugin</artifactId>
<version>${sofa.tracer.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-all</artifactId>
<version>${sofa.tracer.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-sofa-boot-starter</artifactId>
<version>${sofa.tracer.version}</version>
<version>${project.version}</version>
</dependency>
<!-- opentracing dependency -->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion sofa-tracer-plugins/sofa-tracer-datasource-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.0.11</version>
<version>3.0.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sofa-tracer-plugins/sofa-tracer-dubbo-2.6.x-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.0.11</version>
<version>3.0.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
50 changes: 50 additions & 0 deletions sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.0.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>sofa-tracer-dubbo-common-plugin</artifactId>

<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.3</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-core</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.
*/
package com.alipay.sofa.tracer.plugins.dubbo.constants;

/**
* @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";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.
*/
package com.alipay.sofa.tracer.plugins.dubbo.encoder;

import com.alipay.common.tracer.core.appender.builder.JsonStringBuilder;
import com.alipay.common.tracer.core.appender.builder.XStringBuilder;
import com.alipay.common.tracer.core.middleware.parent.AbstractDigestSpanEncoder;
import com.alipay.common.tracer.core.span.CommonSpanTags;
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 io.opentracing.tag.Tags;

import java.util.Map;

/**
* @author: guolei.sgl ([email protected]) 2019/9/1 2:46 PM
* @since:
**/
public class DubboClientDigestEncoder extends AbstractDigestSpanEncoder {

@Override
protected void appendComponentSlot(XStringBuilder xsb, JsonStringBuilder jsb,
SofaTracerSpan span) {
Map<String, String> tagWithStr = span.getTagsWithStr();
Map<String, Number> tagWithNum = span.getTagsWithNumber();
//protocol
xsb.append(tagWithStr.get(CommonSpanTags.PROTOCOL));
// service
xsb.append(tagWithStr.get(CommonSpanTags.SERVICE));
// method
xsb.append(tagWithStr.get(CommonSpanTags.METHOD));
// invoke type
xsb.append(tagWithStr.get(CommonSpanTags.INVOKE_TYPE));
// remote host
xsb.append(tagWithStr.get(CommonSpanTags.REMOTE_HOST));
// remote port
xsb.append(tagWithStr.get(CommonSpanTags.REMOTE_PORT));
// local port
xsb.append(tagWithStr.get(CommonSpanTags.LOCAL_HOST));
// client.serialize.time
xsb.append(tagWithNum.get(AttachmentKeyConstants.CLIENT_SERIALIZE_TIME) + "");
// client.deserialize.time
xsb.append(tagWithNum.get(AttachmentKeyConstants.CLIENT_DESERIALIZE_TIME) + "");
// client.serialize.size
Number reqSizeNum = tagWithNum.get(AttachmentKeyConstants.CLIENT_SERIALIZE_SIZE);
xsb.append(reqSizeNum == null ? 0 : reqSizeNum.longValue());
// client.deserialize.size
Number respSizeNum = tagWithNum.get(AttachmentKeyConstants.CLIENT_DESERIALIZE_SIZE);
xsb.append(respSizeNum == null ? 0 : respSizeNum.longValue());
// error message
xsb.append(StringUtils.isBlank(tagWithStr.get(Tags.ERROR.getKey())) ? "" : tagWithStr
.get(Tags.ERROR.getKey()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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.
*/
package com.alipay.sofa.tracer.plugins.dubbo.encoder;

import com.alipay.common.tracer.core.appender.builder.JsonStringBuilder;
import com.alipay.common.tracer.core.appender.builder.XStringBuilder;
import com.alipay.common.tracer.core.middleware.parent.AbstractDigestSpanEncoder;
import com.alipay.common.tracer.core.span.CommonSpanTags;
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 io.opentracing.tag.Tags;

import java.util.Map;

/**
* @author: guolei.sgl ([email protected]) 2019/2/26 3:56 PM
* @since:
**/
public class DubboClientDigestJsonEncoder extends AbstractDigestSpanEncoder {

@Override
protected void appendComponentSlot(XStringBuilder xsb, JsonStringBuilder jsb,
SofaTracerSpan span) {
Map<String, String> tagStr = span.getTagsWithStr();
Map<String, Number> tagNum = span.getTagsWithNumber();

// protocol
jsb.append(CommonSpanTags.PROTOCOL, tagStr.get(CommonSpanTags.PROTOCOL));
// serviceName
jsb.append(CommonSpanTags.SERVICE, tagStr.get(CommonSpanTags.SERVICE));
// method
jsb.append(CommonSpanTags.METHOD, tagStr.get(CommonSpanTags.METHOD));
//invoke type
jsb.append(CommonSpanTags.INVOKE_TYPE, tagStr.get(CommonSpanTags.INVOKE_TYPE));
//target ip
jsb.append(CommonSpanTags.REMOTE_HOST, tagStr.get(CommonSpanTags.REMOTE_HOST));
//target port
jsb.append(CommonSpanTags.REMOTE_PORT, tagStr.get(CommonSpanTags.REMOTE_PORT));
//local ip
jsb.append(CommonSpanTags.LOCAL_HOST, tagStr.get(CommonSpanTags.LOCAL_HOST));
//request serialize time
jsb.append(CommonSpanTags.CLIENT_SERIALIZE_TIME,
tagNum.get(AttachmentKeyConstants.CLIENT_SERIALIZE_TIME));
//response deserialize time
jsb.append(CommonSpanTags.CLIENT_DESERIALIZE_TIME,
tagNum.get(AttachmentKeyConstants.CLIENT_DESERIALIZE_TIME));
//Request Body bytes length
Number reqSizeNum = tagNum.get(AttachmentKeyConstants.CLIENT_SERIALIZE_SIZE);
jsb.append(CommonSpanTags.REQ_SIZE, reqSizeNum == null ? 0 : reqSizeNum.longValue());
//Response Body bytes length
Number respSizeNum = tagNum.get(AttachmentKeyConstants.CLIENT_DESERIALIZE_SIZE);
jsb.append(CommonSpanTags.RESP_SIZE, respSizeNum == null ? 0 : respSizeNum.longValue());

//error message
if (StringUtils.isNotBlank(tagStr.get(Tags.ERROR.getKey()))) {
jsb.append(Tags.ERROR.getKey(), tagStr.get(Tags.ERROR.getKey()));
} else {
jsb.append(Tags.ERROR.getKey(), StringUtils.EMPTY_STRING);
}
}
}
Loading

0 comments on commit 0d5ec87

Please sign in to comment.