本文整理了Java中com.nike.wingtips.zipkin.util.ZipkinSpanSender
类的一些代码示例,展示了ZipkinSpanSender
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipkinSpanSender
类的具体详情如下:
包路径:com.nike.wingtips.zipkin.util.ZipkinSpanSender
类名称:ZipkinSpanSender
[英]A interface for sending Zipkin spans to a Zipkin server. This is similar to a Zipkin SpanCollector and you can easily create an adapter that wraps a native Zipkin Brave SpanCollector with this interface if you prefer the features, flexibility, and numerous transport options provided by the native Zipkin SpanCollectors over the no-dependencies HTTP-only default implementation provided by ZipkinSpanSenderDefaultHttpImpl.
[中]用于将Zipkin跨度发送到Zipkin服务器的接口。这类似于Zipkin SpanCollector,您可以轻松创建一个适配器,将本机Zipkin{{0$}SpanCollector包装在这个接口中,如果您喜欢它的功能、灵活性,本机Zipkin SpanCollectors通过ZipkinPansenderDefaultHttpImpl提供的无依赖HTTP纯默认实现提供了许多传输选项。
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!