-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support feign in SOFATracer 2.x (#326)
* support feign in SOFATracer 2.x
- Loading branch information
Showing
26 changed files
with
1,242 additions
and
43 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
29 changes: 29 additions & 0 deletions
29
sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/pom.xml
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,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> |
55 changes: 55 additions & 0 deletions
55
...rc/main/java/com/alipay/sofa/tracer/plugins/springcloud/carriers/FeignRequestCarrier.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,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); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
.../main/java/com/alipay/sofa/tracer/plugins/springcloud/encodes/OpenFeignDigestEncoder.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,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)); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...n/java/com/alipay/sofa/tracer/plugins/springcloud/encodes/OpenFeignDigestJsonEncoder.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,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)); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...in/src/main/java/com/alipay/sofa/tracer/plugins/springcloud/enums/FeignClientLogEnum.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,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; | ||
} | ||
} |
Oops, something went wrong.