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

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

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

Tracer.getCurrentSpan介绍

[英]Gets the current Span from the current Context.

To install a Span to the current Context use #withSpan(Span) OR use SpanBuilder#startScopedSpan methods to start a new Span.

startSpan methods do NOT modify the current Context Span.
[中]从当前上下文获取当前范围。
要在当前上下文中安装Span,请使用#withSpan(Span)或使用SpanBuilder#startScopedSpan方法启动新Span。
startSpan方法不会修改当前的上下文范围。

代码示例

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

TransactionManagerImpl(SessionImpl session) {
 this.session = session;
 this.span = Tracing.getTracer().getCurrentSpan();
}

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

private AbstractReadContext(SessionImpl session, SpannerRpc rpc, int defaultPrefetchChunks) {
 this(session, rpc, defaultPrefetchChunks, Tracing.getTracer().getCurrentSpan());
}

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

@Override
 public void onCompleted() {
  tracer.getCurrentSpan().addAnnotation("Firestore.BatchGet: Complete");
  List<DocumentSnapshot> documentSnapshots = new ArrayList<>();
  for (DocumentReference documentReference : documentReferences) {
   documentSnapshots.add(resultMap.get(documentReference));
  }
  futureList.set(documentSnapshots);
 }
};

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

TransactionRunnerImpl(
  SessionImpl session, SpannerRpc rpc, Sleeper sleeper, int defaultPrefetchChunks) {
 this.session = session;
 this.sleeper = sleeper;
 this.span = Tracing.getTracer().getCurrentSpan();
 this.txn = session.newTransaction();
}

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

@Override
public void onError(Throwable throwable) {
 tracer.getCurrentSpan().addAnnotation("Firestore.BatchGet: Error");
 futureList.setException(throwable);
}

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

@Override
public void onError(Throwable throwable) {
 Tracing.getTracer().getCurrentSpan().addAnnotation("Firestore.Query: Error");
 documentObserver.onError(throwable);
}

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

@Override
 public void onCompleted() {
  Tracing.getTracer()
    .getCurrentSpan()
    .addAnnotation(
      "Firestore.Query: Completed",
      ImmutableMap.of(
        "numDocuments", AttributeValue.longAttributeValue(numDocuments)));
  documentObserver.onCompleted(readTime);
 }
};

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

@Override
 public void intercept(HttpRequest request) throws IOException {
  checkNotNull(request);
  if (this.interceptor != null) {
   this.interceptor.intercept(request);
  }
  if (propagationTextFormat != null && propagationTextFormatSetter != null) {
   SpanContext spanContext = tracer.getCurrentSpan().getContext();
   if (!SpanContext.INVALID.equals(spanContext)) {
    propagationTextFormat.inject(
      spanContext, request.getHeaders(), propagationTextFormatSetter);
   }
  }
 }
}

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

private static void backoffSleep(Context context, long backoffMillis) throws SpannerException {
 tracer
   .getCurrentSpan()
   .addAnnotation(
     "Backing off",

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

Span span = tracer.getCurrentSpan();
ExponentialBackOff backOff = newBackOff();
Context context = Context.current();

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

Span span = Tracing.getTracer().getCurrentSpan();
span.addAnnotation("Acquiring read write session");
Waiter waiter = null;

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

Span span = Tracing.getTracer().getCurrentSpan();
span.addAnnotation("Acquiring session");
Waiter waiter = null;

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

@Override
public void onNext(RunQueryResponse response) {
 if (!firstResponse) {
  firstResponse = true;
  Tracing.getTracer().getCurrentSpan().addAnnotation("Firestore.Query: First response");
 }
 if (response.hasDocument()) {
  numDocuments++;
  if (numDocuments % 100 == 0) {
   Tracing.getTracer()
     .getCurrentSpan()
     .addAnnotation("Firestore.Query: Received 100 documents");
  }
  Document document = response.getDocument();
  QueryDocumentSnapshot documentSnapshot =
    QueryDocumentSnapshot.fromDocument(
      firestore, Timestamp.fromProto(response.getReadTime()), document);
  documentObserver.onNext(documentSnapshot);
 }
 if (readTime == null) {
  readTime = Timestamp.fromProto(response.getReadTime());
 }
}

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

private void maybeCreateSession() {
 Span span = Tracing.getTracer().getCurrentSpan();
 synchronized (lock) {
  if (numWaiters() >= numSessionsBeingCreated) {
   if (canCreateSession()) {
    span.addAnnotation("Creating session");
    createSession();
   } else if (options.isFailIfPoolExhausted()) {
    span.addAnnotation("Pool exhausted. Failing");
    // throw specific exception
    throw newSpannerException(
      ErrorCode.RESOURCE_EXHAUSTED,
      "No session available in the pool. Maximum number of sessions in the pool can be"
        + " overridden by invoking SessionPoolOptions#Builder#setMaxSessions. Client can be made to block"
        + " rather than fail by setting SessionPoolOptions#Builder#setBlockIfPoolExhausted.");
   }
  }
 }
}
/**

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

.getCurrentSpan()
.addAnnotation(
  "CloudFirestore.Commit",

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

.getCurrentSpan()
.addAnnotation(
  "Firestore.BatchGet: Start",

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

tracer.getCurrentSpan().addAnnotation("Firestore.BatchGet: First response");
} else if (numResponses % 100 == 0) {
 tracer.getCurrentSpan().addAnnotation("Firestore.BatchGet: Received 100 responses");

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

.getCurrentSpan()
.addAnnotation(
  "Firestore.Query: Start",

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

rewriteResponse.getTotalBytesRewritten().longValue());
} catch (IOException ex) {
 tracer.getCurrentSpan().setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
 throw translate(ex);

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

@Test
public void getCurrentSpan_WithSpan() {
 assertThat(noopTracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
 Scope ws = noopTracer.withSpan(span);
 try {
  assertThat(noopTracer.getCurrentSpan()).isSameAs(span);
 } finally {
  ws.close();
 }
 assertThat(noopTracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
}

相关文章