com.nike.wingtips.Span.addTimestampedAnnotationForCurrentTime()方法的使用及代码示例

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

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

Span.addTimestampedAnnotationForCurrentTime介绍

[英]Adds a TimestampedAnnotation to this Span's #getTimestampedAnnotations() list, with the current time in epoch microseconds as the timestamp and the given value.

NOTE: Since the span keeps track of its duration in nanoseconds, this method results in a TimestampedAnnotation with a TimestampedAnnotation#getTimestampEpochMicros() that is more accurate than if you created the TimestampedAnnotation directly (i.e. this method uses TimestampedAnnotation#forEpochMicrosWithNanoOffset(long,long,String)). This method should therefore be used anytime you want to add an annotation to a Span with a timestamp of "right now".
[中]将TimeStampedAnnotations添加到此Span的#getTimestampedAnnotations()列表中,当前时间(以历元微秒为单位)作为时间戳和给定值。
注意:由于跨度以纳秒为单位跟踪其持续时间,因此此方法会生成一个TimeStamAnnotation,其TimeStamPepochMicros()比直接创建TimeStamAnnotation更准确(即,此方法使用TimeStamAnnotation#ForepochmiSwithNanoOffset(长、长、字符串))。因此,只要您想在时间戳为“立即”的范围中添加注释,就应该使用此方法。

代码示例

代码示例来源:origin: com.nike.riposte/riposte-core

protected void addEndpointFinishAnnotation(Span span, ServerSpanNamingAndTaggingStrategy<Span> strategy) {
  // Don't allow the annotation addition to cause the endpoint execution future to fail if it
  //      fails, by surrounding with try/catch. This should never actually happen, but better
  //      safe than sorry.
  try {
    span.addTimestampedAnnotationForCurrentTime(
      strategy.endpointFinishAnnotationName()
    );
  }
  catch(Throwable t) {
    logger.error(
      "Unexpected error while annotating Span with endpoint finish timestamp.", t
    );
  }
}

代码示例来源:origin: Nike-Inc/riposte

protected void addEndpointFinishAnnotation(Span span, ServerSpanNamingAndTaggingStrategy<Span> strategy) {
  // Don't allow the annotation addition to cause the endpoint execution future to fail if it
  //      fails, by surrounding with try/catch. This should never actually happen, but better
  //      safe than sorry.
  try {
    span.addTimestampedAnnotationForCurrentTime(
      strategy.endpointFinishAnnotationName()
    );
  }
  catch(Throwable t) {
    logger.error(
      "Unexpected error while annotating Span with endpoint finish timestamp.", t
    );
  }
}

代码示例来源:origin: com.nike.riposte/riposte-core

protected void handleWireSendFinishAnnotationIfNecessary() {
  if (alreadyHandledWireSendFinishAnnotation) {
    return;
  }
  alreadyHandledWireSendFinishAnnotation = true;
  // Add the wire-send-finish annotation if we have a span and the annotation is desired.
  if ((spanForDownstreamCall != null) && proxySpanTaggingStrategy.shouldAddWireSendFinishAnnotation()) {
    spanForDownstreamCall.addTimestampedAnnotationForCurrentTime(
      proxySpanTaggingStrategy.wireSendFinishAnnotationName()
    );
  }
}

代码示例来源:origin: Nike-Inc/riposte

protected void handleWireSendFinishAnnotationIfNecessary() {
  if (alreadyHandledWireSendFinishAnnotation) {
    return;
  }
  alreadyHandledWireSendFinishAnnotation = true;
  // Add the wire-send-finish annotation if we have a span and the annotation is desired.
  if ((spanForDownstreamCall != null) && proxySpanTaggingStrategy.shouldAddWireSendFinishAnnotation()) {
    spanForDownstreamCall.addTimestampedAnnotationForCurrentTime(
      proxySpanTaggingStrategy.wireSendFinishAnnotationName()
    );
  }
}

代码示例来源:origin: com.nike.riposte/riposte-core

protected void addErrorAnnotationToOverallRequestSpan(
  @NotNull HttpProcessingState state,
  @NotNull ResponseInfo<ErrorResponseBody> responseInfo,
  @NotNull Throwable error
) {
  try {
    Span requestSpan = state.getOverallRequestSpan();
    if (
      requestSpan != null
      && spanNamingAndTaggingStrategy.shouldAddErrorAnnotationForCaughtException(responseInfo, error)
    ) {
      requestSpan.addTimestampedAnnotationForCurrentTime(
        spanNamingAndTaggingStrategy.errorAnnotationName(responseInfo, error)
      );
    }
  }
  catch (Throwable t) {
    logger.error(
      "An unexpected error occurred while trying to add an error annotation to the overall request span. "
      + "This should never happen.", t
    );
  }
}

代码示例来源:origin: Nike-Inc/riposte

protected void addErrorAnnotationToOverallRequestSpan(
  @NotNull HttpProcessingState state,
  @NotNull ResponseInfo<ErrorResponseBody> responseInfo,
  @NotNull Throwable error
) {
  try {
    Span requestSpan = state.getOverallRequestSpan();
    if (
      requestSpan != null
      && spanNamingAndTaggingStrategy.shouldAddErrorAnnotationForCaughtException(responseInfo, error)
    ) {
      requestSpan.addTimestampedAnnotationForCurrentTime(
        spanNamingAndTaggingStrategy.errorAnnotationName(responseInfo, error)
      );
    }
  }
  catch (Throwable t) {
    logger.error(
      "An unexpected error occurred while trying to add an error annotation to the overall request span. "
      + "This should never happen.", t
    );
  }
}

代码示例来源:origin: com.nike.riposte/riposte-core

@Override
public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) {
  // We may get multiple messages for a single HTTP request since riposte handles each individual HTTP message
  //      object (including individual payload content messages).
  //      We only do the processing for HttpRequest which is the first message in a request chain.
  if (shouldHandleDoChannelReadMessage(msg)) {
    try {
      startTrace((HttpRequest) msg, ctx);
    }
    catch (Throwable t) {
      logger.error(
        "An unexpected error occurred while starting the distributed tracing overall request span. This "
        + "exception will be swallowed to avoid breaking the Netty pipeline, but it should be "
        + "investigated as it shouldn't ever happen.", t
      );
    }
  }
  if (msg instanceof LastHttpContent) {
    HttpProcessingState httpProcessingState = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get();
    // Add the "we received the last bytes of the request on the wire" annotation to the span if possible
    //      and desired.
    Span requestSpan = handlerUtils.getOverallRequestSpan(httpProcessingState);
    if (requestSpan != null && spanNamingAndTaggingStrategy.shouldAddWireReceiveFinishAnnotation()) {
      requestSpan.addTimestampedAnnotationForCurrentTime(
        spanNamingAndTaggingStrategy.wireReceiveFinishAnnotationName()
      );
    }
  }
  return PipelineContinuationBehavior.CONTINUE;
}

