brave.Tracing.clock()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(130)

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

Tracing.clock介绍

[英]This exposes the microsecond clock used by operations such as Span#finish(). This is helpful when you want to time things manually. Notably, this clock will be coherent for all child spans in this trace (that use this tracing component). For example, NTP or system clock changes will not affect the result.
[中]这暴露了Span#finish()等操作使用的微秒时钟。当您想手动计时时,这很有用。值得注意的是,该时钟对于该跟踪(使用该跟踪组件)中的所有子跨度都是一致的。例如,NTP或系统时钟更改不会影响结果。

代码示例

代码示例来源:origin: openzipkin/brave

timestamp = tracing.clock(span.context()).currentTimeMicroseconds();
timestamp = tracing.clock(span.context()).currentTimeMicroseconds();

代码示例来源:origin: openzipkin/brave

/**
 * MethodInterceptor for {@link SimpleMessageListenerContainer.ContainerDelegate#invokeListener(Channel,
 * Message)}
 */
@Override public Object invoke(MethodInvocation methodInvocation) throws Throwable {
 Message message = (Message) methodInvocation.getArguments()[1];
 TraceContextOrSamplingFlags extracted = springRabbitTracing.extractAndClearHeaders(message);
 // named for BlockingQueueConsumer.nextMessage, which we can't currently see
 Span consumerSpan = tracer.nextSpan(extracted);
 Span listenerSpan = tracer.newChild(consumerSpan.context());
 if (!consumerSpan.isNoop()) {
  setConsumerSpan(consumerSpan, message.getMessageProperties());
  // incur timestamp overhead only once
  long timestamp = tracing.clock(consumerSpan.context()).currentTimeMicroseconds();
  consumerSpan.start(timestamp);
  long consumerFinish = timestamp + 1L; // save a clock reading
  consumerSpan.finish(consumerFinish);
  // not using scoped span as we want to start with a pre-configured time
  listenerSpan.name("on-message").start(consumerFinish);
 }
 try (SpanInScope ws = tracer.withSpanInScope(listenerSpan)) {
  return methodInvocation.proceed();
 } catch (Throwable t) {
  listenerSpan.error(t);
  throw t;
 } finally {
  listenerSpan.finish();
 }
}

代码示例来源:origin: openzipkin/brave

void handleReceive(Message message) {
 if (message == null || tracing.isNoop()) return;
 // remove prior propagation headers from the message
 TraceContextOrSamplingFlags extracted = jmsTracing.extractAndClearMessage(message);
 Span span = tracer.nextSpan(extracted);
 if (!span.isNoop()) {
  span.name("receive").kind(Span.Kind.CONSUMER);
  Destination destination = destination(message);
  if (destination != null) jmsTracing.tagQueueOrTopic(destination, span);
  if (remoteServiceName != null) span.remoteServiceName(remoteServiceName);
  // incur timestamp overhead only once
  long timestamp = tracing.clock(span.context()).currentTimeMicroseconds();
  span.start(timestamp).finish(timestamp);
 }
 jmsTracing.setNextParent(message, span.context());
}

代码示例来源:origin: openzipkin/brave

@Override public Message postProcessMessage(Message message) {
  TraceContext maybeParent = currentTraceContext.get();
  // Unlike message consumers, we try current span before trying extraction. This is the proper
  // order because the span in scope should take precedence over a potentially stale header entry.
  //
  // NOTE: Brave instrumentation used properly does not result in stale header entries, as we
  // always clear message headers after reading.
  Span span;
  if (maybeParent == null) {
   span = tracer.nextSpan(springRabbitTracing.extractAndClearHeaders(message));
  } else {
   // If we have a span in scope assume headers were cleared before
   span = tracer.newChild(maybeParent);
  }

  if (!span.isNoop()) {
   span.kind(Span.Kind.PRODUCER).name("publish");
   if (remoteServiceName != null) span.remoteServiceName(remoteServiceName);
   // incur timestamp overhead only once
   long timestamp = tracing.clock(span.context()).currentTimeMicroseconds();
   span.start(timestamp).finish(timestamp);
  }

  injector.inject(span.context(), message.getMessageProperties());
  return message;
 }
}

代码示例来源:origin: openzipkin/brave

Span startMessageListenerSpan(Message message) {
  if (!addConsumerSpan) return jmsTracing.nextSpan(message).name("on-message").start();
  TraceContextOrSamplingFlags extracted = jmsTracing.extractAndClearMessage(message);

  // JMS has no visibility of the incoming message, which incidentally could be local!
  Span consumerSpan = tracer.nextSpan(extracted).kind(CONSUMER).name("receive");
  Span listenerSpan = tracer.newChild(consumerSpan.context());

  if (!consumerSpan.isNoop()) {
   long timestamp = tracing.clock(consumerSpan.context()).currentTimeMicroseconds();
   consumerSpan.start(timestamp);
   if (remoteServiceName != null) consumerSpan.remoteServiceName(remoteServiceName);
   jmsTracing.tagQueueOrTopic(message, consumerSpan);
   long consumerFinish = timestamp + 1L; // save a clock reading
   consumerSpan.finish(consumerFinish);

   // not using scoped span as we want to start late
   listenerSpan.name("on-message").start(consumerFinish);
  }
  return listenerSpan;
 }
}

代码示例来源:origin: io.zipkin.brave/brave-core

@Override
 long currentTimeMicroseconds(Span span) {
  return tracing
    .clock(toTraceContext(InternalSpan.instance.context(span)))
    .currentTimeMicroseconds();
 }
}

代码示例来源:origin: io.zipkin.brave/brave-instrumentation-kafka-clients

timestamp = tracing.clock(span.context()).currentTimeMicroseconds();
timestamp = tracing.clock(span.context()).currentTimeMicroseconds();

相关文章