Skip to content

Commit

Permalink
[SCB-2049]fix trace id logger do not print error message in codes
Browse files Browse the repository at this point in the history
  • Loading branch information
liubao68 committed Jul 30, 2020
1 parent 845d763 commit da2c570
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Expand Up @@ -92,8 +92,8 @@ public void doCompletableFutureInvoke(Invocation invocation, SwaggerProducerOper
});
} catch (Throwable e) {
if (shouldPrintErrorLog(e)) {
invocation.getTraceIdLogger().error(LOGGER, "unexpected error {},",
invocation.getInvocationQualifiedName(), e);
invocation.getTraceIdLogger().error(LOGGER, "unexpected error {}, message={}",
invocation.getInvocationQualifiedName(), e.getMessage());
}
invocation.onBusinessMethodFinish();
invocation.onBusinessFinish();
Expand Down Expand Up @@ -125,8 +125,8 @@ public Response doInvoke(Invocation invocation, SwaggerProducerOperation produce
invocation.onBusinessFinish();
} catch (Throwable e) {
if (shouldPrintErrorLog(e)) {
invocation.getTraceIdLogger().error(LOGGER, "unexpected error {},",
invocation.getInvocationQualifiedName(), e);
invocation.getTraceIdLogger().error(LOGGER, "unexpected error operation={}, message={}",
invocation.getInvocationQualifiedName(), e.getMessage());
}
invocation.onBusinessMethodFinish();
invocation.onBusinessFinish();
Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.apache.servicecomb.foundation.common.http.HttpStatus;
import org.apache.servicecomb.foundation.common.net.IpPort;
import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
import org.apache.servicecomb.foundation.common.utils.ExceptionUtils;
import org.apache.servicecomb.foundation.common.utils.JsonUtils;
import org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
Expand Down Expand Up @@ -114,8 +115,8 @@ public void invoke(Invocation invocation, AsyncResponse asyncResp) throws Except
}

clientRequest.exceptionHandler(e -> {
invocation.getTraceIdLogger().error(LOGGER, "Failed to send request, local:{}, remote:{}.",
getLocalAddress(), ipPort.getSocketAddress(), e);
invocation.getTraceIdLogger().error(LOGGER, "Failed to send request, local:{}, remote:{}, message={}.",
getLocalAddress(), ipPort.getSocketAddress(), ExceptionUtils.getExceptionMessageWithoutTrace(e));
throwableHandler.handle(e);
});

Expand All @@ -128,7 +129,8 @@ public void invoke(Invocation invocation, AsyncResponse asyncResp) throws Except
restClientRequest.end();
} catch (Throwable e) {
invocation.getTraceIdLogger().error(LOGGER,
"send http request failed, local:{}, remote: {}.", getLocalAddress(), ipPort, e);
"send http request failed, local:{}, remote: {}, message={}.", getLocalAddress(), ipPort
, ExceptionUtils.getExceptionMessageWithoutTrace(e));
fail((ConnectionBase) clientRequest.connection(), e);
}
});
Expand Down Expand Up @@ -198,8 +200,9 @@ protected void handleResponse(HttpClientResponse httpClientResponse) {
}

httpClientResponse.exceptionHandler(e -> {
invocation.getTraceIdLogger().error(LOGGER, "Failed to receive response, local:{}, remote:{}.",
getLocalAddress(), httpClientResponse.netSocket().remoteAddress(), e);
invocation.getTraceIdLogger().error(LOGGER, "Failed to receive response, local:{}, remote:{}, message={}.",
getLocalAddress(), httpClientResponse.netSocket().remoteAddress(),
ExceptionUtils.getExceptionMessageWithoutTrace(e));
fail((ConnectionBase) clientRequest.connection(), e);
});

Expand Down Expand Up @@ -278,7 +281,8 @@ protected void fail(ConnectionBase connection, Throwable e) {
}
asyncResp.fail(invocation.getInvocationType(), e);
} catch (Throwable e1) {
invocation.getTraceIdLogger().error(LOGGER, "failed to invoke asyncResp.fail.", e1);
invocation.getTraceIdLogger().error(LOGGER, "failed to invoke asyncResp, message={}"
, ExceptionUtils.getExceptionMessageWithoutTrace(e));
}
}

Expand All @@ -287,7 +291,8 @@ protected void setCseContext() {
String cseContext = JsonUtils.writeValueAsString(invocation.getContext());
clientRequest.putHeader(org.apache.servicecomb.core.Const.CSE_CONTEXT, cseContext);
} catch (Throwable e) {
invocation.getTraceIdLogger().error(LOGGER, "Failed to encode and set cseContext.", e);
invocation.getTraceIdLogger().error(LOGGER, "Failed to encode and set cseContext, message={}."
, ExceptionUtils.getExceptionMessageWithoutTrace(e));
}
}

Expand Down
Expand Up @@ -281,7 +281,9 @@ public void testSetCseContext_failed() throws JsonProcessingException {

restClientInvocation.setCseContext();

Assert.assertEquals("Failed to encode and set cseContext.", logCollector.getEvents().get(0).getMessage());
Assert.assertEquals(
"Failed to encode and set cseContext, message=cause:RuntimeExceptionWithoutStackTrace,message:null.",
logCollector.getEvents().get(0).getMessage());
logCollector.teardown();
}

Expand Down

0 comments on commit da2c570

Please sign in to comment.