gpt4 book ai didi

com.nike.wingtips.zipkin.util.ZipkinSpanSender.handleSpan()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 12:41:21 27 4
gpt4 key购买 nike

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

ZipkinSpanSender.handleSpan介绍

[英]"Handles" the given Zipkin span. In a typical implementation spans are stored in a threadsafe collection for batching until some trigger is hit that causes the span batch to be sent to the Zipkin server (e.g. scheduled job that sends batches every x period of time, or after a batch size threshold is hit, or both).

IMPORTANT NOTE: DO NOT BLOCK IN THIS METHOD'S IMPLEMENTATION. If you send data to the Zipkin server directly based on this method call then it should be split out into a separate thread to do the work. The only thing that should happen on the calling thread is to put the span into a queue for later processing, or spinning off a job on a separate thread.
[中]“处理”给定的Zipkin跨度。在典型的实现中,跨度存储在threadsafe集合中进行批处理,直到触发某个触发器,导致跨度批处理被发送到Zipkin服务器(例如,每x个时间段发送一次批处理的计划作业,或在达到批处理大小阈值后发送批处理,或两者兼而有之)。
重要提示:不要在该方法的实现中阻塞。如果基于此方法调用直接将数据发送到Zipkin服务器,则应将其拆分为单独的线程来执行该工作。在调用线程上应该做的唯一事情是将跨度放入队列以供以后处理,或者在单独的线程上拆分作业。

代码示例

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

@Override
  public void spanCompleted(Span span) {
    try {
      zipkin.Span zipkinSpan = zipkinSpanConverter.convertWingtipsSpanToZipkinSpan(span, zipkinEndpoint, localComponentNamespace);
      zipkinSpanSender.handleSpan(zipkinSpan);
    }
    catch(Throwable ex) {
      long currentBadSpanCount = spanHandlingErrorCounter.incrementAndGet();

      // Only log once every MIN_SPAN_HANDLING_ERROR_LOG_INTERVAL_MILLIS time interval to prevent log spam from a malicious (or broken) caller.
      long currentTimeMillis = System.currentTimeMillis();
      long timeSinceLastLogMsgMillis = currentTimeMillis - lastSpanHandlingErrorLogTimeEpochMillis;
      if (timeSinceLastLogMsgMillis >= MIN_SPAN_HANDLING_ERROR_LOG_INTERVAL_MILLIS) {
        // We're not synchronizing the read and write to lastSpanHandlingErrorLogTimeEpochMillis, and that's ok. If we get a few extra
        //      log messages due to a race condition it's not the end of the world - we're still satisfying the goal of not allowing a
        //      malicious caller to endlessly spam the logs.
        lastSpanHandlingErrorLogTimeEpochMillis = currentTimeMillis;

        zipkinConversionOrReportingErrorLogger.warn(
          "There have been {} spans that were not zipkin compatible, or that experienced an error during span handling. Latest example: "
          + "wingtips_span_with_error=\"{}\", conversion_or_handling_error=\"{}\"",
          currentBadSpanCount, span.toKeyValueString(), ex.toString());
      }
    }
  }
}

代码示例来源:origin: com.nike.wingtips/wingtips-zipkin

@Override
  public void spanCompleted(Span span) {
    try {
      zipkin.Span zipkinSpan = zipkinSpanConverter.convertWingtipsSpanToZipkinSpan(span, zipkinEndpoint, localComponentNamespace);
      zipkinSpanSender.handleSpan(zipkinSpan);
    }
    catch(Throwable ex) {
      long currentBadSpanCount = spanHandlingErrorCounter.incrementAndGet();

      // Only log once every MIN_SPAN_HANDLING_ERROR_LOG_INTERVAL_MILLIS time interval to prevent log spam from a malicious (or broken) caller.
      long currentTimeMillis = System.currentTimeMillis();
      long timeSinceLastLogMsgMillis = currentTimeMillis - lastSpanHandlingErrorLogTimeEpochMillis;
      if (timeSinceLastLogMsgMillis >= MIN_SPAN_HANDLING_ERROR_LOG_INTERVAL_MILLIS) {
        // We're not synchronizing the read and write to lastSpanHandlingErrorLogTimeEpochMillis, and that's ok. If we get a few extra
        //      log messages due to a race condition it's not the end of the world - we're still satisfying the goal of not allowing a
        //      malicious caller to endlessly spam the logs.
        lastSpanHandlingErrorLogTimeEpochMillis = currentTimeMillis;

        zipkinConversionOrReportingErrorLogger.warn(
          "There have been {} spans that were not zipkin compatible, or that experienced an error during span handling. Latest example: "
          + "wingtips_span_with_error=\"{}\", conversion_or_handling_error=\"{}\"",
          currentBadSpanCount, span.toKeyValueString(), ex.toString());
      }
    }
  }
}

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

