Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support feign in SOFATracer 2.x #326

Merged
merged 6 commits into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<module>tracer-test/log4j2-test</module>
<module>tracer-test/log4j-test</module>
<module>sofa-tracer-plugins/sofa-tracer-dubbo-2.6.x-plugin</module>
<module>sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin</module>
</modules>

<properties>
Expand Down Expand Up @@ -137,6 +138,12 @@
<version>${sofa.tracer.version}</version>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-tracer-spring-cloud-plugin</artifactId>
<version>${sofa.tracer.version}</version>
</dependency>

<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-all</artifactId>
Expand Down Expand Up @@ -169,6 +176,13 @@
<version>${opentracing.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>1.4.7.RELEASE</version>
<scope>provided</scope>
</dependency>

<!-- 对外部框架的一些插件使用 -->
<dependency>
<groupId>javax.servlet</groupId>
Expand Down
29 changes: 29 additions & 0 deletions sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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>2.4.4-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>sofa-tracer-spring-cloud-plugin</artifactId>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-core</artifactId>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>tracer-extensions</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.springcloud.carriers;

import feign.Request;
import io.opentracing.propagation.TextMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

/**
* @author: guolei.sgl (guolei.sgl@antfin.com) 2019/3/13 5:09 PM
* @since:
**/
public class FeignRequestCarrier implements TextMap {

private Request request;

public FeignRequestCarrier(Request request) {
if (request == null) {
throw new NullPointerException("Headers request should not be null!");
}
this.request = request;
}

@Override
public Iterator<Map.Entry<String, String>> iterator() {
throw new UnsupportedOperationException();
}

@Override
public void put(String key, String val) {
Collection<String> vals = request.headers().get(key);
if (vals == null) {
vals = new ArrayList<>();
}
vals.add(val);
request.headers().put(key, vals);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.springcloud.encodes;

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 io.opentracing.tag.Tags;

import java.util.Map;

/**
* @author: guolei.sgl (guolei.sgl@antfin.com) 2019/9/1 3:52 PM
* @since:
**/
public class OpenFeignDigestEncoder extends AbstractDigestSpanEncoder {

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

xsb.append(tagWithStr.get(CommonSpanTags.REQUEST_URL));
xsb.append(tagWithStr.get(CommonSpanTags.METHOD));

if (StringUtils.isNotBlank(tagWithStr.get(Tags.ERROR.getKey()))) {
xsb.append(tagWithStr.get(Tags.ERROR.getKey()));
} else {
xsb.append(StringUtils.EMPTY_STRING);
}

Number requestSize = tagWithNum.get(CommonSpanTags.REQ_SIZE);
xsb.append(requestSize == null ? 0L : requestSize.longValue());
Number responseSize = tagWithNum.get(CommonSpanTags.RESP_SIZE);
xsb.append(responseSize == null ? 0L : responseSize.longValue());

//target appName
xsb.append(tagWithStr.get(CommonSpanTags.REMOTE_HOST));
xsb.append(tagWithStr.get(CommonSpanTags.REMOTE_PORT));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.springcloud.encodes;

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 io.opentracing.tag.Tags;

import java.util.Map;

/**
* @author: guolei.sgl (guolei.sgl@antfin.com) 2019/3/13 3:30 PM
* @since:
**/
public class OpenFeignDigestJsonEncoder extends AbstractDigestSpanEncoder {

@Override
protected void appendComponentSlot(XStringBuilder xsb, JsonStringBuilder jsb,
SofaTracerSpan span) {

Map<String, String> tagWithStr = span.getTagsWithStr();
Map<String, Number> tagWithNum = span.getTagsWithNumber();

jsb.append(CommonSpanTags.REQUEST_URL, tagWithStr.get(CommonSpanTags.REQUEST_URL));
jsb.append(CommonSpanTags.METHOD, tagWithStr.get(CommonSpanTags.METHOD));

if (StringUtils.isNotBlank(tagWithStr.get(Tags.ERROR.getKey()))) {
jsb.append(Tags.ERROR.getKey(), tagWithStr.get(Tags.ERROR.getKey()));
} else {
jsb.append(Tags.ERROR.getKey(), StringUtils.EMPTY_STRING);
}

Number requestSize = tagWithNum.get(CommonSpanTags.REQ_SIZE);
jsb.append(CommonSpanTags.REQ_SIZE, (requestSize == null ? 0L : requestSize.longValue()));
Number responseSize = tagWithNum.get(CommonSpanTags.RESP_SIZE);
jsb.append(CommonSpanTags.RESP_SIZE, (responseSize == null ? 0L : responseSize.longValue()));

//target appName
jsb.append(CommonSpanTags.REMOTE_HOST, tagWithStr.get(CommonSpanTags.REMOTE_HOST));
jsb.append(CommonSpanTags.REMOTE_PORT, tagWithStr.get(CommonSpanTags.REMOTE_PORT));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.springcloud.enums;

/**
* @author: guolei.sgl (guolei.sgl@antfin.com) 2019/3/13 2:46 PM
* @since:
**/
public enum FeignClientLogEnum {
// Feign Client Digest Log
FEIGN_CLIENT_DIGEST("feign_digest_log_name", "feign-digest.log", "feign_digest_rolling"),
// Feign Client Stat Log
FEIGN_CLIENT_STAT("feign_stat_log_name", "feign-stat.log", "feign_stat_rolling");

private String logNameKey;
private String defaultLogName;
private String rollingKey;

FeignClientLogEnum(String logNameKey, String defaultLogName, String rollingKey) {
this.logNameKey = logNameKey;
this.defaultLogName = defaultLogName;
this.rollingKey = rollingKey;
}

public String getLogNameKey() {
//log reserve config key
return logNameKey;
}

public String getDefaultLogName() {
return defaultLogName;
}

public String getRollingKey() {
return rollingKey;
}
}
Loading