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

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

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

Status.withDescription介绍

[英]Creates a derived instance of Status with the given description.
[中]创建具有给定描述的状态的派生实例。

代码示例

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

static void endSpanWithFailure(Span span, SpannerException e) {
 span.setStatus(
   StatusConverter.fromGrpcStatus(e.getErrorCode().getGrpcStatus())
     .withDescription(e.getMessage()));
 span.end();
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public StorageObject patch(StorageObject storageObject, Map<Option, ?> options) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_PATCH_OBJECT);
 Scope scope = tracer.withSpan(span);
 try {
  return patchCall(storageObject, options).execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public Notification createNotification(String bucket, Notification notification) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_NOTIFICATION);
 Scope scope = tracer.withSpan(span);
 try {
  return storage.notifications().insert(bucket, notification).execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public List<ObjectAccessControl> listDefaultAcls(String bucket) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_LIST_OBJECT_DEFAULT_ACLS);
 Scope scope = tracer.withSpan(span);
 try {
  return storage.defaultObjectAccessControls().list(bucket).execute().getItems();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public List<Notification> listNotifications(String bucket) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_LIST_NOTIFICATIONS);
 Scope scope = tracer.withSpan(span);
 try {
  return storage.notifications().list(bucket).execute().getItems();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public ObjectAccessControl createDefaultAcl(ObjectAccessControl acl) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_OBJECT_DEFAULT_ACL);
 Scope scope = tracer.withSpan(span);
 try {
  return storage.defaultObjectAccessControls().insert(acl.getBucket(), acl).execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public StorageObject get(StorageObject object, Map<Option, ?> options) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_OBJECT);
 Scope scope = tracer.withSpan(span);
 try {
  return getCall(object, options).execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  StorageException serviceException = translate(ex);
  if (serviceException.getCode() == HTTP_NOT_FOUND) {
   return null;
  }
  throw serviceException;
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
 public ServiceAccount getServiceAccount(String projectId) {
  Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_SERVICE_ACCOUNT);
  Scope scope = tracer.withSpan(span);
  try {
   return storage.projects().serviceAccount().get(projectId).execute();
  } catch (IOException ex) {
   span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
   throw translate(ex);
  } finally {
   scope.close();
   span.end();
  }
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public ObjectAccessControl getDefaultAcl(String bucket, String entity) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_OBJECT_DEFAULT_ACL);
 Scope scope = tracer.withSpan(span);
 try {
  return storage.defaultObjectAccessControls().get(bucket, entity).execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  StorageException serviceException = translate(ex);
  if (serviceException.getCode() == HTTP_NOT_FOUND) {
   return null;
  }
  throw serviceException;
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public ObjectAccessControl patchDefaultAcl(ObjectAccessControl acl) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_PATCH_OBJECT_DEFAULT_ACL);
 Scope scope = tracer.withSpan(span);
 try {
  return storage
    .defaultObjectAccessControls()
    .patch(acl.getBucket(), acl.getEntity(), acl)
    .execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public Policy setIamPolicy(String bucket, Policy policy, Map<Option, ?> options) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_SET_BUCKET_IAM_POLICY);
 Scope scope = tracer.withSpan(span);
 try {
  return storage
    .buckets()
    .setIamPolicy(bucket, policy)
    .setUserProject(Option.USER_PROJECT.getString(options))
    .execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public Policy getIamPolicy(String bucket, Map<Option, ?> options) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_BUCKET_IAM_POLICY);
 Scope scope = tracer.withSpan(span);
 try {
  return storage
    .buckets()
    .getIamPolicy(bucket)
    .setUserProject(Option.USER_PROJECT.getString(options))
    .execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public BucketAccessControl createAcl(BucketAccessControl acl, Map<Option, ?> options) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_BUCKET_ACL);
 Scope scope = tracer.withSpan(span);
 try {
  return storage
    .bucketAccessControls()
    .insert(acl.getBucket(), acl)
    .setUserProject(Option.USER_PROJECT.getString(options))
    .execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public List<BucketAccessControl> listAcls(String bucket, Map<Option, ?> options) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_LIST_BUCKET_ACLS);
 Scope scope = tracer.withSpan(span);
 try {
  return storage
    .bucketAccessControls()
    .list(bucket)
    .setUserProject(Option.USER_PROJECT.getString(options))
    .execute()
    .getItems();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public BucketAccessControl patchAcl(BucketAccessControl acl, Map<Option, ?> options) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_PATCH_BUCKET_ACL);
 Scope scope = tracer.withSpan(span);
 try {
  return storage
    .bucketAccessControls()
    .patch(acl.getBucket(), acl.getEntity(), acl)
    .setUserProject(Option.USER_PROJECT.getString(options))
    .execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public ObjectAccessControl createAcl(ObjectAccessControl acl) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_OBJECT_ACL);
 Scope scope = tracer.withSpan(span);
 try {
  return storage
    .objectAccessControls()
    .insert(acl.getBucket(), acl.getObject(), acl)
    .setGeneration(acl.getGeneration())
    .execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public Bucket lockRetentionPolicy(Bucket bucket, Map<Option, ?> options) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_LOCK_RETENTION_POLICY);
 Scope scope = tracer.withSpan(span);
 try {
  return storage
    .buckets()
    .lockRetentionPolicy(bucket.getName(), Option.IF_METAGENERATION_MATCH.getLong(options))
    .setUserProject(Option.USER_PROJECT.getString(options))
    .execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public ObjectAccessControl patchAcl(ObjectAccessControl acl) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_PATCH_OBJECT_ACL);
 Scope scope = tracer.withSpan(span);
 try {
  return storage
    .objectAccessControls()
    .patch(acl.getBucket(), acl.getObject(), acl.getEntity(), acl)
    .setGeneration(acl.getGeneration())
    .execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

相关文章