io.opencensus.trace.Status.getCanonicalCode()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中io.opencensus.trace.Status.getCanonicalCode()方法的一些代码示例,展示了Status.getCanonicalCode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Status.getCanonicalCode()方法的具体详情如下:
包路径:io.opencensus.trace.Status
类名称:Status
方法名:getCanonicalCode

Status.getCanonicalCode介绍

[英]Returns the canonical status code.
[中]返回规范状态代码。

代码示例

代码示例来源: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: 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: 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/gax-java

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: 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

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

/**
 * 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

@Test
 public void parseResponseStatusError_Others() {
  // some random status code
  assertThat(HttpTraceUtil.parseResponseStatus(434, null).getCanonicalCode())
    .isEqualTo(CanonicalCode.UNKNOWN);
  assertThat(HttpTraceUtil.parseResponseStatus(517, null).getCanonicalCode())
    .isEqualTo(CanonicalCode.UNKNOWN);
 }
}

代码示例来源: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

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 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: 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: 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: 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 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());
 }
}

相关文章