本文整理了Java中io.opencensus.trace.Status
类的一些代码示例,展示了Status
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Status
类的具体详情如下:
包路径:io.opencensus.trace.Status
类名称:Status
[英]Defines the status of a Span by providing a standard CanonicalCode in conjunction with an optional descriptive message. Instances of Status are created by starting with the template for the appropriate Status.CanonicalCode and supplementing it with additional information: Status.NOT_FOUND.withDescription("Could not find
[中]通过提供标准规范代码和可选的描述性消息来定义范围的状态。状态的实例是从相应状态的模板开始创建的。CanonicalCode并用附加信息对其进行补充:状态。没有找到。withDescription(“无法找到
代码示例来源:origin: googleapis/google-cloud-java
static void endSpanWithFailure(Span span, Exception e) {
if (e instanceof SpannerException) {
endSpanWithFailure(span, (SpannerException) e);
} else {
span.setStatus(Status.INTERNAL.withDescription(e.getMessage()));
span.end();
}
}
代码示例来源: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: 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: 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
@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
/**
* Returns a {@link io.opencensus.trace.Status.CanonicalCode} from a {@link io.grpc.Status.Code}.
*
* @param grpcCode the given {@code io.grpc.Status.Code}.
* @return a {@code io.opencensus.trace.Status.CanonicalCode} from a {@code io.grpc.Status.Code}.
* @since 0.6
*/
public static io.opencensus.trace.Status.CanonicalCode fromGrpcCode(
io.grpc.Status.Code grpcCode) {
return opencensusStatusFromGrpcCode(grpcCode).getCanonicalCode();
}
代码示例来源:origin: census-instrumentation/opencensus-java
private void considerForSampling(RecordEventsSpanImpl span) {
Status status = span.getStatus();
// Null status means running Span, this should not happen in production, but the library
// should not crash because of this.
if (status != null) {
Bucket bucket =
status.isOk()
? getLatencyBucket(span.getLatencyNs())
: getErrorBucket(status.getCanonicalCode());
// If unable to find the bucket, ignore this Span.
if (bucket != null) {
bucket.considerForSampling(span);
}
}
}
代码示例来源:origin: census-instrumentation/opencensus-java
private static List<Status> buildStatusList() {
TreeMap<Integer, Status> canonicalizer = new TreeMap<Integer, Status>();
for (CanonicalCode code : CanonicalCode.values()) {
Status replaced = canonicalizer.put(code.value(), new Status(code, null));
if (replaced != null) {
throw new IllegalStateException(
"Code value duplication between "
+ replaced.getCanonicalCode().name()
+ " & "
+ code.name());
}
}
return Collections.unmodifiableList(new ArrayList<Status>(canonicalizer.values()));
}
代码示例来源: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
sb.append("\"name\":\"").append(toSpanName(span)).append("\",");
sb.append("\"type\":\"").append(toSpanType(span)).append('"');
if (!status.isOk()) {
sb.append(",\"error\":").append("true");
代码示例来源: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: io.opencensus/opencensus-contrib-grpc-util
/**
* Returns a {@link io.opencensus.trace.Status.CanonicalCode} from a {@link io.grpc.Status.Code}.
*
* @param grpcCode the given {@code io.grpc.Status.Code}.
* @return a {@code io.opencensus.trace.Status.CanonicalCode} from a {@code io.grpc.Status.Code}.
* @since 0.6
*/
public static io.opencensus.trace.Status.CanonicalCode fromGrpcCode(
io.grpc.Status.Code grpcCode) {
return opencensusStatusFromGrpcCode(grpcCode).getCanonicalCode();
}
代码示例来源:origin: io.opencensus/opencensus-impl-core
private void considerForSampling(RecordEventsSpanImpl span) {
Status status = span.getStatus();
// Null status means running Span, this should not happen in production, but the library
// should not crash because of this.
if (status != null) {
Bucket bucket =
status.isOk()
? getLatencyBucket(span.getLatencyNs())
: getErrorBucket(status.getCanonicalCode());
// If unable to find the bucket, ignore this Span.
if (bucket != null) {
bucket.considerForSampling(span);
}
}
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
private static List<Status> buildStatusList() {
TreeMap<Integer, Status> canonicalizer = new TreeMap<Integer, Status>();
for (CanonicalCode code : CanonicalCode.values()) {
Status replaced = canonicalizer.put(code.value(), new Status(code, null));
if (replaced != null) {
throw new IllegalStateException(
"Code value duplication between "
+ replaced.getCanonicalCode().name()
+ " & "
+ code.name());
}
}
return Collections.unmodifiableList(new ArrayList<Status>(canonicalizer.values()));
}
代码示例来源:origin: census-instrumentation/opencensus-java
@Test
public void parseResponseStatusErrorWithoutMessage() {
Throwable error = new NullPointerException();
assertThat(HttpTraceUtil.parseResponseStatus(0, error).getDescription())
.isEqualTo("NullPointerException");
}
代码示例来源:origin: googleapis/google-cloud-java
static void endSpanWithFailure(Span span, SpannerException e) {
span.setStatus(
StatusConverter.fromGrpcStatus(e.getErrorCode().getGrpcStatus())
.withDescription(e.getMessage()));
span.end();
}
代码示例来源: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: com.google.api/gax
private void populateError(Map<String, AttributeValue> attributes, Throwable error) {
if (error == null) {
attributes.put("status", null);
return;
}
Status status = convertErrorToStatus(error);
attributes.put(
"status", AttributeValue.stringAttributeValue(status.getCanonicalCode().toString()));
}
代码示例来源:origin: googleapis/google-cloud-java
public static Status statusFromApiException(ApiException exception) {
if (exception.getStatusCode().getTransportCode() instanceof io.grpc.Status) {
io.grpc.Status grpcStatus = (io.grpc.Status) exception.getStatusCode().getTransportCode();
return StatusConverter.fromGrpcStatus(grpcStatus);
}
return Status.UNKNOWN.withDescription(exception.getMessage());
}
}
代码示例来源: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();
}
内容来源于网络,如有侵权,请联系作者删除!