代码示例来源:origin: Nike-Inc/riposte

@Override
public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) {
  // We may get multiple messages for a single HTTP request since riposte handles each individual HTTP message
  //      object (including individual payload content messages).
  //      We only do the processing for HttpRequest which is the first message in a request chain.
  if (shouldHandleDoChannelReadMessage(msg)) {
    try {
      startTrace((HttpRequest) msg, ctx);
    }
    catch (Throwable t) {
      logger.error(
        "An unexpected error occurred while starting the distributed tracing overall request span. This "
        + "exception will be swallowed to avoid breaking the Netty pipeline, but it should be "
        + "investigated as it shouldn't ever happen.", t
      );
    }
  }
  if (msg instanceof LastHttpContent) {
    HttpProcessingState httpProcessingState = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get();
    // Add the "we received the last bytes of the request on the wire" annotation to the span if possible
    //      and desired.
    Span requestSpan = handlerUtils.getOverallRequestSpan(httpProcessingState);
    if (requestSpan != null && spanNamingAndTaggingStrategy.shouldAddWireReceiveFinishAnnotation()) {
      requestSpan.addTimestampedAnnotationForCurrentTime(
        spanNamingAndTaggingStrategy.wireReceiveFinishAnnotationName()
      );
    }
  }
  return PipelineContinuationBehavior.CONTINUE;
}

代码示例来源:origin: com.nike.riposte/riposte-core

endpointExecutionSpan.addTimestampedAnnotationForCurrentTime(
  spanTaggingStrategy.endpointStartAnnotationName()
);

代码示例来源:origin: Nike-Inc/riposte

endpointExecutionSpan.addTimestampedAnnotationForCurrentTime(
  spanTaggingStrategy.endpointStartAnnotationName()
);

代码示例来源:origin: Nike-Inc/riposte

verify(spanMock).addTimestampedAnnotationForCurrentTime(
  distributedTracingConfig.getServerSpanNamingAndTaggingStrategy().wireReceiveFinishAnnotationName()
);
verify(spanMock, never()).addTimestampedAnnotationForCurrentTime(anyString());

代码示例来源:origin: Nike-Inc/riposte

