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

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

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

Tracer.spanBuilder介绍

[英]Returns a SpanBuilder to create and start a new child Span as a child of to the current Span if any, otherwise creates a root Span.

See SpanBuilder for usage examples.

This must be used to create a Span when automatic Context propagation is used.

This is equivalent with:

tracer.spanBuilderWithExplicitParent("MySpanName",tracer.getCurrentSpan());

[中]返回SpanBuilder以创建并启动新的子跨度,作为当前跨度的子跨度(如果有),否则将创建根跨度。
有关用法示例,请参见SpanBuilder。
当使用自动上下文传播时,必须使用此选项来创建范围。
这相当于:

tracer.spanBuilderWithExplicitParent("MySpanName",tracer.getCurrentSpan());

代码示例

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

/** Transaction functions that returns its result in the provided SettableFuture. */
private <T> void runTransaction(
  final Transaction.Function<T> transactionCallback,
  final SettableApiFuture<T> resultFuture,
  final TransactionOptions options) {
 // span is intentionally not ended here. It will be ended by runTransactionAttempt on success
 // or error.
 Span span = tracer.spanBuilder("CloudFirestore.Transaction").startSpan();
 try (Scope s = tracer.withSpan(span)) {
  runTransactionAttempt(transactionCallback, resultFuture, options, span);
 }
}

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

/** Helper method to start a span. */
private Span startSpan(String spanName) {
 return tracer
   .spanBuilder(spanName)
   .setRecordEvents(censusHttpModule.isRecordEvents())
   .startSpan();
}

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

@Override
public ReadOnlyTransaction singleUseReadOnlyTransaction(TimestampBound bound) {
 Span span = tracer.spanBuilder(READ_ONLY_TRANSACTION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  return pool.getReadSession().singleUseReadOnlyTransaction(bound);
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 }
}

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

@Override
public ReadOnlyTransaction readOnlyTransaction() {
 Span span = tracer.spanBuilder(READ_ONLY_TRANSACTION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  return pool.getReadSession().readOnlyTransaction();
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 }
}

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

@Override
public TransactionRunner readWriteTransaction() {
 Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  return pool.getReadWriteSession().readWriteTransaction();
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 }
}

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

@Override
public void close() {
 Span span = tracer.spanBuilder(DELETE_SESSION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  runWithRetries(
    new Callable<Void>() {
     @Override
     public Void call() throws Exception {
      gapicRpc.deleteSession(name, options);
      return null;
     }
    });
  span.end();
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 }
}

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

@Override
public ReadContext singleUse() {
 Span span = tracer.spanBuilder(READ_ONLY_TRANSACTION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  return pool.getReadSession().singleUse();
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 }
}

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

@Override
public ReadContext singleUse(TimestampBound bound) {
 Span span = tracer.spanBuilder(READ_ONLY_TRANSACTION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  return pool.getReadSession().singleUse(bound);
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 }
}

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

@Override
public ReadOnlyTransaction singleUseReadOnlyTransaction() {
 Span span = tracer.spanBuilder(READ_ONLY_TRANSACTION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  return pool.getReadSession().singleUseReadOnlyTransaction();
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 }
}

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

@Override
public ReadOnlyTransaction readOnlyTransaction(TimestampBound bound) {
 Span span = tracer.spanBuilder(READ_ONLY_TRANSACTION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  return pool.getReadSession().readOnlyTransaction(bound);
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 }
}

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

@Override
public TransactionManager transactionManager() {
 Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  return pool.getReadWriteSession().transactionManager();
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 }
}

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

@Override
public long executePartitionedUpdate(Statement stmt) {
 Span span = tracer.spanBuilder(PARTITION_DML_TRANSACTION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  return pool.getReadWriteSession().executePartitionedUpdate(stmt);
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 }
}

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

@Override
public Timestamp write(Iterable<Mutation> mutations) throws SpannerException {
 Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  return pool.getReadWriteSession().write(mutations);
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 } finally {
  span.end();
 }
}

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

@Override
public Timestamp writeAtLeastOnce(Iterable<Mutation> mutations) throws SpannerException {
 Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  return pool.getReadWriteSession().writeAtLeastOnce(mutations);
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 } finally {
  span.end();
 }
}

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

Session createSession(final DatabaseId db) throws SpannerException {
 final Map<SpannerRpc.Option, ?> options =
   optionMap(SessionOption.channelHint(random.nextLong()));
 Span span = tracer.spanBuilder(CREATE_SESSION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  com.google.spanner.v1.Session session =
    runWithRetries(
      new Callable<com.google.spanner.v1.Session>() {
       @Override
       public com.google.spanner.v1.Session call() throws Exception {
        return gapicRpc.createSession(
          db.getName(), getOptions().getSessionLabels(), options);
       }
      });
  span.end();
  return new SessionImpl(session.getName(), options);
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 }
}

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

ByteString beginTransaction() {
 Span span = tracer.spanBuilder(BEGIN_TRANSACTION).startSpan();
 try (Scope s = tracer.withSpan(span)) {
  final BeginTransactionRequest request =
    BeginTransactionRequest.newBuilder()
      .setSession(name)
      .setOptions(
        TransactionOptions.newBuilder()
          .setReadWrite(TransactionOptions.ReadWrite.getDefaultInstance()))
      .build();
  Transaction txn =
    runWithRetries(
      new Callable<Transaction>() {
       @Override
       public Transaction call() throws Exception {
        return gapicRpc.beginTransaction(request, options);
       }
      });
  if (txn.getId().isEmpty()) {
   throw newSpannerException(ErrorCode.INTERNAL, "Missing id in transaction\n" + getName());
  }
  span.end();
  return txn.getId();
 } catch (RuntimeException e) {
  TraceUtil.endSpanWithFailure(span, e);
  throw e;
 }
}

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

.setReadWrite(TransactionOptions.ReadWrite.getDefaultInstance()))
    .build();
Span span = tracer.spanBuilder(COMMIT).startSpan();
try (Scope s = tracer.withSpan(span)) {
 CommitResponse response =

代码示例来源:origin: census-instrumentation/opencensus-java

@MustBeClosed
private static Scope newExportScope() {
 // Start a new span with explicit sampler (with low probability) to avoid the case when user
 // sets the default sampler to always sample and we get the Thrift span of the Jaeger
 // export call always sampled and go to an infinite loop.
 return tracer.spanBuilder(EXPORT_SPAN_NAME).setSampler(lowProbabilitySampler).startScopedSpan();
}

代码示例来源:origin: census-instrumentation/opencensus-java

@MustBeClosed
@Override
public Closeable startScopedSpan(String spanName) {
 checkNotNull(spanName, "spanName");
 return Tracing.getTracer()
   .spanBuilder(spanName)
   .setSampler(Samplers.alwaysSample())
   .setRecordEvents(true)
   .startScopedSpan();
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
 public void doNotCrash_NoopImplementation() throws Exception {
  SpanBuilder spanBuilder = tracer.spanBuilder("MySpanName");
  spanBuilder.setParentLinks(Collections.<Span>emptyList());
  spanBuilder.setRecordEvents(true);
  spanBuilder.setSampler(Samplers.alwaysSample());
  spanBuilder.setSpanKind(Kind.SERVER);
  assertThat(spanBuilder.startSpan()).isSameAs(BlankSpan.INSTANCE);
 }
}

相关文章