提交 8611124b 编写于 作者: 于玉桔 提交者: wu-sheng

Unified http status code usage (#3239)

* Unified http status code usage

* fmt
上级 73cf05c5
...@@ -114,7 +114,7 @@ public class DefaultHttpClientInterceptor implements InstanceMethodsAroundInterc ...@@ -114,7 +114,7 @@ public class DefaultHttpClientInterceptor implements InstanceMethodsAroundInterc
AbstractSpan span = ContextManager.activeSpan(); AbstractSpan span = ContextManager.activeSpan();
if (statusCode >= 400) { if (statusCode >= 400) {
span.errorOccurred(); span.errorOccurred();
Tags.STATUS_CODE.set(span, statusCode + ""); Tags.STATUS_CODE.set(span, Integer.toString(statusCode));
} }
} }
......
...@@ -49,8 +49,8 @@ public class HttpAsyncResponseConsumerWrapper<T> implements HttpAsyncResponseCon ...@@ -49,8 +49,8 @@ public class HttpAsyncResponseConsumerWrapper<T> implements HttpAsyncResponseCon
public void responseReceived(HttpResponse response) throws IOException, HttpException { public void responseReceived(HttpResponse response) throws IOException, HttpException {
if (ContextManager.isActive()) { if (ContextManager.isActive()) {
int statusCode = response.getStatusLine().getStatusCode(); int statusCode = response.getStatusLine().getStatusCode();
if (statusCode > 400) { if (statusCode >= 400) {
AbstractSpan span = ContextManager.activeSpan(); AbstractSpan span = ContextManager.activeSpan().errorOccurred();
Tags.STATUS_CODE.set(span, String.valueOf(statusCode)); Tags.STATUS_CODE.set(span, String.valueOf(statusCode));
} }
ContextManager.stopSpan(); ContextManager.stopSpan();
......
...@@ -18,19 +18,20 @@ ...@@ -18,19 +18,20 @@
package org.apache.skywalking.apm.plugin.spring.webflux.v5; package org.apache.skywalking.apm.plugin.spring.webflux.v5;
import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpResponseStatus;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import java.lang.reflect.Method;
public class StatusInterceptor implements InstanceMethodsAroundInterceptor { public class StatusInterceptor implements InstanceMethodsAroundInterceptor {
@Override @Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable { MethodInterceptResult result) throws Throwable {
HttpResponseStatus status = (HttpResponseStatus)allArguments[0]; HttpResponseStatus status = (HttpResponseStatus)allArguments[0];
if (status.code() > 400) { if (status.code() >= 400) {
ContextManager.activeSpan().errorOccurred(); ContextManager.activeSpan().errorOccurred();
Tags.STATUS_CODE.set(ContextManager.activeSpan(), String.valueOf(status.code())); Tags.STATUS_CODE.set(ContextManager.activeSpan(), String.valueOf(status.code()));
} }
......
...@@ -42,7 +42,7 @@ public class HttpClientOperationsStatusInterceptor implements InstanceMethodsAro ...@@ -42,7 +42,7 @@ public class HttpClientOperationsStatusInterceptor implements InstanceMethodsAro
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable { Object ret) throws Throwable {
HttpResponseStatus response = (HttpResponseStatus) ret; HttpResponseStatus response = (HttpResponseStatus) ret;
if (response.code() > 400) { if (response.code() >= 400) {
ContextManager.activeSpan().errorOccurred(); ContextManager.activeSpan().errorOccurred();
Tags.STATUS_CODE.set(ContextManager.activeSpan(), String.valueOf(response.code())); Tags.STATUS_CODE.set(ContextManager.activeSpan(), String.valueOf(response.code()));
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册