@UseDataProvider("errorAnnotationScenarioDataProvider")
@Test
public void addErrorAnnotationToOverallRequestSpan_works_as_expected(
  ErrorAnnotationScenario scenario
) {
  // given
  HttpProcessingState stateSpy = spy(state);
  doReturn(scenario.overallRequestSpanMock).when(stateSpy).getOverallRequestSpan();
  ResponseInfo<ErrorResponseBody> responseInfoMock = mock(ResponseInfo.class);
  Throwable errorMock = mock(Throwable.class);
  doReturn(scenario.addErrorAnnotationConfigValue)
    .when(serverSpanNamingAndTaggingStrategyMock).shouldAddErrorAnnotationForCaughtException(any(), any());
  String annotationValueFromStrategy = UUID.randomUUID().toString();
  doReturn(annotationValueFromStrategy)
    .when(serverSpanNamingAndTaggingStrategyMock).errorAnnotationName(any(), any());
  // when
  handler.addErrorAnnotationToOverallRequestSpan(stateSpy, responseInfoMock, errorMock);
  // then
  if (scenario.expectAnnotation) {
    verify(scenario.overallRequestSpanMock).addTimestampedAnnotationForCurrentTime(annotationValueFromStrategy);
    verify(serverSpanNamingAndTaggingStrategyMock).errorAnnotationName(responseInfoMock, errorMock);
  }
  if (scenario.overallRequestSpanMock != null) {
    verify(serverSpanNamingAndTaggingStrategyMock)
      .shouldAddErrorAnnotationForCaughtException(responseInfoMock, errorMock);
  }
}

代码示例来源:origin: Nike-Inc/riposte

? times(1)
                        : never();
verify(spanMock, startAnnotationVerification).addTimestampedAnnotationForCurrentTime(
  scenario.startAnnotationName
);
                        ? times(1)
                        : never();
verify(spanMock, finishAnnotationVerification).addTimestampedAnnotationForCurrentTime(
  scenario.finishAnnotationName
);

代码示例来源:origin: Nike-Inc/riposte

overallRequestSpan.addTimestampedAnnotationForCurrentTime(
  spanNamingAndTaggingStrategy.wireSendStartAnnotationName()
);
Span overallRequestSpan = state.getOverallRequestSpan();
if (overallRequestSpan != null && spanNamingAndTaggingStrategy.shouldAddWireSendFinishAnnotation()) {
  overallRequestSpan.addTimestampedAnnotationForCurrentTime(
    spanNamingAndTaggingStrategy.wireSendFinishAnnotationName()
  );

代码示例来源:origin: com.nike.riposte/riposte-core

overallRequestSpan.addTimestampedAnnotationForCurrentTime(
  spanNamingAndTaggingStrategy.wireSendStartAnnotationName()
);
Span overallRequestSpan = state.getOverallRequestSpan();
if (overallRequestSpan != null && spanNamingAndTaggingStrategy.shouldAddWireSendFinishAnnotation()) {
  overallRequestSpan.addTimestampedAnnotationForCurrentTime(
    spanNamingAndTaggingStrategy.wireSendFinishAnnotationName()
  );

代码示例来源:origin: com.nike.riposte/riposte-core

currentSpan.addTimestampedAnnotationForCurrentTime(
          proxySpanTaggingStrategy.wireReceiveFinishAnnotationName()
        );
  && proxySpanTaggingStrategy.shouldAddWireReceiveStartAnnotation()
) {
  spanForDownstreamCall.addTimestampedAnnotationForCurrentTime(
    proxySpanTaggingStrategy.wireReceiveStartAnnotationName()
  );

代码示例来源:origin: Nike-Inc/riposte

currentSpan.addTimestampedAnnotationForCurrentTime(
          proxySpanTaggingStrategy.wireReceiveFinishAnnotationName()
        );
  && proxySpanTaggingStrategy.shouldAddWireReceiveStartAnnotation()
) {
  spanForDownstreamCall.addTimestampedAnnotationForCurrentTime(
    proxySpanTaggingStrategy.wireReceiveStartAnnotationName()
  );

代码示例来源:origin: Nike-Inc/wingtips

span.addTimestampedAnnotationForCurrentTime(annotationValue);
long nanoTimeAfterMethodCall = System.nanoTime();

代码示例来源:origin: com.nike.riposte/riposte-core

newSpan.addTimestampedAnnotationForCurrentTime(
  spanNamingAndTaggingStrategy.wireReceiveStartAnnotationName()
);

代码示例来源:origin: Nike-Inc/riposte

newSpan.addTimestampedAnnotationForCurrentTime(
  spanNamingAndTaggingStrategy.wireReceiveStartAnnotationName()
);

相关文章