@Test
public void spanCompleted_does_not_propagate_exceptions_generated_by_span_sender() {
  // given
  doThrow(new RuntimeException("kaboom")).when(spanSenderMock).handleSpan(any(zipkin.Span.class));
  // when
  Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
    @Override
    public void call() throws Throwable {
      listener.spanCompleted(spanMock);
    }
  });
  // then
  verify(spanSenderMock).handleSpan(any(zipkin.Span.class));
  assertThat(ex).isNull();
}

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

@Test
public void spanCompleted_logs_error_during_handling_if_time_since_lastSpanHandlingErrorLogTimeEpochMillis_is_greater_than_MIN_SPAN_HANDLING_ERROR_LOG_INTERVAL_MILLIS() throws InterruptedException {
  // given
  Logger loggerMock = mock(Logger.class);
  Whitebox.setInternalState(listener, "zipkinConversionOrReportingErrorLogger", loggerMock);
  long lastLogTimeToSet = System.currentTimeMillis() - (MIN_SPAN_HANDLING_ERROR_LOG_INTERVAL_MILLIS + 10);
  Whitebox.setInternalState(listener, "lastSpanHandlingErrorLogTimeEpochMillis", lastLogTimeToSet);
  doThrow(new RuntimeException("kaboom")).when(spanSenderMock).handleSpan(any(zipkin.Span.class));
  // when
  long before = System.currentTimeMillis();
  listener.spanCompleted(spanMock);
  long after = System.currentTimeMillis();
  // then
  verify(loggerMock).warn(anyString(), anyLong(), anyString(), anyString());
  // Also verify that the lastSpanHandlingErrorLogTimeEpochMillis value got updated.
  assertThat((long)Whitebox.getInternalState(listener, "lastSpanHandlingErrorLogTimeEpochMillis")).isBetween(before, after);
}

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

@Test
  public void spanCompleted_does_not_log_an_error_during_handling_if_time_since_lastSpanHandlingErrorLogTimeEpochMillis_is_less_than_MIN_SPAN_HANDLING_ERROR_LOG_INTERVAL_MILLIS() throws InterruptedException {
    // given
    Logger loggerMock = mock(Logger.class);
    Whitebox.setInternalState(listener, "zipkinConversionOrReportingErrorLogger", loggerMock);
    long lastLogTimeToSet = System.currentTimeMillis() - (MIN_SPAN_HANDLING_ERROR_LOG_INTERVAL_MILLIS - 1000);
    Whitebox.setInternalState(listener, "lastSpanHandlingErrorLogTimeEpochMillis", lastLogTimeToSet);
    doThrow(new RuntimeException("kaboom")).when(spanSenderMock).handleSpan(any(zipkin.Span.class));

    // when
    listener.spanCompleted(spanMock);

    // then
    verifyZeroInteractions(loggerMock);
    // Also verify that the lastSpanHandlingErrorLogTimeEpochMillis value was *not* updated.
    assertThat((long)Whitebox.getInternalState(listener, "lastSpanHandlingErrorLogTimeEpochMillis")).isEqualTo(lastLogTimeToSet);
  }
}

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

@Test
public void spanCompleted_converts_to_zipkin_span_and_passes_it_to_zipkinSpanSender() {
  // given
  zipkin.Span zipkinSpan = zipkin.Span.builder().traceId(42).id(4242).name("foo").build();
  doReturn(zipkinSpan).when(spanConverterMock).convertWingtipsSpanToZipkinSpan(any(Span.class), any(Endpoint.class), any(String.class));
  // when
  listener.spanCompleted(spanMock);
  // then
  verify(spanConverterMock).convertWingtipsSpanToZipkinSpan(spanMock, listener.zipkinEndpoint, localComponentNamespace);
  verify(spanSenderMock).handleSpan(zipkinSpan);
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com