-
Notifications
You must be signed in to change notification settings - Fork 380
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
Resttemplate plugin #117
Merged
Merged
Resttemplate plugin #117
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9aa096b
Merge pull request #4 from alipay/master
glmapper f1d2bbc
add rest template plugin
3a897b4
Merge branch 'master-alipay'
460c9e9
reback commit
aee6415
add readme
0aec2b7
Trigger ci
8834099
upgrade-to-2.3.0
81f9270
Merge branch 'master' into resttemplate-plugin
glmapper 21fc566
Merge branch 'master' into resttemplate-plugin
3d5109c
upgrade version to 2.3.0
790b1e9
Merge branch 'resttemplate-plugin' of https://github.com/glmapper/sof…
d05fe95
Merge branch 'master' into resttemplate-plugin
glmapper 29ae802
补充自动注入方式构建Resttemplate&补充readme
e8c843c
Merge branch 'resttemplate-plugin' of https://github.com/glmapper/sof…
7fe160b
拦截器中的异常直接抛出
43af3c0
优化测试用例时间
d3686c7
修复异常规范问题
125334e
fix since & rebuild
89b916d
fix cr
cff609c
format code
ccebd65
fix cr & fix conflict
ebc0244
readme 中代码块高亮
2f5dcf1
rebuild ci
cb3e5bb
delete resttemplate properties
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
75 changes: 75 additions & 0 deletions
75
sofa-tracer-plugins/sofa-tracer-resttmplate-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,75 @@ | ||
<?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.3.0</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>sofa-tracer-resttmplate-plugin</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>tracer-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alipay.sofa</groupId> | ||
<artifactId>tracer-extensions</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
</dependency> | ||
<!-- needed for AsyncClientHttpRequestInterceptor --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
</dependency> | ||
|
||
<!-- test dependency --> | ||
<dependency> | ||
<groupId>org.jmockit</groupId> | ||
<artifactId>jmockit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jmockit</groupId> | ||
<artifactId>jmockit-coverage</artifactId> | ||
<scope>test</scope> | ||
</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>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>fastjson</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
84 changes: 84 additions & 0 deletions
84
...ugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/RestTemplateDigestJsonEncoder.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,84 @@ | ||
/* | ||
* 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.sofa.alipay.tracer.plugins.rest; | ||
|
||
import com.alipay.common.tracer.core.appender.builder.JsonStringBuilder; | ||
import com.alipay.common.tracer.core.appender.self.Timestamp; | ||
import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext; | ||
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 java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* RestTemplateDigestJsonEncoder | ||
* @author: guolei.sgl | ||
* @since: v2.3.0 | ||
*/ | ||
public class RestTemplateDigestJsonEncoder extends AbstractDigestSpanEncoder { | ||
|
||
@Override | ||
public String encode(SofaTracerSpan span) throws IOException { | ||
JsonStringBuilder jsonStringBuilder = new JsonStringBuilder(); | ||
//span end time | ||
jsonStringBuilder.appendBegin("time", Timestamp.format(span.getEndTime())); | ||
appendSlot(jsonStringBuilder, span); | ||
return jsonStringBuilder.toString(); | ||
} | ||
|
||
private void appendSlot(JsonStringBuilder jsonStringBuilder, SofaTracerSpan sofaTracerSpan) { | ||
SofaTracerSpanContext context = sofaTracerSpan.getSofaTracerSpanContext(); | ||
Map<String, String> tagWithStr = sofaTracerSpan.getTagsWithStr(); | ||
Map<String, Number> tagWithNumber = sofaTracerSpan.getTagsWithNumber(); | ||
//app | ||
jsonStringBuilder | ||
.append(CommonSpanTags.LOCAL_APP, tagWithStr.get(CommonSpanTags.LOCAL_APP)); | ||
//TraceId | ||
jsonStringBuilder.append("traceId", context.getTraceId()); | ||
//SpanId | ||
jsonStringBuilder.append("spanId", context.getSpanId()); | ||
//URL | ||
jsonStringBuilder.append(CommonSpanTags.REQUEST_URL, | ||
tagWithStr.get(CommonSpanTags.REQUEST_URL)); | ||
//POST/GET | ||
jsonStringBuilder.append(CommonSpanTags.METHOD, tagWithStr.get(CommonSpanTags.METHOD)); | ||
//Http status code | ||
jsonStringBuilder.append(CommonSpanTags.RESULT_CODE, | ||
tagWithStr.get(CommonSpanTags.RESULT_CODE)); | ||
Number responseSize = tagWithNumber.get(CommonSpanTags.RESP_SIZE); | ||
//Response Body bytes length | ||
jsonStringBuilder.append(CommonSpanTags.RESP_SIZE, (responseSize == null ? 0L | ||
: responseSize.longValue())); | ||
//time-consuming ms | ||
jsonStringBuilder.append("time.cost.milliseconds", | ||
(sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime())); | ||
jsonStringBuilder.append(CommonSpanTags.CURRENT_THREAD_NAME, | ||
tagWithStr.get(CommonSpanTags.CURRENT_THREAD_NAME)); | ||
//target appName | ||
jsonStringBuilder.append(CommonSpanTags.REMOTE_APP, | ||
tagWithStr.get(CommonSpanTags.REMOTE_APP)); | ||
this.appendBaggage(jsonStringBuilder, context); | ||
} | ||
|
||
private void appendBaggage(JsonStringBuilder jsonStringBuilder, | ||
SofaTracerSpanContext sofaTracerSpanContext) { | ||
//baggage | ||
jsonStringBuilder.appendEnd("baggage", baggageSerialized(sofaTracerSpanContext)); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...tmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/RestTemplateLogEnum.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.sofa.alipay.tracer.plugins.rest; | ||
|
||
/** | ||
* RestTemplateLogEnum | ||
* @author: guolei.sgl | ||
* @since: v2.3.0 | ||
*/ | ||
public enum RestTemplateLogEnum { | ||
|
||
// RestTemplate Client Digest Log | ||
REST_TEMPLATE_DIGEST("resttemplate_digest_log_name", "resttemplate-digest.log", | ||
"resttemplate_digest_rolling"), | ||
// RestTemplate Stat Log | ||
REST_TEMPLATE_STAT("resttemplate_stat_log_name", "resttemplate-stat.log", | ||
"resttemplate_stat_rolling"); | ||
|
||
private String logNameKey; | ||
private String defaultLogName; | ||
private String rollingKey; | ||
|
||
RestTemplateLogEnum(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; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/RestTemplateRequestCarrier.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,47 @@ | ||
/* | ||
* 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.sofa.alipay.tracer.plugins.rest; | ||
|
||
import io.opentracing.propagation.TextMap; | ||
import org.springframework.http.HttpRequest; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
/** | ||
* RestTemplateRequestCarrier | ||
* @author: guolei.sgl | ||
* @since: v2.3.0 | ||
*/ | ||
public class RestTemplateRequestCarrier implements TextMap { | ||
|
||
private final HttpRequest request; | ||
|
||
public RestTemplateRequestCarrier(HttpRequest request) { | ||
this.request = request; | ||
} | ||
|
||
@Override | ||
public Iterator<Map.Entry<String, String>> iterator() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void put(String key, String value) { | ||
request.getHeaders().add(key, value); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个版本号为什么降下来了? 2.5.2 里面修复tracer日志配置问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前是从2.4.9 升上来的,2.3.0 会依赖 sofaboot 2.5.2以上版本
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯,所以升级到最新版的2.5.2吧。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 PR 里面统一进行了版本的升级 Upgrade to 2.3.0