本文整理了Java中io.opencensus.trace.Status.getDescription()
方法的一些代码示例,展示了Status.getDescription()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Status.getDescription()
方法的具体详情如下:
包路径:io.opencensus.trace.Status
类名称:Status
方法名:getDescription
[英]Returns the description of this Status for human consumption.
[中]返回此状态的描述以供人类使用。
代码示例来源:origin: census-instrumentation/opencensus-java
/**
* Returns a {@link io.grpc.Status} from a {@link io.opencensus.trace.Status}.
*
* @param opencensusStatus the given {@code io.opencensus.trace.Status}.
* @return a {@code io.grpc.Status} from a {@code io.opencensus.trace.Status}.
* @since 0.6
*/
public static io.grpc.Status toGrpcStatus(io.opencensus.trace.Status opencensusStatus) {
io.grpc.Status status =
grpcStatusFromOpencensusCanonicalCode(opencensusStatus.getCanonicalCode());
if (opencensusStatus.getDescription() != null) {
status = status.withDescription(opencensusStatus.getDescription());
}
return status;
}
代码示例来源:origin: io.opencensus/opencensus-contrib-grpc-util
/**
* Returns a {@link io.grpc.Status} from a {@link io.opencensus.trace.Status}.
*
* @param opencensusStatus the given {@code io.opencensus.trace.Status}.
* @return a {@code io.grpc.Status} from a {@code io.opencensus.trace.Status}.
* @since 0.6
*/
public static io.grpc.Status toGrpcStatus(io.opencensus.trace.Status opencensusStatus) {
io.grpc.Status status =
grpcStatusFromOpencensusCanonicalCode(opencensusStatus.getCanonicalCode());
if (opencensusStatus.getDescription() != null) {
status = status.withDescription(opencensusStatus.getDescription());
}
return status;
}
代码示例来源:origin: census-instrumentation/opencensus-java
private static Status toStatusProto(io.opencensus.trace.Status status) {
Status.Builder statusBuilder = Status.newBuilder().setCode(status.getCanonicalCode().value());
if (status.getDescription() != null) {
statusBuilder.setMessage(status.getDescription());
}
return statusBuilder.build();
}
代码示例来源:origin: census-instrumentation/opencensus-java
private static Status toStatusProto(io.opencensus.trace.Status status) {
Status.Builder statusBuilder = Status.newBuilder().setCode(status.getCanonicalCode().value());
if (status.getDescription() != null) {
statusBuilder.setMessage(status.getDescription());
}
return statusBuilder.build();
}
代码示例来源:origin: io.opencensus/opencensus-exporter-trace-stackdriver
private static Status toStatusProto(io.opencensus.trace.Status status) {
Status.Builder statusBuilder = Status.newBuilder().setCode(status.getCanonicalCode().value());
if (status.getDescription() != null) {
statusBuilder.setMessage(status.getDescription());
}
return statusBuilder.build();
}
代码示例来源:origin: census-instrumentation/opencensus-java
@Test
public void parseResponseStatusErrorWithoutMessage() {
Throwable error = new NullPointerException();
assertThat(HttpTraceUtil.parseResponseStatus(0, error).getDescription())
.isEqualTo("NullPointerException");
}
代码示例来源:origin: census-instrumentation/opencensus-java
@Test
public void parseResponseStatusErrorWithMessage() {
Throwable error = new Exception("testError");
assertThat(HttpTraceUtil.parseResponseStatus(0, error).getDescription()).isEqualTo("testError");
}
代码示例来源:origin: census-instrumentation/opencensus-java
private static void parseResponseStatus(
int code, CanonicalCode expectedCanonicalCode, String expectedDesc) {
Status status = HttpTraceUtil.parseResponseStatus(code, null);
assertThat(status.getCanonicalCode()).isEqualTo(expectedCanonicalCode);
assertThat(status.getDescription()).isEqualTo(expectedDesc);
}
代码示例来源:origin: census-instrumentation/opencensus-java
@Test
public void status_Ok() {
assertThat(Status.OK.getCanonicalCode()).isEqualTo(Status.CanonicalCode.OK);
assertThat(Status.OK.getDescription()).isNull();
assertThat(Status.OK.isOk()).isTrue();
}
代码示例来源:origin: census-instrumentation/opencensus-java
@Test
public void parseResponseStatusNoResponse() {
assertThat(HttpTraceUtil.parseResponseStatus(0, null).getDescription()).isEqualTo(null);
assertThat(HttpTraceUtil.parseResponseStatus(0, null).getCanonicalCode())
.isEqualTo(CanonicalCode.UNKNOWN);
}
代码示例来源:origin: census-instrumentation/opencensus-java
@Test
public void createStatus_WithDescription() {
Status status = Status.UNKNOWN.withDescription("This is an error.");
assertThat(status.getCanonicalCode()).isEqualTo(Status.CanonicalCode.UNKNOWN);
assertThat(status.getDescription()).isEqualTo("This is an error.");
assertThat(status.isOk()).isFalse();
}
代码示例来源:origin: googleapis/gax-java
@Test
public void testErrorConversion() {
for (Code code : Code.values()) {
ApiException error = new ApiException("fake message", null, new FakeStatusCode(code), false);
Status opencensusStatus = OpencensusTracer.convertErrorToStatus(error);
assertThat(opencensusStatus.getDescription()).isEqualTo("fake message");
assertThat(opencensusStatus.getCanonicalCode().toString()).isEqualTo(code.toString());
}
}
}
代码示例来源:origin: census-instrumentation/opencensus-java
@Test
public void convertFromGrpcStatus() {
// Without description
for (io.grpc.Status.Code grpcCanonicalCode : io.grpc.Status.Code.values()) {
io.grpc.Status grpcStatus = io.grpc.Status.fromCode(grpcCanonicalCode);
io.opencensus.trace.Status opencensusStatus = StatusConverter.fromGrpcStatus(grpcStatus);
assertThat(opencensusStatus.getCanonicalCode().toString())
.isEqualTo(grpcStatus.getCode().toString());
assertThat(opencensusStatus.getDescription()).isNull();
}
// With description
for (io.grpc.Status.Code grpcCanonicalCode : io.grpc.Status.Code.values()) {
io.grpc.Status grpcStatus =
io.grpc.Status.fromCode(grpcCanonicalCode).withDescription("This is my description");
io.opencensus.trace.Status opencensusStatus = StatusConverter.fromGrpcStatus(grpcStatus);
assertThat(opencensusStatus.getCanonicalCode().toString())
.isEqualTo(grpcStatus.getCode().toString());
assertThat(opencensusStatus.getDescription()).isEqualTo(grpcStatus.getDescription());
}
}
代码示例来源:origin: census-instrumentation/opencensus-java
@Test
public void convertToGrpcStatus() {
// Without description
for (io.opencensus.trace.Status.CanonicalCode opencensusCanonicalCode :
io.opencensus.trace.Status.CanonicalCode.values()) {
io.opencensus.trace.Status opencensusStatus = opencensusCanonicalCode.toStatus();
io.grpc.Status grpcStatus = StatusConverter.toGrpcStatus(opencensusStatus);
assertThat(grpcStatus.getCode().toString())
.isEqualTo(opencensusStatus.getCanonicalCode().toString());
assertThat(grpcStatus.getDescription()).isNull();
}
// With description
for (io.opencensus.trace.Status.CanonicalCode opencensusCanonicalCode :
io.opencensus.trace.Status.CanonicalCode.values()) {
io.opencensus.trace.Status opencensusStatus =
opencensusCanonicalCode.toStatus().withDescription("This is my description");
io.grpc.Status grpcStatus = StatusConverter.toGrpcStatus(opencensusStatus);
assertThat(grpcStatus.getCode().toString())
.isEqualTo(opencensusStatus.getCanonicalCode().toString());
assertThat(grpcStatus.getDescription()).isEqualTo(opencensusStatus.getDescription());
}
}
}
代码示例来源:origin: census-instrumentation/opencensus-java
if (status != null) {
spanBuilder.putTag(STATUS_CODE, status.getCanonicalCode().toString());
if (status.getDescription() != null) {
spanBuilder.putTag(STATUS_DESCRIPTION, status.getDescription());
内容来源于网络,如有侵权,请联系作者删除!